~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/unlinkd.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: unlinkd.cc,v 1.64 2007/04/30 16:56:09 wessels Exp $
 
3
 * $Id$
4
4
 *
5
5
 * DEBUG: section 2     Unlink Daemon
6
6
 * AUTHOR: Duane Wessels
21
21
 *  it under the terms of the GNU General Public License as published by
22
22
 *  the Free Software Foundation; either version 2 of the License, or
23
23
 *  (at your option) any later version.
24
 
 *  
 
24
 *
25
25
 *  This program is distributed in the hope that it will be useful,
26
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
28
 *  GNU General Public License for more details.
29
 
 *  
 
29
 *
30
30
 *  You should have received a copy of the GNU General Public License
31
31
 *  along with this program; if not, write to the Free Software
32
32
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
53
53
{
54
54
    char buf[MAXPATHLEN];
55
55
    int l;
56
 
    int x;
 
56
    int bytes_written;
57
57
    static int queuelen = 0;
58
58
 
59
59
    if (unlinkd_wfd < 0) {
70
70
     */
71
71
    if (queuelen >= UNLINKD_QUEUE_LIMIT) {
72
72
#if defined(USE_EPOLL) || defined(USE_KQUEUE)
73
 
        /*
74
 
         * DPW 2007-04-23
75
 
         * We can't use fd_set when using epoll() or kqueue().  In
76
 
         * these cases we block for 10 ms.
77
 
         */
78
 
        xusleep(10000);
 
73
        /*
 
74
         * DPW 2007-04-23
 
75
         * We can't use fd_set when using epoll() or kqueue().  In
 
76
         * these cases we block for 10 ms.
 
77
         */
 
78
        xusleep(10000);
79
79
#else
80
 
        /*
81
 
         * DPW 2007-04-23
82
 
         * When we can use select, block for up to 100 ms.
83
 
         */
 
80
        /*
 
81
         * DPW 2007-04-23
 
82
         * When we can use select, block for up to 100 ms.
 
83
         */
84
84
        struct timeval to;
85
85
        fd_set R;
86
86
        FD_ZERO(&R);
98
98
    * decrement the queue size by the number of newlines read.
99
99
    */
100
100
    if (queuelen > 0) {
101
 
        int x;
 
101
        int bytes_read;
102
102
        int i;
103
103
        char rbuf[512];
104
 
        x = read(unlinkd_rfd, rbuf, 511);
105
 
 
106
 
        if (x > 0) {
107
 
            rbuf[x] = '\0';
108
 
 
109
 
            for (i = 0; i < x; i++)
 
104
        bytes_read = read(unlinkd_rfd, rbuf, 511);
 
105
 
 
106
        if (bytes_read > 0) {
 
107
            rbuf[bytes_read] = '\0';
 
108
 
 
109
            for (i = 0; i < bytes_read; i++)
110
110
                if ('\n' == rbuf[i])
111
111
                    queuelen--;
112
112
 
118
118
    assert(l < MAXPATHLEN);
119
119
    xstrncpy(buf, path, MAXPATHLEN);
120
120
    buf[l++] = '\n';
121
 
    x = write(unlinkd_wfd, buf, l);
 
121
    bytes_written = write(unlinkd_wfd, buf, l);
122
122
 
123
 
    if (x < 0) {
 
123
    if (bytes_written < 0) {
124
124
        debugs(2, 1, "unlinkdUnlink: write FD " << unlinkd_wfd << " failed: " << xstrerror());
125
125
        safeunlink(path, 0);
126
126
        return;
127
 
    } else if (x != l) {
128
 
        debugs(2, 1, "unlinkdUnlink: FD " << unlinkd_wfd << " only wrote " << x << " of " << l << " bytes");
 
127
    } else if (bytes_written != l) {
 
128
        debugs(2, 1, "unlinkdUnlink: FD " << unlinkd_wfd << " only wrote " << bytes_written << " of " << l << " bytes");
129
129
        safeunlink(path, 0);
130
130
        return;
131
131
    }
145
145
#ifdef _SQUID_MSWIN_
146
146
{
147
147
 
148
 
    if (unlinkd_wfd > -1)
149
 
    {
 
148
    if (unlinkd_wfd > -1) {
150
149
        debugs(2, 1, "Closing unlinkd pipe on FD " << unlinkd_wfd);
151
150
        shutdown(unlinkd_wfd, SD_BOTH);
152
151
        comm_close(unlinkd_wfd);
160
159
    } else
161
160
        debugs(2, 0, "unlinkdClose: WARNING: unlinkd_wfd is " << unlinkd_wfd);
162
161
 
163
 
    if (hIpc)
164
 
    {
 
162
    if (hIpc) {
165
163
        if (WaitForSingleObject(hIpc, 5000) != WAIT_OBJECT_0) {
166
164
            getCurrentTime();
167
165
            debugs(2, 1, "unlinkdClose: WARNING: (unlinkd," << pid << "d) didn't exit in 5 seconds");
194
192
unlinkdInit(void)
195
193
{
196
194
    const char *args[2];
 
195
    IpAddress localhost;
197
196
 
198
197
    args[0] = "(unlinkd)";
199
198
    args[1] = NULL;
 
199
    localhost.SetLocalhost();
 
200
 
200
201
    pid = ipcCreate(
201
202
#if USE_POLL && defined(_SQUID_OSF_)
202
203
              /* pipes and poll() don't get along on DUNIX -DW */
203
204
              IPC_STREAM,
204
205
#elif defined(_SQUID_MSWIN_)
205
 
/* select() will fail on a pipe */
206
 
IPC_TCP_SOCKET,
 
206
              /* select() will fail on a pipe */
 
207
              IPC_TCP_SOCKET,
207
208
#else
208
 
/* We currently need to use FIFO.. see below */
209
 
IPC_FIFO,
 
209
              /* We currently need to use FIFO.. see below */
 
210
              IPC_FIFO,
210
211
#endif
211
212
              Config.Program.unlinkd,
212
213
              args,
213
214
              "unlinkd",
 
215
              localhost,
214
216
              &unlinkd_rfd,
215
217
              &unlinkd_wfd,
216
218
              &hIpc);