]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2025 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 | #include <iostream> | |
16 | #include <cstdio> | |
17 | #if HAVE_PATHS_H | |
18 | #include <paths.h> | |
19 | #endif | |
20 | ||
21 | /** | |
22 | \defgroup unlinkd unlinkd | |
23 | \ingroup ExternalPrograms | |
24 | \par | |
25 | The unlink(2) system call can cause a process to block | |
26 | for a significant amount of time. Therefore we do not want | |
27 | to make unlink() calls from Squid. Instead we pass them | |
28 | to this external process. | |
29 | */ | |
30 | ||
31 | /// \ingroup unlinkd | |
32 | #define UNLINK_BUF_LEN 1024 | |
33 | ||
34 | /** | |
35 | \ingroup unlinkd | |
36 | \par This is the unlinkd external process. | |
37 | * | |
38 | \par | |
39 | * unlinkd receives the full path of any files to be removed | |
40 | * from stdin, each on its own line. | |
41 | * | |
42 | \par | |
43 | * The results for each file are printed to stdout in the order | |
44 | * they were received | |
45 | * | |
46 | \param argc Ignored. | |
47 | \param argv Ignored. | |
48 | \retval ERR An error occurred removing the file. | |
49 | \retval OK The file has been removed. | |
50 | */ | |
51 | int | |
52 | main(int, char *[]) | |
53 | { | |
54 | std::string sbuf; | |
55 | close(2); | |
56 | if (open(_PATH_DEVNULL, O_RDWR) < 0) { | |
57 | ; // the irony of having to close(2) earlier is that we cannot report this failure. | |
58 | } | |
59 | while (getline(std::cin, sbuf)) { | |
60 | // tailing newline is removed by getline | |
61 | const int rv = remove(sbuf.c_str()); | |
62 | if (rv < 0) | |
63 | std::cout << "ERR" << std::endl; // endl flushes | |
64 | else | |
65 | std::cout << "OK" << std::endl; | |
66 | } | |
67 | ||
68 | return EXIT_SUCCESS; | |
69 | } | |
70 |