]> git.ipfire.org Git - thirdparty/squid.git/blame - src/unlinkd_daemon.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / unlinkd_daemon.cc
CommitLineData
128fe1c6 1/*
f70aedc4 2 * Copyright (C) 1996-2021 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 14
ee74db84
FC
15#include <iostream>
16#include <cstdio>
25f98340
AJ
17#if HAVE_PATHS_H
18#include <paths.h>
19#endif
128fe1c6 20
63be0a78 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 */
128fe1c6 30
63be0a78 31/// \ingroup unlinkd
128fe1c6 32#define UNLINK_BUF_LEN 1024
33
63be0a78 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.
61beade2 48 \retval ERR An error occurred removing the file.
63be0a78 49 \retval OK The file has been removed.
50 */
128fe1c6 51int
ced8def3 52main(int, char *[])
128fe1c6 53{
ee74db84 54 std::string sbuf;
128fe1c6 55 close(2);
8f084aaf
AJ
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 }
ee74db84
FC
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
128fe1c6 64 else
ee74db84 65 std::cout << "OK" << std::endl;
128fe1c6 66 }
67
24885773 68 return EXIT_SUCCESS;
128fe1c6 69}
f53969cc 70