32#define HELLO_BUF_SZ 32
63ipcCreate(
int type,
const char *prog,
const char *
const args[],
const char *name,
Ip::Address &local_addr,
int *rfd,
int *wfd,
void **
hIpc)
68 struct addrinfo *AI =
nullptr;
78#if USE_POLL && _SQUID_OSF_
92#define IPC_CHECK_FAIL(f,d,c) \
94 debugs(54, DBG_CRITICAL, "ERROR: Failed to create helper " d " FD: " << c); \
95 return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); \
147#if HAVE_SOCKETPAIR && defined(AF_UNIX)
153 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
160 if (
xsetsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &buflen,
sizeof(buflen)) == -1) {
165 if (
xsetsockopt(fds[0], SOL_SOCKET, SO_RCVBUF, &buflen,
sizeof(buflen)) == -1) {
170 if (
xsetsockopt(fds[1], SOL_SOCKET, SO_SNDBUF, &buflen,
sizeof(buflen)) == -1) {
175 if (
xsetsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &buflen,
sizeof(buflen)) == -1) {
188 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) < 0) {
205 debugs(54, 3,
"ipcCreate: prfd FD " << prfd);
206 debugs(54, 3,
"ipcCreate: pwfd FD " << pwfd);
207 debugs(54, 3,
"ipcCreate: crfd FD " << crfd);
208 debugs(54, 3,
"ipcCreate: cwfd FD " << cwfd);
213 if (
xgetsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
222 debugs(54, 3,
"ipcCreate: FD " << pwfd <<
" sockaddr " << PaS);
228 if (
xgetsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
239 debugs(54, 3,
"ipcCreate: FD " << crfd <<
" sockaddr " << ChS );
250 debugs(54, 3,
"ipcCreate: FD " << crfd <<
" listening...");
256 if ((
pid = fork()) < 0) {
328 debugs(54, 3,
"ipcCreate: calling accept on FD " << crfd);
330 if ((fd =
xaccept(crfd,
nullptr,
nullptr)) < 0) {
336 debugs(54, 3,
"ipcCreate: CHILD accepted new FD " << fd);
366 const auto dupOrExit = [prog,name](
const int oldFd) {
367 const auto newFd = dup(oldFd);
369 const auto savedErrno = errno;
373 Debug::Extra <<
"dup(2) system call error for FD " << oldFd <<
": " <<
xstrerr(savedErrno));
391 t1 = dupOrExit(crfd);
393 t2 = dupOrExit(cwfd);
397 assert(t1 > 2 && t2 > 2 && t3 > 2);
426 execvp(prog, (
char *
const *) args);
int TheProcessKind
ProcessKind for the current process.
@ pkHelper
general-purpose helper child
static std::ostream & Extra(std::ostream &)
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)
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)
int xgetsockname(int socketFd, struct sockaddr *sa, socklen_t *saLength)
POSIX getsockname(2) equivalent.
int xaccept(int socketFd, struct sockaddr *sa, socklen_t *saLength)
POSIX accept(2) equivalent.
int xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
POSIX setsockopt(2) equivalent.
int xlisten(int socketFd, int backlog)
POSIX listen(2) equivalent.
void ResyncDebugLog(FILE *newFile)
a hack for low-level file descriptor manipulations in ipcCreate()
int xread(int fd, void *buf, size_t bufSize)
POSIX read(2) equivalent.
int xwrite(int fd, const void *buf, size_t bufSize)
POSIX write(2) equivalent.
int xclose(int fd)
POSIX close(2) equivalent.
const char * xstrerr(int error)