]>
Commit | Line | Data |
---|---|---|
128fe1c6 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
128fe1c6 | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
128fe1c6 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section -- Unlink Daemon */ |
10 | ||
128fe1c6 | 11 | #define SQUID_HELPER 1 |
12 | ||
f7f3304a | 13 | #include "squid.h" |
25f98340 AJ |
14 | |
15 | #if HAVE_PATHS_H | |
16 | #include <paths.h> | |
17 | #endif | |
128fe1c6 | 18 | |
63be0a78 | 19 | /** |
20 | \defgroup unlinkd unlinkd | |
21 | \ingroup ExternalPrograms | |
22 | \par | |
23 | The unlink(2) system call can cause a process to block | |
24 | for a significant amount of time. Therefore we do not want | |
25 | to make unlink() calls from Squid. Instead we pass them | |
26 | to this external process. | |
27 | */ | |
128fe1c6 | 28 | |
63be0a78 | 29 | /// \ingroup unlinkd |
128fe1c6 | 30 | #define UNLINK_BUF_LEN 1024 |
31 | ||
63be0a78 | 32 | /** |
33 | \ingroup unlinkd | |
34 | \par This is the unlinkd external process. | |
35 | * | |
36 | \par | |
37 | * unlinkd receives the full path of any files to be removed | |
38 | * from stdin, each on its own line. | |
39 | * | |
40 | \par | |
41 | * The results for each file are printed to stdout in the order | |
42 | * they were received | |
43 | * | |
44 | \param argc Ignored. | |
45 | \param argv Ignored. | |
46 | \retval ERR An error occured removing the file. | |
47 | \retval OK The file has been removed. | |
48 | */ | |
128fe1c6 | 49 | int |
50 | main(int argc, char *argv[]) | |
51 | { | |
52 | char buf[UNLINK_BUF_LEN]; | |
53 | char *t; | |
54 | int x; | |
55 | setbuf(stdin, NULL); | |
56 | setbuf(stdout, NULL); | |
57 | close(2); | |
8f084aaf AJ |
58 | if (open(_PATH_DEVNULL, O_RDWR) < 0) { |
59 | ; // the irony of having to close(2) earlier is that we cannot report this failure. | |
60 | } | |
128fe1c6 | 61 | |
8f084aaf | 62 | while (fgets(buf, sizeof(buf), stdin)) { |
128fe1c6 | 63 | if ((t = strchr(buf, '\n'))) |
64 | *t = '\0'; | |
65 | x = unlink(buf); | |
66 | if (x < 0) | |
67 | printf("ERR\n"); | |
68 | else | |
69 | printf("OK\n"); | |
70 | } | |
71 | ||
25f98340 | 72 | return 0; |
128fe1c6 | 73 | } |