]>
Commit | Line | Data |
---|---|---|
128fe1c6 | 1 | /* |
b510f3a1 | 2 | * DEBUG: section -- Unlink Daemon |
128fe1c6 | 3 | * AUTHOR: Duane Wessels |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
128fe1c6 | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
128fe1c6 | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
32 | ||
33 | #define SQUID_HELPER 1 | |
34 | ||
f7f3304a | 35 | #include "squid.h" |
25f98340 AJ |
36 | |
37 | #if HAVE_PATHS_H | |
38 | #include <paths.h> | |
39 | #endif | |
128fe1c6 | 40 | |
63be0a78 | 41 | /** |
42 | \defgroup unlinkd unlinkd | |
43 | \ingroup ExternalPrograms | |
44 | \par | |
45 | The unlink(2) system call can cause a process to block | |
46 | for a significant amount of time. Therefore we do not want | |
47 | to make unlink() calls from Squid. Instead we pass them | |
48 | to this external process. | |
49 | */ | |
128fe1c6 | 50 | |
63be0a78 | 51 | /// \ingroup unlinkd |
128fe1c6 | 52 | #define UNLINK_BUF_LEN 1024 |
53 | ||
63be0a78 | 54 | /** |
55 | \ingroup unlinkd | |
56 | \par This is the unlinkd external process. | |
57 | * | |
58 | \par | |
59 | * unlinkd receives the full path of any files to be removed | |
60 | * from stdin, each on its own line. | |
61 | * | |
62 | \par | |
63 | * The results for each file are printed to stdout in the order | |
64 | * they were received | |
65 | * | |
66 | \param argc Ignored. | |
67 | \param argv Ignored. | |
68 | \retval ERR An error occured removing the file. | |
69 | \retval OK The file has been removed. | |
70 | */ | |
128fe1c6 | 71 | int |
72 | main(int argc, char *argv[]) | |
73 | { | |
74 | char buf[UNLINK_BUF_LEN]; | |
75 | char *t; | |
76 | int x; | |
77 | setbuf(stdin, NULL); | |
78 | setbuf(stdout, NULL); | |
79 | close(2); | |
8f084aaf AJ |
80 | if (open(_PATH_DEVNULL, O_RDWR) < 0) { |
81 | ; // the irony of having to close(2) earlier is that we cannot report this failure. | |
82 | } | |
128fe1c6 | 83 | |
8f084aaf | 84 | while (fgets(buf, sizeof(buf), stdin)) { |
128fe1c6 | 85 | if ((t = strchr(buf, '\n'))) |
86 | *t = '\0'; | |
87 | x = unlink(buf); | |
88 | if (x < 0) | |
89 | printf("ERR\n"); | |
90 | else | |
91 | printf("OK\n"); | |
92 | } | |
93 | ||
25f98340 | 94 | return 0; |
128fe1c6 | 95 | } |