2 * $Id: ipc_win32.cc,v 1.5 2007/12/14 23:11:47 amosjeffries Exp $
4 * DEBUG: section 54 Windows Interprocess Communication
5 * AUTHOR: Andrey Shorin <tolsty@tushino.com>
6 * AUTHOR: Guido Serassio <serassio@squid-cache.org>
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
39 #include "SquidTime.h"
66 static unsigned int __stdcall
ipc_thread_1(void *params
);
67 static unsigned int __stdcall
ipc_thread_2(void *params
);
69 static const char *ok_string
= "OK\n";
70 static const char *err_string
= "ERR\n";
71 static const char *shutdown_string
= "$shutdown\n";
73 static const char *hello_string
= "hi there\n";
74 #define HELLO_BUF_SZ 32
75 static char hello_buf
[HELLO_BUF_SZ
];
78 ipcCloseAllFD(int prfd
, int pwfd
, int crfd
, int cwfd
)
103 env_str
= (char *)xcalloc((tmp_s
= strlen(Config
.debugOptions
) + 32), 1);
104 snprintf(env_str
, tmp_s
, "SQUID_DEBUG=%s", Config
.debugOptions
);
110 ipcCreate(int type
, const char *prog
, const char *const args
[], const char *name
, IPAddress
&local_addr
, int *rfd
, int *wfd
, void **hIpc
)
112 unsigned long thread
;
114 struct ipc_params params
;
116 int optlen
= sizeof(opt
);
121 struct addrinfo
*aiCS
= NULL
;
122 struct addrinfo
*aiPS
= NULL
;
130 requirePathnameExists(name
, prog
);
141 if (WIN32_OS_version
!= _WIN_OS_WINNT
) {
142 getsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, &optlen
);
143 opt
= opt
& ~(SO_SYNCHRONOUS_NONALERT
| SO_SYNCHRONOUS_ALERT
);
144 setsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, sizeof(opt
));
147 if (type
== IPC_TCP_SOCKET
) {
148 crfd
= cwfd
= comm_open(SOCK_STREAM
,
153 prfd
= pwfd
= comm_open(SOCK_STREAM
,
154 IPPROTO_TCP
, /* protocol */
158 } else if (type
== IPC_UDP_SOCKET
) {
159 crfd
= cwfd
= comm_open(SOCK_DGRAM
,
164 prfd
= pwfd
= comm_open(SOCK_DGRAM
,
169 } else if (type
== IPC_FIFO
) {
170 debugs(54, 0, "ipcCreate: " << prog
<< ": use IPC_TCP_SOCKET instead of IP_FIFO on Windows");
176 debugs(54, 3, "ipcCreate: prfd FD " << prfd
);
177 debugs(54, 3, "ipcCreate: pwfd FD " << pwfd
);
178 debugs(54, 3, "ipcCreate: crfd FD " << crfd
);
179 debugs(54, 3, "ipcCreate: cwfd FD " << cwfd
);
181 if (WIN32_OS_version
!= _WIN_OS_WINNT
) {
182 getsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, &optlen
);
183 opt
= opt
| SO_SYNCHRONOUS_NONALERT
;
184 setsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, optlen
);
188 debugs(54, 0, "ipcCreate: Failed to create child FD.");
189 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
193 debugs(54, 0, "ipcCreate: Failed to create server FD.");
194 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
197 // AYJ: these flags should be neutral, but if not IPv6 version needs adding
198 if (type
== IPC_TCP_SOCKET
|| type
== IPC_UDP_SOCKET
) {
200 tmp_addr
.InitAddrInfo(aiPS
);
202 if (getsockname(pwfd
, aiPS
->ai_addr
, &(aiPS
->ai_addrlen
) ) < 0) {
203 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
204 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
209 debugs(54, 3, "ipcCreate: FD " << pwfd
<< " sockaddr " << tmp_addr
);
211 tmp_addr
.InitAddrInfo(aiCS
);
213 if (getsockname(crfd
, aiCS
->ai_addr
, &(aiCS
->ai_addrlen
) ) < 0) {
214 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
215 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
221 debugs(54, 3, "ipcCreate: FD " << crfd
<< " sockaddr " << tmp_addr
);
224 if (type
== IPC_TCP_SOCKET
) {
225 if (listen(crfd
, 1) < 0) {
226 debugs(54, 1, "ipcCreate: listen FD " << crfd
<< ": " << xstrerror());
227 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
230 debugs(54, 3, "ipcCreate: FD " << crfd
<< " listening...");
233 /* flush or else we get dup data if unbuffered_logs is set */
244 params
.local_addr
= local_addr
;
248 params
.args
= (char **) args
;
250 thread
= _beginthreadex(NULL
, 0, ipc_thread_1
, ¶ms
, 0, NULL
);
253 debugs(54, 1, "ipcCreate: _beginthread: " << xstrerror());
254 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
257 /* NP: tmp_addr was left with eiether empty or aiCS in IPAddress format */
258 if (comm_connect_addr(pwfd
, tmp_addr
) == COMM_ERROR
) {
259 CloseHandle((HANDLE
) thread
);
260 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
263 memset(hello_buf
, '\0', HELLO_BUF_SZ
);
264 x
= recv(prfd
, (void *)hello_buf
, HELLO_BUF_SZ
- 1, 0);
267 debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
268 debugs(54, 0, "--> read: " << xstrerror());
269 CloseHandle((HANDLE
) thread
);
270 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
271 } else if (strcmp(hello_buf
, hello_string
)) {
272 debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
273 debugs(54, 0, "--> read returned " << x
);
274 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
275 CloseHandle((HANDLE
) thread
);
276 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
279 x
= send(pwfd
, (const void *)ok_string
, strlen(ok_string
), 0);
282 debugs(54, 0, "ipcCreate: PARENT: OK write test failed");
283 debugs(54, 0, "--> read: " << xstrerror());
284 CloseHandle((HANDLE
) thread
);
285 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
288 memset(hello_buf
, '\0', HELLO_BUF_SZ
);
289 x
= recv(prfd
, (void *)hello_buf
, HELLO_BUF_SZ
- 1, 0);
292 debugs(54, 0, "ipcCreate: PARENT: OK read test failed");
293 debugs(54, 0, "--> read: " << xstrerror());
294 CloseHandle((HANDLE
) thread
);
295 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
296 } else if (!strcmp(hello_buf
, err_string
)) {
297 debugs(54, 0, "ipcCreate: PARENT: OK read test failed");
298 debugs(54, 0, "--> read returned " << x
);
299 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
300 CloseHandle((HANDLE
) thread
);
301 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
305 pid
= atol(hello_buf
);
306 commSetTimeout(prfd
, -1, NULL
, NULL
);
307 commSetNonBlocking(prfd
);
308 commSetNonBlocking(pwfd
);
309 commSetCloseOnExec(prfd
);
310 commSetCloseOnExec(pwfd
);
318 fd_table
[prfd
].flags
.ipc
= 1;
320 fd_table
[pwfd
].flags
.ipc
= 1;
322 fd_table
[crfd
].flags
.ipc
= 1;
324 fd_table
[cwfd
].flags
.ipc
= 1;
326 if (Config
.sleep_after_fork
) {
327 /* XXX emulation of usleep() */
329 sl
= Config
.sleep_after_fork
/ 1000;
337 if (GetExitCodeThread((HANDLE
) thread
, &ecode
) && ecode
== STILL_ACTIVE
) {
339 *hIpc
= (HANDLE
) thread
;
343 CloseHandle((HANDLE
) thread
);
344 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
349 ipcSend(int cwfd
, const char *buf
, int len
)
353 x
= send(cwfd
, (const void *)buf
, len
, 0);
356 debugs(54, 0, "sendto FD " << cwfd
<< ": " << xstrerror());
357 debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
363 static unsigned int __stdcall
364 ipc_thread_1(void *in_params
)
366 int t1
, t2
, t3
, retval
= -1;
371 HANDLE hProcess
= NULL
, thread
= NULL
;
374 struct thread_params thread_params
;
379 PROCESS_INFORMATION pi
;
381 int prfd_ipc
= -1, pwfd_ipc
= -1, crfd_ipc
= -1, cwfd_ipc
= -1;
382 char *prog
= NULL
, *buf1
= NULL
;
386 struct addrinfo
*aiPS_ipc
= NULL
;
387 struct addrinfo
*aiCS_ipc
= NULL
;
389 struct ipc_params
*params
= (struct ipc_params
*) in_params
;
390 int type
= params
->type
;
391 int crfd
= params
->crfd
;
392 int cwfd
= params
->cwfd
;
393 char **args
= params
->args
;
395 IPAddress PS
= params
->PS
;
396 IPAddress local_addr
= params
->local_addr
;
398 buf1
= (char *)xcalloc(1, 8192);
399 strcpy(buf1
, params
->prog
);
400 prog
= strtok(buf1
, w_space
);
402 if ((str
= strrchr(prog
, '/')))
405 if ((str
= strrchr(prog
, '\\')))
408 prog
= xstrdup(prog
);
410 if (type
== IPC_TCP_SOCKET
) {
411 debugs(54, 3, "ipcCreate: calling accept on FD " << crfd
);
413 if ((fd
= accept(crfd
, NULL
, NULL
)) < 0) {
414 debugs(54, 0, "ipcCreate: FD " << crfd
<< " accept: " << xstrerror());
418 debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd
);
420 snprintf(buf1
, 8191, "%s CHILD socket", prog
);
421 fd_open(fd
, FD_SOCKET
, buf1
);
422 fd_table
[fd
].flags
.ipc
= 1;
424 } else if (type
== IPC_UDP_SOCKET
) {
425 if (comm_connect_addr(crfd
, params
->PS
) == COMM_ERROR
)
429 x
= send(cwfd
, (const void *)hello_string
, strlen(hello_string
) + 1, 0);
432 debugs(54, 0, "sendto FD " << cwfd
<< ": " << xstrerror());
433 debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
438 memset(buf1
, '\0', sizeof(buf1
));
439 x
= recv(crfd
, (void *)buf1
, 8191, 0);
442 debugs(54, 0, "ipcCreate: CHILD: OK read test failed");
443 debugs(54, 0, "--> read: " << xstrerror());
445 } else if (strcmp(buf1
, ok_string
)) {
446 debugs(54, 0, "ipcCreate: CHILD: OK read test failed");
447 debugs(54, 0, "--> read returned " << x
);
448 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
452 /* assign file descriptors to child process */
453 if (_pipe(p2c
, 1024, _O_BINARY
| _O_NOINHERIT
) < 0) {
454 debugs(54, 0, "ipcCreate: CHILD: pipe: " << xstrerror());
455 ipcSend(cwfd
, err_string
, strlen(err_string
));
459 if (_pipe(c2p
, 1024, _O_BINARY
| _O_NOINHERIT
) < 0) {
460 debugs(54, 0, "ipcCreate: CHILD: pipe: " << xstrerror());
461 ipcSend(cwfd
, err_string
, strlen(err_string
));
465 if (type
== IPC_UDP_SOCKET
) {
466 snprintf(buf1
, 8192, "%s(%ld) <-> ipc CHILD socket", prog
, -1L);
467 crfd_ipc
= cwfd_ipc
= comm_open(SOCK_DGRAM
, IPPROTO_UDP
, local_addr
, 0, buf1
);
470 debugs(54, 0, "ipcCreate: CHILD: Failed to create child FD for " << prog
<< ".");
471 ipcSend(cwfd
, err_string
, strlen(err_string
));
475 snprintf(buf1
, 8192, "%s(%ld) <-> ipc PARENT socket", prog
, -1L);
476 prfd_ipc
= pwfd_ipc
= comm_open(SOCK_DGRAM
, IPPROTO_UDP
, local_addr
, 0, buf1
);
479 debugs(54, 0, "ipcCreate: CHILD: Failed to create server FD for " << prog
<< ".");
480 ipcSend(cwfd
, err_string
, strlen(err_string
));
484 PS_ipc
.InitAddrInfo(aiPS_ipc
);
486 if (getsockname(pwfd_ipc
, aiPS_ipc
->ai_addr
, &(aiPS_ipc
->ai_addrlen
)) < 0) {
487 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
488 ipcSend(cwfd
, err_string
, strlen(err_string
));
494 debugs(54, 3, "ipcCreate: FD " << pwfd_ipc
<< " sockaddr " << PS_ipc
);
496 CS_ipc
.InitAddrInfo(aiCS_ipc
);
498 if (getsockname(crfd_ipc
, aiCS_ipc
->ai_addr
, &(aiCS_ipc
->ai_addrlen
)) < 0) {
499 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
500 ipcSend(cwfd
, err_string
, strlen(err_string
));
506 debugs(54, 3, "ipcCreate: FD " << crfd_ipc
<< " sockaddr " << CS_ipc
);
508 if (comm_connect_addr(pwfd_ipc
, CS_ipc
) == COMM_ERROR
) {
509 ipcSend(cwfd
, err_string
, strlen(err_string
));
515 if (comm_connect_addr(crfd_ipc
, PS_ipc
) == COMM_ERROR
) {
516 ipcSend(cwfd
, err_string
, strlen(err_string
));
519 } /* IPC_UDP_SOCKET */
531 dup2(fileno(debug_log
), 2);
537 commUnsetNonBlocking(fd
);
539 memset(&si
, 0, sizeof(STARTUPINFO
));
541 si
.cb
= sizeof(STARTUPINFO
);
543 si
.hStdInput
= (HANDLE
) _get_osfhandle(0);
545 si
.hStdOutput
= (HANDLE
) _get_osfhandle(1);
547 si
.hStdError
= (HANDLE
) _get_osfhandle(2);
549 si
.dwFlags
= STARTF_USESTDHANDLES
;
551 /* Make sure all other valid handles are not inerithable */
552 for (x
= 3; x
< Squid_MaxFD
; x
++) {
553 if ((F
= _get_osfhandle(x
)) == -1)
556 SetHandleInformation((HANDLE
) F
, HANDLE_FLAG_INHERIT
, 0);
560 strcpy(buf1
+ 4096, params
->prog
);
561 str
= strtok(buf1
+ 4096, w_space
);
566 } while ((str
= strtok(NULL
, w_space
)));
571 strcat(buf1
, args
[x
++]);
575 if (CreateProcess(buf1
+ 4096, buf1
, NULL
, NULL
, TRUE
, CREATE_NO_WINDOW
,
576 NULL
, NULL
, &si
, &pi
)) {
577 pid
= pi
.dwProcessId
;
578 hProcess
= pi
.hProcess
;
581 WIN32_maperror(GetLastError());
594 debugs(54, 0, "ipcCreate: CHILD: " << params
->prog
<< ": " << xstrerror());
596 ipcSend(cwfd
, err_string
, strlen(err_string
));
600 if (type
== IPC_UDP_SOCKET
) {
601 WSAPROTOCOL_INFO wpi
;
603 memset(&wpi
, 0, sizeof(wpi
));
605 if (SOCKET_ERROR
== WSADuplicateSocket(crfd_ipc
, pid
, &wpi
)) {
606 debugs(54, 0, "ipcCreate: CHILD: WSADuplicateSocket: " << xstrerror());
608 ipcSend(cwfd
, err_string
, strlen(err_string
));
612 x
= write(c2p
[1], (const char *) &wpi
, sizeof(wpi
));
614 if (x
< (ssize_t
)sizeof(wpi
)) {
615 debugs(54, 0, "ipcCreate: CHILD: write FD " << c2p
[1] << ": " << xstrerror());
616 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
618 ipcSend(cwfd
, err_string
, strlen(err_string
));
622 x
= read(p2c
[0], buf1
, 8192);
625 debugs(54, 0, "ipcCreate: CHILD: read FD " << p2c
[0] << ": " << xstrerror());
626 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
628 ipcSend(cwfd
, err_string
, strlen(err_string
));
630 } else if (strncmp(buf1
, ok_string
, strlen(ok_string
))) {
631 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
632 debugs(54, 0, "--> read returned " << x
);
634 debugs(54, 0, "--> got '" << rfc1738_escape(buf1
) << "'");
635 ipcSend(cwfd
, err_string
, strlen(err_string
));
639 x
= write(c2p
[1], (const char *) &PS_ipc
, sizeof(PS_ipc
));
641 if (x
< (ssize_t
)sizeof(PS_ipc
)) {
642 debugs(54, 0, "ipcCreate: CHILD: write FD " << c2p
[1] << ": " << xstrerror());
643 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
645 ipcSend(cwfd
, err_string
, strlen(err_string
));
649 x
= read(p2c
[0], buf1
, 8192);
652 debugs(54, 0, "ipcCreate: CHILD: read FD " << p2c
[0] << ": " << xstrerror());
653 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
655 ipcSend(cwfd
, err_string
, strlen(err_string
));
657 } else if (strncmp(buf1
, ok_string
, strlen(ok_string
))) {
658 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
659 debugs(54, 0, "--> read returned " << x
);
661 debugs(54, 0, "--> got '" << rfc1738_escape(buf1
) << "'");
662 ipcSend(cwfd
, err_string
, strlen(err_string
));
666 x
= send(pwfd_ipc
, (const void *)ok_string
, strlen(ok_string
), 0);
667 x
= recv(prfd_ipc
, (void *)(buf1
+ 200), 8191 - 200, 0);
668 assert((size_t) x
== strlen(ok_string
)
669 && !strncmp(ok_string
, buf1
+ 200, strlen(ok_string
)));
670 } /* IPC_UDP_SOCKET */
672 snprintf(buf1
, 8191, "%s(%ld) CHILD socket", prog
, (long int) pid
);
676 if (prfd_ipc
!= -1) {
677 snprintf(buf1
, 8191, "%s(%ld) <-> ipc CHILD socket", prog
, (long int) pid
);
678 fd_note(crfd_ipc
, buf1
);
679 snprintf(buf1
, 8191, "%s(%ld) <-> ipc PARENT socket", prog
, (long int) pid
);
680 fd_note(prfd_ipc
, buf1
);
683 /* else { IPC_TCP_SOCKET */
684 /* commSetNoLinger(fd); */
686 thread_params
.prog
= prog
;
688 thread_params
.send_fd
= cwfd
;
690 thread_params
.pid
= pid
;
692 if ((thread_params
.type
= type
) == IPC_TCP_SOCKET
)
693 thread_params
.rfd
= p2c
[0];
695 thread_params
.rfd
= prfd_ipc
;
698 (HANDLE
) _beginthreadex(NULL
, 0, ipc_thread_2
, &thread_params
, 0, NULL
);
701 debugs(54, 0, "ipcCreate: CHILD: _beginthreadex: " << xstrerror());
702 ipcSend(cwfd
, err_string
, strlen(err_string
));
706 snprintf(buf1
, 8191, "%ld\n", (long int) pid
);
708 if (-1 == ipcSend(cwfd
, buf1
, strlen(buf1
)))
711 debugs(54, 2, "ipc(" << prog
<< "," << pid
<< "): started successfully");
715 x
= recv(crfd
, (void *)buf1
, 8192, 0);
718 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes received from parent. Exiting...");
724 if (type
== IPC_UDP_SOCKET
&& !strcmp(buf1
, shutdown_string
)) {
725 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): request for shutdown received from parent. Exiting...");
727 TerminateProcess(hProcess
, 0);
731 debugs(54, 5, "ipc(" << prog
<< "," << pid
<< "): received from parent: " << rfc1738_escape_unescaped(buf1
));
733 if (type
== IPC_TCP_SOCKET
)
734 x
= write(c2p
[1], buf1
, x
);
736 x
= send(pwfd_ipc
, (const void *)buf1
, x
, 0);
739 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes written to " << prog
<< ". Exiting...");
752 if (fd_table
[crfd
].flags
.open
)
753 ipcCloseAllFD(-1, -1, crfd
, cwfd
);
755 if (prfd_ipc
!= -1) {
756 send(crfd_ipc
, (const void *)shutdown_string
, strlen(shutdown_string
), 0);
757 shutdown(crfd_ipc
, SD_BOTH
);
758 shutdown(prfd_ipc
, SD_BOTH
);
761 ipcCloseAllFD(prfd_ipc
, pwfd_ipc
, crfd_ipc
, cwfd_ipc
);
763 if (hProcess
&& WAIT_OBJECT_0
!=
764 WaitForSingleObject(hProcess
, type
== IPC_UDP_SOCKET
? 12000 : 5000)) {
767 debugs(54, 0, "ipc(" << prog
<< "," << pid
<< "): WARNING: " << prog
<<
768 " didn't exit in " << (type
== IPC_UDP_SOCKET
? 12 : 5) << " seconds.");
772 if (thread
&& WAIT_OBJECT_0
!= WaitForSingleObject(thread
, 3000)) {
774 debugs(54, 0, "ipc(" << prog
<< "," << pid
<< "): WARNING: ipc_thread_2 didn't exit in 3 seconds.");
781 debugs(54, 2, "ipc(" << prog
<< "," << pid
<< "): normal exit");
793 CloseHandle(hProcess
);
801 static unsigned int __stdcall
802 ipc_thread_2(void *in_params
)
806 struct thread_params
*params
= (struct thread_params
*) in_params
;
807 int type
= params
->type
;
808 int rfd
= params
->rfd
;
809 int send_fd
= params
->send_fd
;
810 char *prog
= xstrdup(params
->prog
);
811 pid_t pid
= params
->pid
;
812 char *buf2
= (char *)xcalloc(1, 8192);
815 if (type
== IPC_TCP_SOCKET
)
816 x
= read(rfd
, buf2
, 8192);
818 x
= recv(rfd
, (void *)buf2
, 8192, 0);
820 if ((x
<= 0 && type
== IPC_TCP_SOCKET
) ||
821 (x
< 0 && type
== IPC_UDP_SOCKET
)) {
822 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes read from " << prog
<< ". Exiting...");
829 if (type
== IPC_UDP_SOCKET
&& !strcmp(buf2
, shutdown_string
)) {
830 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): request for shutdown received. Exiting...");
836 if ((buf2
[x
- 1] == '\n') && (buf2
[x
- 2] == '\r')) {
843 debugs(54, 5, "ipc(" << prog
<< "," << pid
<< "): received from child : " << rfc1738_escape_unescaped(buf2
));
845 x
= send(send_fd
, (const void *)buf2
, x
, 0);
847 if ((x
<= 0 && type
== IPC_TCP_SOCKET
) ||
848 (x
< 0 && type
== IPC_UDP_SOCKET
)) {
849 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes sent to parent. Exiting...");