]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ipc.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ipc.cc
index aa2c431d6d885542eb4dc57eadfedc2f5b852fd6..94e611ec8606d2c6a454bd6de872b78f17ad24fe 100644 (file)
  *
  */
 
-#include "squid-old.h"
+#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";
 #define HELLO_BUF_SZ 32
@@ -138,14 +144,14 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
         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");
@@ -161,7 +167,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
         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;
         }
 
@@ -178,7 +184,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
         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;
         }
 
@@ -199,11 +205,11 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
     debugs(54, 3, "ipcCreate: cwfd FD " << cwfd);
 
     if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) {
-        PaS.InitAddrInfo(AI);
+        Ip::Address::InitAddrInfo(AI);
 
         if (getsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
-            PaS.FreeAddrInfo(AI);
-            debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
+            Ip::Address::FreeAddrInfo(AI);
+            debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerror());
             return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
         }
 
@@ -211,19 +217,19 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
 
         debugs(54, 3, "ipcCreate: FD " << pwfd << " sockaddr " << PaS);
 
-        PaS.FreeAddrInfo(AI);
+        Ip::Address::FreeAddrInfo(AI);
 
-        ChS.InitAddrInfo(AI);
+        Ip::Address::InitAddrInfo(AI);
 
         if (getsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
-            ChS.FreeAddrInfo(AI);
-            debugs(54, 0, "ipcCreate: getsockname: " << xstrerror());
+            Ip::Address::FreeAddrInfo(AI);
+            debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerror());
             return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
         }
 
         ChS = *AI;
 
-        ChS.FreeAddrInfo(AI);
+        Ip::Address::FreeAddrInfo(AI);
 
         debugs(54, 3, "ipcCreate: FD " << crfd << " sockaddr " << ChS );
 
@@ -231,7 +237,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
 
     if (type == IPC_TCP_SOCKET) {
         if (listen(crfd, 1) < 0) {
-            debugs(54, 1, "ipcCreate: listen FD " << crfd << ": " << xstrerror());
+            debugs(54, DBG_IMPORTANT, "ipcCreate: listen FD " << crfd << ": " << xstrerror());
             return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
         }
 
@@ -242,7 +248,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
     logsFlush();
 
     if ((pid = fork()) < 0) {
-        debugs(54, 1, "ipcCreate: fork: " << xstrerror());
+        debugs(54, DBG_IMPORTANT, "ipcCreate: fork: " << xstrerror());
         return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
     }
 
@@ -268,13 +274,13 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
             x = read(prfd, hello_buf, HELLO_BUF_SZ - 1);
 
         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);
         }
 
@@ -305,6 +311,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
     }
 
     /* child */
+    TheProcessKind = pkHelper;
     no_suid();                 /* give up extra priviliges */
 
     /* close shared socket with parent */
@@ -319,7 +326,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
         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);
         }
 
@@ -335,14 +342,14 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
         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);
         }
     }
@@ -388,7 +395,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
     close(t3);
 
     /* Make sure all other filedescriptors are closed */
-    for (x = 3; x < SQUID_MAXFD; x++)
+    for (x = 3; x < SQUID_MAXFD; ++x)
         close(x);
 
 #if HAVE_SETSID
@@ -400,7 +407,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
 
     debug_log = fdopen(2, "a+");
 
-    debugs(54, 0, "ipcCreate: " << prog << ": " << xstrerror());
+    debugs(54, DBG_CRITICAL, "ipcCreate: " << prog << ": " << xstrerror());
 
     _exit(1);