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"
56 struct thread_params
{
64 static unsigned int __stdcall
ipc_thread_1(void *params
);
65 static unsigned int __stdcall
ipc_thread_2(void *params
);
67 static const char *ok_string
= "OK\n";
68 static const char *err_string
= "ERR\n";
69 static const char *shutdown_string
= "$shutdown\n";
71 static const char *hello_string
= "hi there\n";
72 #define HELLO_BUF_SZ 32
73 static char hello_buf
[HELLO_BUF_SZ
];
76 ipcCloseAllFD(int prfd
, int pwfd
, int crfd
, int cwfd
)
101 env_str
= (char *)xcalloc((tmp_s
= strlen(Config
.debugOptions
) + 32), 1);
102 snprintf(env_str
, tmp_s
, "SQUID_DEBUG=%s", Config
.debugOptions
);
108 ipcCreate(int type
, const char *prog
, const char *const args
[], const char *name
, IpAddress
&local_addr
, int *rfd
, int *wfd
, void **hIpc
)
110 unsigned long thread
;
112 struct ipc_params params
;
114 int optlen
= sizeof(opt
);
119 struct addrinfo
*aiCS
= NULL
;
120 struct addrinfo
*aiPS
= NULL
;
128 requirePathnameExists(name
, prog
);
139 if (WIN32_OS_version
!= _WIN_OS_WINNT
) {
140 getsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, &optlen
);
141 opt
= opt
& ~(SO_SYNCHRONOUS_NONALERT
| SO_SYNCHRONOUS_ALERT
);
142 setsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, sizeof(opt
));
145 if (type
== IPC_TCP_SOCKET
) {
146 crfd
= cwfd
= comm_open(SOCK_STREAM
,
151 prfd
= pwfd
= comm_open(SOCK_STREAM
,
152 IPPROTO_TCP
, /* protocol */
156 } else if (type
== IPC_UDP_SOCKET
) {
157 crfd
= cwfd
= comm_open(SOCK_DGRAM
,
162 prfd
= pwfd
= comm_open(SOCK_DGRAM
,
167 } else if (type
== IPC_FIFO
) {
168 debugs(54, 0, "ipcCreate: " << prog
<< ": use IPC_TCP_SOCKET instead of IP_FIFO on Windows");
174 debugs(54, 3, "ipcCreate: prfd FD " << prfd
);
175 debugs(54, 3, "ipcCreate: pwfd FD " << pwfd
);
176 debugs(54, 3, "ipcCreate: crfd FD " << crfd
);
177 debugs(54, 3, "ipcCreate: cwfd FD " << cwfd
);
179 if (WIN32_OS_version
!= _WIN_OS_WINNT
) {
180 getsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, &optlen
);
181 opt
= opt
| SO_SYNCHRONOUS_NONALERT
;
182 setsockopt(INVALID_SOCKET
, SOL_SOCKET
, SO_OPENTYPE
, (char *) &opt
, optlen
);
186 debugs(54, 0, "ipcCreate: Failed to create child FD.");
187 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
191 debugs(54, 0, "ipcCreate: Failed to create server FD.");
192 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
195 // AYJ: these flags should be neutral, but if not IPv6 version needs adding
196 if (type
== IPC_TCP_SOCKET
|| type
== IPC_UDP_SOCKET
) {
198 tmp_addr
.InitAddrInfo(aiPS
);
200 if (getsockname(pwfd
, aiPS
->ai_addr
, &(aiPS
->ai_addrlen
) ) < 0) {
201 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
202 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
207 debugs(54, 3, "ipcCreate: FD " << pwfd
<< " sockaddr " << tmp_addr
);
209 tmp_addr
.InitAddrInfo(aiCS
);
211 if (getsockname(crfd
, aiCS
->ai_addr
, &(aiCS
->ai_addrlen
) ) < 0) {
212 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
213 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
219 debugs(54, 3, "ipcCreate: FD " << crfd
<< " sockaddr " << tmp_addr
);
222 if (type
== IPC_TCP_SOCKET
) {
223 if (listen(crfd
, 1) < 0) {
224 debugs(54, 1, "ipcCreate: listen FD " << crfd
<< ": " << xstrerror());
225 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
228 debugs(54, 3, "ipcCreate: FD " << crfd
<< " listening...");
231 /* flush or else we get dup data if unbuffered_logs is set */
242 params
.local_addr
= local_addr
;
246 params
.args
= (char **) args
;
248 thread
= _beginthreadex(NULL
, 0, ipc_thread_1
, ¶ms
, 0, NULL
);
251 debugs(54, 1, "ipcCreate: _beginthread: " << xstrerror());
252 return ipcCloseAllFD(prfd
, pwfd
, crfd
, cwfd
);
255 /* NP: tmp_addr was left with eiether empty or aiCS in IpAddress format */
256 if (comm_connect_addr(pwfd
, tmp_addr
) == COMM_ERROR
) {
257 CloseHandle((HANDLE
) thread
);
258 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
261 memset(hello_buf
, '\0', HELLO_BUF_SZ
);
262 x
= recv(prfd
, (void *)hello_buf
, HELLO_BUF_SZ
- 1, 0);
265 debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
266 debugs(54, 0, "--> read: " << xstrerror());
267 CloseHandle((HANDLE
) thread
);
268 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
269 } else if (strcmp(hello_buf
, hello_string
)) {
270 debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
271 debugs(54, 0, "--> read returned " << x
);
272 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
273 CloseHandle((HANDLE
) thread
);
274 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
277 x
= send(pwfd
, (const void *)ok_string
, strlen(ok_string
), 0);
280 debugs(54, 0, "ipcCreate: PARENT: OK write test failed");
281 debugs(54, 0, "--> read: " << xstrerror());
282 CloseHandle((HANDLE
) thread
);
283 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
286 memset(hello_buf
, '\0', HELLO_BUF_SZ
);
287 x
= recv(prfd
, (void *)hello_buf
, HELLO_BUF_SZ
- 1, 0);
290 debugs(54, 0, "ipcCreate: PARENT: OK read test failed");
291 debugs(54, 0, "--> read: " << xstrerror());
292 CloseHandle((HANDLE
) thread
);
293 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
294 } else if (!strcmp(hello_buf
, err_string
)) {
295 debugs(54, 0, "ipcCreate: PARENT: OK read test failed");
296 debugs(54, 0, "--> read returned " << x
);
297 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
298 CloseHandle((HANDLE
) thread
);
299 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
303 pid
= atol(hello_buf
);
304 commSetTimeout(prfd
, -1, NULL
, NULL
);
305 commSetNonBlocking(prfd
);
306 commSetNonBlocking(pwfd
);
307 commSetCloseOnExec(prfd
);
308 commSetCloseOnExec(pwfd
);
316 fd_table
[prfd
].flags
.ipc
= 1;
318 fd_table
[pwfd
].flags
.ipc
= 1;
320 fd_table
[crfd
].flags
.ipc
= 1;
322 fd_table
[cwfd
].flags
.ipc
= 1;
324 if (Config
.sleep_after_fork
) {
325 /* XXX emulation of usleep() */
327 sl
= Config
.sleep_after_fork
/ 1000;
335 if (GetExitCodeThread((HANDLE
) thread
, &ecode
) && ecode
== STILL_ACTIVE
) {
337 *hIpc
= (HANDLE
) thread
;
341 CloseHandle((HANDLE
) thread
);
342 return ipcCloseAllFD(prfd
, pwfd
, -1, -1);
347 ipcSend(int cwfd
, const char *buf
, int len
)
351 x
= send(cwfd
, (const void *)buf
, len
, 0);
354 debugs(54, 0, "sendto FD " << cwfd
<< ": " << xstrerror());
355 debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
361 static unsigned int __stdcall
362 ipc_thread_1(void *in_params
)
364 int t1
, t2
, t3
, retval
= -1;
365 int p2c
[2] = {-1, -1};
366 int c2p
[2] = {-1, -1};
367 HANDLE hProcess
= NULL
, thread
= NULL
;
370 struct thread_params thread_params
;
375 PROCESS_INFORMATION pi
;
377 int prfd_ipc
= -1, pwfd_ipc
= -1, crfd_ipc
= -1, cwfd_ipc
= -1;
378 char *prog
= NULL
, *buf1
= NULL
;
382 struct addrinfo
*aiPS_ipc
= NULL
;
383 struct addrinfo
*aiCS_ipc
= NULL
;
385 struct ipc_params
*params
= (struct ipc_params
*) in_params
;
386 int type
= params
->type
;
387 int crfd
= params
->crfd
;
388 int cwfd
= params
->cwfd
;
389 char **args
= params
->args
;
391 IpAddress PS
= params
->PS
;
392 IpAddress local_addr
= params
->local_addr
;
394 buf1
= (char *)xcalloc(1, 8192);
395 strcpy(buf1
, params
->prog
);
396 prog
= strtok(buf1
, w_space
);
398 if ((str
= strrchr(prog
, '/')))
401 if ((str
= strrchr(prog
, '\\')))
404 prog
= xstrdup(prog
);
406 if (type
== IPC_TCP_SOCKET
) {
407 debugs(54, 3, "ipcCreate: calling accept on FD " << crfd
);
409 if ((fd
= accept(crfd
, NULL
, NULL
)) < 0) {
410 debugs(54, 0, "ipcCreate: FD " << crfd
<< " accept: " << xstrerror());
414 debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd
);
416 snprintf(buf1
, 8191, "%s CHILD socket", prog
);
417 fd_open(fd
, FD_SOCKET
, buf1
);
418 fd_table
[fd
].flags
.ipc
= 1;
420 } else if (type
== IPC_UDP_SOCKET
) {
421 if (comm_connect_addr(crfd
, params
->PS
) == COMM_ERROR
)
425 x
= send(cwfd
, (const void *)hello_string
, strlen(hello_string
) + 1, 0);
428 debugs(54, 0, "sendto FD " << cwfd
<< ": " << xstrerror());
429 debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
434 memset(buf1
, '\0', sizeof(buf1
));
435 x
= recv(crfd
, (void *)buf1
, 8191, 0);
438 debugs(54, 0, "ipcCreate: CHILD: OK read test failed");
439 debugs(54, 0, "--> read: " << xstrerror());
441 } else if (strcmp(buf1
, ok_string
)) {
442 debugs(54, 0, "ipcCreate: CHILD: OK read test failed");
443 debugs(54, 0, "--> read returned " << x
);
444 debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf
) << "'");
448 /* assign file descriptors to child process */
449 if (_pipe(p2c
, 1024, _O_BINARY
| _O_NOINHERIT
) < 0) {
450 debugs(54, 0, "ipcCreate: CHILD: pipe: " << xstrerror());
451 ipcSend(cwfd
, err_string
, strlen(err_string
));
455 if (_pipe(c2p
, 1024, _O_BINARY
| _O_NOINHERIT
) < 0) {
456 debugs(54, 0, "ipcCreate: CHILD: pipe: " << xstrerror());
457 ipcSend(cwfd
, err_string
, strlen(err_string
));
461 if (type
== IPC_UDP_SOCKET
) {
462 snprintf(buf1
, 8192, "%s(%ld) <-> ipc CHILD socket", prog
, -1L);
463 crfd_ipc
= cwfd_ipc
= comm_open(SOCK_DGRAM
, IPPROTO_UDP
, local_addr
, 0, buf1
);
466 debugs(54, 0, "ipcCreate: CHILD: Failed to create child FD for " << prog
<< ".");
467 ipcSend(cwfd
, err_string
, strlen(err_string
));
471 snprintf(buf1
, 8192, "%s(%ld) <-> ipc PARENT socket", prog
, -1L);
472 prfd_ipc
= pwfd_ipc
= comm_open(SOCK_DGRAM
, IPPROTO_UDP
, local_addr
, 0, buf1
);
475 debugs(54, 0, "ipcCreate: CHILD: Failed to create server FD for " << prog
<< ".");
476 ipcSend(cwfd
, err_string
, strlen(err_string
));
480 PS_ipc
.InitAddrInfo(aiPS_ipc
);
482 if (getsockname(pwfd_ipc
, aiPS_ipc
->ai_addr
, &(aiPS_ipc
->ai_addrlen
)) < 0) {
483 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
484 ipcSend(cwfd
, err_string
, strlen(err_string
));
490 debugs(54, 3, "ipcCreate: FD " << pwfd_ipc
<< " sockaddr " << PS_ipc
);
492 CS_ipc
.InitAddrInfo(aiCS_ipc
);
494 if (getsockname(crfd_ipc
, aiCS_ipc
->ai_addr
, &(aiCS_ipc
->ai_addrlen
)) < 0) {
495 debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
496 ipcSend(cwfd
, err_string
, strlen(err_string
));
502 debugs(54, 3, "ipcCreate: FD " << crfd_ipc
<< " sockaddr " << CS_ipc
);
504 if (comm_connect_addr(pwfd_ipc
, CS_ipc
) == COMM_ERROR
) {
505 ipcSend(cwfd
, err_string
, strlen(err_string
));
511 if (comm_connect_addr(crfd_ipc
, PS_ipc
) == COMM_ERROR
) {
512 ipcSend(cwfd
, err_string
, strlen(err_string
));
515 } /* IPC_UDP_SOCKET */
527 dup2(fileno(debug_log
), 2);
533 commUnsetNonBlocking(fd
);
535 memset(&si
, 0, sizeof(STARTUPINFO
));
537 si
.cb
= sizeof(STARTUPINFO
);
539 si
.hStdInput
= (HANDLE
) _get_osfhandle(0);
541 si
.hStdOutput
= (HANDLE
) _get_osfhandle(1);
543 si
.hStdError
= (HANDLE
) _get_osfhandle(2);
545 si
.dwFlags
= STARTF_USESTDHANDLES
;
547 /* Make sure all other valid handles are not inerithable */
548 for (x
= 3; x
< Squid_MaxFD
; x
++) {
549 if ((F
= _get_osfhandle(x
)) == -1)
552 SetHandleInformation((HANDLE
) F
, HANDLE_FLAG_INHERIT
, 0);
556 strcpy(buf1
+ 4096, params
->prog
);
557 str
= strtok(buf1
+ 4096, w_space
);
562 } while ((str
= strtok(NULL
, w_space
)));
567 strcat(buf1
, args
[x
++]);
571 if (CreateProcess(buf1
+ 4096, buf1
, NULL
, NULL
, TRUE
, CREATE_NO_WINDOW
,
572 NULL
, NULL
, &si
, &pi
)) {
573 pid
= pi
.dwProcessId
;
574 hProcess
= pi
.hProcess
;
577 WIN32_maperror(GetLastError());
590 debugs(54, 0, "ipcCreate: CHILD: " << params
->prog
<< ": " << xstrerror());
592 ipcSend(cwfd
, err_string
, strlen(err_string
));
596 if (type
== IPC_UDP_SOCKET
) {
597 WSAPROTOCOL_INFO wpi
;
599 memset(&wpi
, 0, sizeof(wpi
));
601 if (SOCKET_ERROR
== WSADuplicateSocket(crfd_ipc
, pid
, &wpi
)) {
602 debugs(54, 0, "ipcCreate: CHILD: WSADuplicateSocket: " << xstrerror());
604 ipcSend(cwfd
, err_string
, strlen(err_string
));
608 x
= write(c2p
[1], (const char *) &wpi
, sizeof(wpi
));
610 if (x
< (ssize_t
)sizeof(wpi
)) {
611 debugs(54, 0, "ipcCreate: CHILD: write FD " << c2p
[1] << ": " << xstrerror());
612 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
614 ipcSend(cwfd
, err_string
, strlen(err_string
));
618 x
= read(p2c
[0], buf1
, 8192);
621 debugs(54, 0, "ipcCreate: CHILD: read FD " << p2c
[0] << ": " << xstrerror());
622 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
624 ipcSend(cwfd
, err_string
, strlen(err_string
));
626 } else if (strncmp(buf1
, ok_string
, strlen(ok_string
))) {
627 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
628 debugs(54, 0, "--> read returned " << x
);
630 debugs(54, 0, "--> got '" << rfc1738_escape(buf1
) << "'");
631 ipcSend(cwfd
, err_string
, strlen(err_string
));
635 x
= write(c2p
[1], (const char *) &PS_ipc
, sizeof(PS_ipc
));
637 if (x
< (ssize_t
)sizeof(PS_ipc
)) {
638 debugs(54, 0, "ipcCreate: CHILD: write FD " << c2p
[1] << ": " << xstrerror());
639 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
641 ipcSend(cwfd
, err_string
, strlen(err_string
));
645 x
= read(p2c
[0], buf1
, 8192);
648 debugs(54, 0, "ipcCreate: CHILD: read FD " << p2c
[0] << ": " << xstrerror());
649 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
651 ipcSend(cwfd
, err_string
, strlen(err_string
));
653 } else if (strncmp(buf1
, ok_string
, strlen(ok_string
))) {
654 debugs(54, 0, "ipcCreate: CHILD: " << prog
<< ": socket exchange failed");
655 debugs(54, 0, "--> read returned " << x
);
657 debugs(54, 0, "--> got '" << rfc1738_escape(buf1
) << "'");
658 ipcSend(cwfd
, err_string
, strlen(err_string
));
662 x
= send(pwfd_ipc
, (const void *)ok_string
, strlen(ok_string
), 0);
663 x
= recv(prfd_ipc
, (void *)(buf1
+ 200), 8191 - 200, 0);
664 assert((size_t) x
== strlen(ok_string
)
665 && !strncmp(ok_string
, buf1
+ 200, strlen(ok_string
)));
666 } /* IPC_UDP_SOCKET */
668 snprintf(buf1
, 8191, "%s(%ld) CHILD socket", prog
, (long int) pid
);
672 if (prfd_ipc
!= -1) {
673 snprintf(buf1
, 8191, "%s(%ld) <-> ipc CHILD socket", prog
, (long int) pid
);
674 fd_note(crfd_ipc
, buf1
);
675 snprintf(buf1
, 8191, "%s(%ld) <-> ipc PARENT socket", prog
, (long int) pid
);
676 fd_note(prfd_ipc
, buf1
);
679 /* else { IPC_TCP_SOCKET */
680 /* commSetNoLinger(fd); */
682 thread_params
.prog
= prog
;
684 thread_params
.send_fd
= cwfd
;
686 thread_params
.pid
= pid
;
688 if ((thread_params
.type
= type
) == IPC_TCP_SOCKET
)
689 thread_params
.rfd
= p2c
[0];
691 thread_params
.rfd
= prfd_ipc
;
694 (HANDLE
) _beginthreadex(NULL
, 0, ipc_thread_2
, &thread_params
, 0, NULL
);
697 debugs(54, 0, "ipcCreate: CHILD: _beginthreadex: " << xstrerror());
698 ipcSend(cwfd
, err_string
, strlen(err_string
));
702 snprintf(buf1
, 8191, "%ld\n", (long int) pid
);
704 if (-1 == ipcSend(cwfd
, buf1
, strlen(buf1
)))
707 debugs(54, 2, "ipc(" << prog
<< "," << pid
<< "): started successfully");
711 x
= recv(crfd
, (void *)buf1
, 8192, 0);
714 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes received from parent. Exiting...");
720 if (type
== IPC_UDP_SOCKET
&& !strcmp(buf1
, shutdown_string
)) {
721 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): request for shutdown received from parent. Exiting...");
723 TerminateProcess(hProcess
, 0);
727 debugs(54, 5, "ipc(" << prog
<< "," << pid
<< "): received from parent: " << rfc1738_escape_unescaped(buf1
));
729 if (type
== IPC_TCP_SOCKET
)
730 x
= write(c2p
[1], buf1
, x
);
732 x
= send(pwfd_ipc
, (const void *)buf1
, x
, 0);
735 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes written to " << prog
<< ". Exiting...");
748 if (fd_table
[crfd
].flags
.open
)
749 ipcCloseAllFD(-1, -1, crfd
, cwfd
);
751 if (prfd_ipc
!= -1) {
752 send(crfd_ipc
, (const void *)shutdown_string
, strlen(shutdown_string
), 0);
753 shutdown(crfd_ipc
, SD_BOTH
);
754 shutdown(prfd_ipc
, SD_BOTH
);
757 ipcCloseAllFD(prfd_ipc
, pwfd_ipc
, crfd_ipc
, cwfd_ipc
);
759 if (hProcess
&& WAIT_OBJECT_0
!=
760 WaitForSingleObject(hProcess
, type
== IPC_UDP_SOCKET
? 12000 : 5000)) {
763 debugs(54, 0, "ipc(" << prog
<< "," << pid
<< "): WARNING: " << prog
<<
764 " didn't exit in " << (type
== IPC_UDP_SOCKET
? 12 : 5) << " seconds.");
768 if (thread
&& WAIT_OBJECT_0
!= WaitForSingleObject(thread
, 3000)) {
770 debugs(54, 0, "ipc(" << prog
<< "," << pid
<< "): WARNING: ipc_thread_2 didn't exit in 3 seconds.");
777 debugs(54, 2, "ipc(" << prog
<< "," << pid
<< "): normal exit");
789 CloseHandle(hProcess
);
797 static unsigned int __stdcall
798 ipc_thread_2(void *in_params
)
802 struct thread_params
*params
= (struct thread_params
*) in_params
;
803 int type
= params
->type
;
804 int rfd
= params
->rfd
;
805 int send_fd
= params
->send_fd
;
806 char *prog
= xstrdup(params
->prog
);
807 pid_t pid
= params
->pid
;
808 char *buf2
= (char *)xcalloc(1, 8192);
811 if (type
== IPC_TCP_SOCKET
)
812 x
= read(rfd
, buf2
, 8192);
814 x
= recv(rfd
, (void *)buf2
, 8192, 0);
816 if ((x
<= 0 && type
== IPC_TCP_SOCKET
) ||
817 (x
< 0 && type
== IPC_UDP_SOCKET
)) {
818 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes read from " << prog
<< ". Exiting...");
825 if (type
== IPC_UDP_SOCKET
&& !strcmp(buf2
, shutdown_string
)) {
826 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): request for shutdown received. Exiting...");
832 if ((buf2
[x
- 1] == '\n') && (buf2
[x
- 2] == '\r')) {
839 debugs(54, 5, "ipc(" << prog
<< "," << pid
<< "): received from child : " << rfc1738_escape_unescaped(buf2
));
841 x
= send(send_fd
, (const void *)buf2
, x
, 0);
843 if ((x
<= 0 && type
== IPC_TCP_SOCKET
) ||
844 (x
< 0 && type
== IPC_UDP_SOCKET
)) {
845 debugs(54, 3, "ipc(" << prog
<< "," << pid
<< "): " << x
<< " bytes sent to parent. Exiting...");