/*
- * DEBUG: section 54 Interprocess Communication
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
-#include "squid-old.h"
+/* DEBUG: section 54 Interprocess Communication */
+
+#include "squid.h"
#include "comm/Connection.h"
+#include "fd.h"
#include "fde.h"
+#include "globals.h"
#include "ip/Address.h"
+#include "ipc/Kid.h"
#include "rfc1738.h"
+#include "SquidConfig.h"
+#include "SquidIpc.h"
+#include "tools.h"
static const char *hello_string = "hi there\n";
+#ifndef HELLO_BUF_SZ
#define HELLO_BUF_SZ 32
+#endif
static char hello_buf[HELLO_BUF_SZ];
static int
COMM_NOCLOEXEC,
name);
prfd = pwfd = comm_open(SOCK_STREAM,
- 0, /* protocol */
+ 0, /* protocol */
local_addr,
- 0, /* blocking */
+ 0, /* blocking */
name);
IPC_CHECK_FAIL(crfd, "child read", "TCP " << local_addr);
IPC_CHECK_FAIL(prfd, "parent read", "TCP " << local_addr);
int c2p[2];
if (pipe(p2c) < 0) {
- debugs(54, 0, "ipcCreate: pipe: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: pipe: " << xstrerror());
return -1; // maybe ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
fd_open(prfd = p2c[0], FD_PIPE, "IPC FIFO Parent Read");
fd_open(cwfd = p2c[1], FD_PIPE, "IPC FIFO Child Write");
if (pipe(c2p) < 0) {
- debugs(54, 0, "ipcCreate: pipe: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: pipe: " << xstrerror());
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
fd_open(crfd = c2p[0], FD_PIPE, "IPC FIFO Child Read");
int buflen = 32768;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
- debugs(54, 0, "ipcCreate: socketpair: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: socketpair: " << xstrerror());
return -1;
}
int fds[2];
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) < 0) {
- debugs(54, 0, "ipcCreate: socketpair: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: socketpair: " << xstrerror());
return -1;
}
debugs(54, 3, "ipcCreate: cwfd FD " << cwfd);
if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) {
- PaS.InitAddrInfo(AI);
+ Ip::Address::InitAddr(AI);
if (getsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
- PaS.FreeAddrInfo(AI);
- debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
+ Ip::Address::FreeAddr(AI);
+ debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerror());
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
debugs(54, 3, "ipcCreate: FD " << pwfd << " sockaddr " << PaS);
- PaS.FreeAddrInfo(AI);
+ Ip::Address::FreeAddr(AI);
- ChS.InitAddrInfo(AI);
+ Ip::Address::InitAddr(AI);
if (getsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
- ChS.FreeAddrInfo(AI);
- debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
+ Ip::Address::FreeAddr(AI);
+ debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerror());
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
ChS = *AI;
- ChS.FreeAddrInfo(AI);
+ Ip::Address::FreeAddr(AI);
debugs(54, 3, "ipcCreate: FD " << crfd << " sockaddr " << ChS );
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
- if (pid > 0) { /* parent */
+ if (pid > 0) { /* parent */
/* close shared socket with child */
comm_close(crfd);
cwfd = crfd = -1;
if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) {
- if (comm_connect_addr(pwfd, ChS) == COMM_ERROR)
+ if (comm_connect_addr(pwfd, ChS) == Comm::COMM_ERROR)
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
- memset(hello_buf, '\0', HELLO_BUF_SZ);
-
if (type == IPC_UDP_SOCKET)
- x = comm_udp_recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0);
+ x = comm_udp_recv(prfd, hello_buf, sizeof(hello_buf)-1, 0);
else
- x = read(prfd, hello_buf, HELLO_BUF_SZ - 1);
+ x = read(prfd, hello_buf, sizeof(hello_buf)-1);
+ if (x >= 0)
+ hello_buf[x+1] = '\0';
if (x < 0) {
- debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
- debugs(54, 0, "--> read: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: PARENT: hello read test failed");
+ debugs(54, DBG_CRITICAL, "--> read: " << xstrerror());
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
} else if (strcmp(hello_buf, hello_string)) {
- debugs(54, 0, "ipcCreate: PARENT: hello read test failed");
- debugs(54, 0, "--> read returned " << x);
- debugs(54, 0, "--> got '" << rfc1738_escape(hello_buf) << "'");
+ debugs(54, DBG_CRITICAL, "ipcCreate: PARENT: hello read test failed");
+ debugs(54, DBG_CRITICAL, "--> read returned " << x);
+ debugs(54, DBG_CRITICAL, "--> got '" << rfc1738_escape(hello_buf) << "'");
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
}
/* child */
- no_suid(); /* give up extra priviliges */
+ TheProcessKind = pkHelper;
+ no_suid(); /* give up extra priviliges */
/* close shared socket with parent */
close(prfd);
debugs(54, 3, "ipcCreate: calling accept on FD " << crfd);
if ((fd = accept(crfd, NULL, NULL)) < 0) {
- debugs(54, 0, "ipcCreate: FD " << crfd << " accept: " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: FD " << crfd << " accept: " << xstrerror());
_exit(1);
}
close(crfd);
cwfd = crfd = fd;
} else if (type == IPC_UDP_SOCKET) {
- if (comm_connect_addr(crfd, PaS) == COMM_ERROR)
+ if (comm_connect_addr(crfd, PaS) == Comm::COMM_ERROR)
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
x = comm_udp_send(cwfd, hello_string, strlen(hello_string) + 1, 0);
if (x < 0) {
- debugs(54, 0, "sendto FD " << cwfd << ": " << xstrerror());
- debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
+ debugs(54, DBG_CRITICAL, "sendto FD " << cwfd << ": " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: hello write test failed");
_exit(1);
}
} else {
if (write(cwfd, hello_string, strlen(hello_string) + 1) < 0) {
- debugs(54, 0, "write FD " << cwfd << ": " << xstrerror());
- debugs(54, 0, "ipcCreate: CHILD: hello write test failed");
+ debugs(54, DBG_CRITICAL, "write FD " << cwfd << ": " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: CHILD: hello write test failed");
_exit(1);
}
}
debug_log = fdopen(2, "a+");
- debugs(54, 0, "ipcCreate: " << prog << ": " << xstrerror());
+ debugs(54, DBG_CRITICAL, "ipcCreate: " << prog << ": " << xstrerror());
_exit(1);
return 0;
}
+