]> git.ipfire.org Git - thirdparty/squid.git/blob - src/unlinkd_daemon.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / unlinkd_daemon.cc
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section -- Unlink Daemon */
10
11 #define SQUID_HELPER 1
12
13 #include "squid.h"
14
15 #if HAVE_PATHS_H
16 #include <paths.h>
17 #endif
18
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 */
28
29 /// \ingroup unlinkd
30 #define UNLINK_BUF_LEN 1024
31
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 */
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);
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 }
61
62 while (fgets(buf, sizeof(buf), stdin)) {
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
72 return 0;
73 }