28#define HELLO_BUF_SZ 32
65ipcCreate(
int type,
const char *prog,
const char *
const args[],
const char *name,
Ip::Address &local_addr,
int *rfd,
int *wfd,
void **
hIpc)
70 struct addrinfo *AI =
nullptr;
80#if USE_POLL && _SQUID_OSF_
94#define IPC_CHECK_FAIL(f,d,c) \
96 debugs(54, DBG_CRITICAL, "ERROR: Failed to create helper " d " FD: " << c); \
97 return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); \
149#if HAVE_SOCKETPAIR && defined(AF_UNIX)
155 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
162 if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, (
void *) &buflen,
sizeof(buflen)) == -1) {
167 if (setsockopt(fds[0], SOL_SOCKET, SO_RCVBUF, (
void *) &buflen,
sizeof(buflen)) == -1) {
172 if (setsockopt(fds[1], SOL_SOCKET, SO_SNDBUF, (
void *) &buflen,
sizeof(buflen)) == -1) {
177 if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, (
void *) &buflen,
sizeof(buflen)) == -1) {
190 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) < 0) {
207 debugs(54, 3,
"ipcCreate: prfd FD " << prfd);
208 debugs(54, 3,
"ipcCreate: pwfd FD " << pwfd);
209 debugs(54, 3,
"ipcCreate: crfd FD " << crfd);
210 debugs(54, 3,
"ipcCreate: cwfd FD " << cwfd);
215 if (getsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
224 debugs(54, 3,
"ipcCreate: FD " << pwfd <<
" sockaddr " << PaS);
230 if (getsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
241 debugs(54, 3,
"ipcCreate: FD " << crfd <<
" sockaddr " << ChS );
246 if (listen(crfd, 1) < 0) {
252 debugs(54, 3,
"ipcCreate: FD " << crfd <<
" listening...");
258 if ((
pid = fork()) < 0) {
330 debugs(54, 3,
"ipcCreate: calling accept on FD " << crfd);
332 if ((fd = accept(crfd,
nullptr,
nullptr)) < 0) {
338 debugs(54, 3,
"ipcCreate: CHILD accepted new FD " << fd);
374 }
while (x < 3 && x > -1);
384 assert(t1 > 2 && t2 > 2 && t3 > 2);
405 for (x = 3; x < SQUID_MAXFD; ++x)
413 execvp(prog, (
char *
const *) args);
int TheProcessKind
ProcessKind for the current process.
@ pkHelper
general-purpose helper child
static char * debugOptions
static void InitAddr(struct addrinfo *&ai)
static void FreeAddr(struct addrinfo *&ai)
void fd_open(const int fd, unsigned int, const char *description)
int commSetNonBlocking(int fd)
void commUnsetFdTimeout(int fd)
clear a timeout handler by FD number
void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note)
int comm_udp_recv(int fd, void *buf, size_t len, int flags)
int comm_open(int sock_type, int proto, Ip::Address &addr, int flags, const char *note)
int comm_connect_addr(int sock, const Ip::Address &address)
ssize_t comm_udp_send(int s, const void *buf, size_t len, int flags)
#define debugs(SECTION, LEVEL, CONTENT)
#define debug_log
change-avoidance macro; new code should call DebugStream() instead
static void PutEnvironment()
#define IPC_CHECK_FAIL(f, d, c)
static const char * hello_string
static char hello_buf[HELLO_BUF_SZ]
static int ipcCloseAllFD(int prfd, int pwfd, int crfd, int cwfd)
pid_t ipcCreate(int type, const char *prog, const char *const args[], const char *name, Ip::Address &local_addr, int *rfd, int *wfd, void **hIpc)
#define rfc1738_escape(x)
void ResyncDebugLog(FILE *newFile)
a hack for low-level file descriptor manipulations in ipcCreate()
void * xcalloc(size_t n, size_t sz)
const char * xstrerr(int error)