22
21
* it under the terms of the GNU General Public License as published by
23
22
* the Free Software Foundation; either version 2 of the License, or
24
23
* (at your option) any later version.
26
25
* This program is distributed in the hope that it will be useful,
27
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
28
* GNU General Public License for more details.
31
30
* You should have received a copy of the GNU General Public License
32
31
* along with this program; if not, write to the Free Software
33
32
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
104
env_str = (char *)xcalloc((tmp_s = strlen(Config.debugOptions) + 32), 1);
105
snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Config.debugOptions);
101
env_str = (char *)xcalloc((tmp_s = strlen(Debug::debugOptions) + 32), 1);
102
snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Debug::debugOptions);
111
ipcCreate(int type, const char *prog, const char *const args[], const char *name, int *rfd, int *wfd, void **hIpc)
108
ipcCreate(int type, const char *prog, const char *const args[], const char *name, IpAddress &local_addr, int *rfd, int *wfd, void **hIpc)
113
110
unsigned long thread;
149
146
crfd = cwfd = comm_open(SOCK_STREAM,
155
151
prfd = pwfd = comm_open(SOCK_STREAM,
156
152
IPPROTO_TCP, /* protocol */
159
154
0, /* blocking */
161
156
} else if (type == IPC_UDP_SOCKET) {
162
157
crfd = cwfd = comm_open(SOCK_DGRAM,
168
162
prfd = pwfd = comm_open(SOCK_DGRAM,
174
167
} else if (type == IPC_FIFO) {
175
168
debugs(54, 0, "ipcCreate: " << prog << ": use IPC_TCP_SOCKET instead of IP_FIFO on Windows");
199
192
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
195
// AYJ: these flags should be neutral, but if not IPv6 version needs adding
202
196
if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) {
204
memset(&PS, '\0', len);
206
if (getsockname(pwfd, (struct sockaddr *) &PS, &len) < 0) {
207
debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
208
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
211
debugs(54, 3, "ipcCreate: FD " << pwfd << " sockaddr " << inet_ntoa(PS.sin_addr) << ":" << ntohs(PS.sin_port));
213
memset(&CS, '\0', len);
215
if (getsockname(crfd, (struct sockaddr *) &CS, &len) < 0) {
216
debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
217
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
220
debugs(54, 3, "ipcCreate: FD " << crfd << " sockaddr " << inet_ntoa(CS.sin_addr) << ":" << ntohs(CS.sin_port));
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 );
223
222
if (type == IPC_TCP_SOCKET) {
251
252
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
254
if (comm_connect_addr(pwfd, &CS) == COMM_ERROR) {
255
/* NP: tmp_addr was left with eiether empty or aiCS in IpAddress format */
256
if (comm_connect_addr(pwfd, tmp_addr) == COMM_ERROR) {
255
257
CloseHandle((HANDLE) thread);
256
258
return ipcCloseAllFD(prfd, pwfd, -1, -1);
377
377
int prfd_ipc = -1, pwfd_ipc = -1, crfd_ipc = -1, cwfd_ipc = -1;
378
378
char *prog = NULL, *buf1 = NULL;
380
struct sockaddr_in CS_ipc, PS_ipc;
382
struct addrinfo *aiPS_ipc = NULL;
383
struct addrinfo *aiCS_ipc = NULL;
382
385
struct ipc_params *params = (struct ipc_params *) in_params;
383
386
int type = params->type;
385
388
int cwfd = params->cwfd;
386
389
char **args = params->args;
388
struct sockaddr_in PS = params->PS;
391
IpAddress PS = params->PS;
392
IpAddress local_addr = params->local_addr;
391
394
buf1 = (char *)xcalloc(1, 8192);
392
395
strcpy(buf1, params->prog);
411
414
debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd);
412
415
comm_close(crfd);
413
416
snprintf(buf1, 8191, "%s CHILD socket", prog);
414
fdc_open(fd, FD_SOCKET, buf1);
417
fd_open(fd, FD_SOCKET, buf1);
415
418
fd_table[fd].flags.ipc = 1;
416
419
cwfd = crfd = fd;
417
420
} else if (type == IPC_UDP_SOCKET) {
418
if (comm_connect_addr(crfd, &PS) == COMM_ERROR)
421
if (comm_connect_addr(crfd, params->PS) == COMM_ERROR)
458
461
if (type == IPC_UDP_SOCKET) {
459
462
snprintf(buf1, 8192, "%s(%ld) <-> ipc CHILD socket", prog, -1L);
460
crfd_ipc = cwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, 0, buf1);
463
crfd_ipc = cwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
462
465
if (crfd_ipc < 0) {
463
466
debugs(54, 0, "ipcCreate: CHILD: Failed to create child FD for " << prog << ".");
468
471
snprintf(buf1, 8192, "%s(%ld) <-> ipc PARENT socket", prog, -1L);
469
prfd_ipc = pwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, 0, buf1);
472
prfd_ipc = pwfd_ipc = comm_open(SOCK_DGRAM, IPPROTO_UDP, local_addr, 0, buf1);
471
474
if (pwfd_ipc < 0) {
472
475
debugs(54, 0, "ipcCreate: CHILD: Failed to create server FD for " << prog << ".");
477
tmp_s = sizeof(PS_ipc);
478
memset(&PS_ipc, '\0', tmp_s);
480
if (getsockname(pwfd_ipc, (struct sockaddr *) &PS_ipc, &tmp_s) < 0) {
481
debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
482
ipcSend(cwfd, err_string, strlen(err_string));
486
debugs(54, 3, "ipcCreate: FD " << pwfd_ipc << " sockaddr " << inet_ntoa(PS_ipc.sin_addr) << ":" << ntohs(PS_ipc.sin_port));
488
tmp_s = sizeof(CS_ipc);
489
memset(&CS_ipc, '\0', tmp_s);
491
if (getsockname(crfd_ipc, (struct sockaddr *) &CS_ipc, &tmp_s) < 0) {
492
debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
493
ipcSend(cwfd, err_string, strlen(err_string));
497
debugs(54, 3, "ipcCreate: FD " << crfd_ipc << " sockaddr " << inet_ntoa(CS_ipc.sin_addr) << ":" << ntohs(CS_ipc.sin_port));
499
if (comm_connect_addr(pwfd_ipc, &CS_ipc) == COMM_ERROR) {
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) {
500
505
ipcSend(cwfd, err_string, strlen(err_string));
506
if (comm_connect_addr(crfd_ipc, &PS_ipc) == COMM_ERROR) {
511
if (comm_connect_addr(crfd_ipc, PS_ipc) == COMM_ERROR) {
507
512
ipcSend(cwfd, err_string, strlen(err_string));
699
704
if (-1 == ipcSend(cwfd, buf1, strlen(buf1)))
702
debugs(54, 2, "ipc(" << prog << "," << pid << "): started successfully");
707
debugs(54, 2, "ipc(" << prog << "," << pid << "): started successfully");