7 * Copyright (c) 1995 Open Market, Inc.
10 * This file contains proprietary and confidential information and
11 * remains the unpublished property of Open Market, Inc. Use,
12 * disclosure, or reproduction is prohibited except as permitted by
13 * express written license agreement with Open Market, Inc.
16 * snapper@openmarket.com
20 static const char rcsid[] = "$Id: os_unix.c,v 1.28 2001/06/22 14:26:39 robs Exp $";
23 #include "fcgi_config.h"
25 #include <sys/types.h>
27 #ifdef HAVE_NETINET_IN_H
28 #include <netinet/in.h>
31 #include <arpa/inet.h>
34 #include <fcntl.h> /* for fcntl */
36 #include <memory.h> /* for memchr() */
37 #include <netinet/tcp.h>
49 #ifdef HAVE_SYS_SOCKET_H
50 #include <sys/socket.h> /* for getpeername */
62 #define INADDR_NONE ((unsigned long) -1)
66 * This structure holds an entry for each oustanding async I/O operation.
69 OS_AsyncProc procPtr; /* callout completion procedure */
70 ClientData clientData; /* caller private data */
79 * Entries in the async I/O table are allocated 2 per file descriptor.
81 * Read Entry Index = fd * 2
82 * Write Entry Index = (fd * 2) + 1
84 #define AIO_RD_IX(fd) (fd * 2)
85 #define AIO_WR_IX(fd) ((fd * 2) + 1)
87 static int asyncIoInUse = FALSE;
88 static int asyncIoTableSize = 16;
89 static AioInfo *asyncIoTable = NULL;
91 static int libInitialized = FALSE;
93 static fd_set readFdSet;
94 static fd_set writeFdSet;
96 static fd_set readFdSetPost;
97 static int numRdPosted = 0;
98 static fd_set writeFdSetPost;
99 static int numWrPosted = 0;
100 static int volatile maxFd = -1;
103 *--------------------------------------------------------------
107 * Set up the OS library for use.
109 * NOTE: This function is really only needed for application
110 * asynchronous I/O. It will most likely change in the
111 * future to setup the multi-threaded environment.
114 * Returns 0 if success, -1 if not.
117 * Async I/O table allocated and initialized.
119 *--------------------------------------------------------------
121 int OS_LibInit(int stdioFds[3])
126 asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
127 if(asyncIoTable == NULL) {
131 memset((char *) asyncIoTable, 0,
132 asyncIoTableSize * sizeof(AioInfo));
135 FD_ZERO(&writeFdSet);
136 FD_ZERO(&readFdSetPost);
137 FD_ZERO(&writeFdSetPost);
138 libInitialized = TRUE;
143 *--------------------------------------------------------------
147 * Shutdown the OS library.
153 * Memory freed, fds closed.
155 *--------------------------------------------------------------
157 void OS_LibShutdown()
164 libInitialized = FALSE;
169 *----------------------------------------------------------------------
171 * OS_BuildSockAddrUn --
173 * Using the pathname bindPath, fill in the sockaddr_un structure
174 * *servAddrPtr and the length of this structure *servAddrLen.
176 * The format of the sockaddr_un structure changed incompatibly in
177 * 4.3BSD Reno. Digital UNIX supports both formats, other systems
178 * support one or the other.
181 * 0 for normal return, -1 for failure (bindPath too long).
183 *----------------------------------------------------------------------
186 static int OS_BuildSockAddrUn(const char *bindPath,
187 struct sockaddr_un *servAddrPtr,
190 int bindPathLen = strlen(bindPath);
192 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
193 if(bindPathLen >= sizeof(servAddrPtr->sun_path)) {
196 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
197 if(bindPathLen > sizeof(servAddrPtr->sun_path)) {
201 memset((char *) servAddrPtr, 0, sizeof(*servAddrPtr));
202 servAddrPtr->sun_family = AF_UNIX;
203 memcpy(servAddrPtr->sun_path, bindPath, bindPathLen);
204 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
205 *servAddrLen = sizeof(servAddrPtr->sun_len)
206 + sizeof(servAddrPtr->sun_family)
208 servAddrPtr->sun_len = *servAddrLen;
209 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
210 *servAddrLen = sizeof(servAddrPtr->sun_family) + bindPathLen;
214 union SockAddrUnion {
215 struct sockaddr_un unixVariant;
216 struct sockaddr_in inetVariant;
220 * OS_CreateLocalIpcFd --
222 * This procedure is responsible for creating the listener socket
223 * on Unix for local process communication. It will create a
224 * domain socket or a TCP/IP socket bound to "localhost" and return
225 * a file descriptor to it to the caller.
228 * Listener socket created. This call returns either a valid
229 * file descriptor or -1 on error.
234 *----------------------------------------------------------------------
236 int OS_CreateLocalIpcFd(const char *bindPath, int backlog)
238 int listenSock, servLen;
239 union SockAddrUnion sa;
241 unsigned long tcp_ia;
244 char host[MAXPATHLEN];
246 strcpy(host, bindPath);
247 if((tp = strchr(host, ':')) != 0) {
249 if((port = atoi(tp)) == 0) {
256 if (!*host || !strcmp(host,"*")) {
257 tcp_ia = htonl(INADDR_ANY);
259 tcp_ia = inet_addr(host);
260 if (tcp_ia == INADDR_NONE) {
261 struct hostent * hep;
262 hep = gethostbyname(host);
263 if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
264 fprintf(stderr, "Cannot resolve host name %s -- exiting!\n", host);
267 if (hep->h_addr_list[1]) {
268 fprintf(stderr, "Host %s has multiple addresses ---\n", host);
269 fprintf(stderr, "you must choose one explicitly!!!\n");
272 tcp_ia = ((struct in_addr *) (hep->h_addr))->s_addr;
278 listenSock = socket(AF_INET, SOCK_STREAM, 0);
279 if(listenSock >= 0) {
281 if(setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR,
282 (char *) &flag, sizeof(flag)) < 0) {
283 fprintf(stderr, "Can't set SO_REUSEADDR.\n");
288 listenSock = socket(AF_UNIX, SOCK_STREAM, 0);
295 * Bind the listening socket.
298 memset((char *) &sa.inetVariant, 0, sizeof(sa.inetVariant));
299 sa.inetVariant.sin_family = AF_INET;
300 sa.inetVariant.sin_addr.s_addr = tcp_ia;
301 sa.inetVariant.sin_port = htons(port);
302 servLen = sizeof(sa.inetVariant);
305 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
306 fprintf(stderr, "Listening socket's path name is too long.\n");
310 if(bind(listenSock, (struct sockaddr *) &sa.unixVariant, servLen) < 0
311 || listen(listenSock, backlog) < 0) {
312 perror("bind/listen");
320 *----------------------------------------------------------------------
324 * Create the socket and connect to the remote application if
327 * This was lifted from the cgi-fcgi application and was abstracted
328 * out because Windows NT does not have a domain socket and must
329 * use a named pipe which has a different API altogether.
332 * -1 if fail or a valid file descriptor if connection succeeds.
335 * Remote connection established.
337 *----------------------------------------------------------------------
339 int OS_FcgiConnect(char *bindPath)
341 union SockAddrUnion sa;
342 int servLen, resultSock;
345 char host[MAXPATHLEN];
349 strcpy(host, bindPath);
350 if((tp = strchr(host, ':')) != 0) {
352 if((port = atoi(tp)) == 0) {
360 if((hp = gethostbyname((*host ? host : "localhost"))) == NULL) {
361 fprintf(stderr, "Unknown host: %s\n", bindPath);
364 sa.inetVariant.sin_family = AF_INET;
365 memcpy(&sa.inetVariant.sin_addr, hp->h_addr, hp->h_length);
366 sa.inetVariant.sin_port = htons(port);
367 servLen = sizeof(sa.inetVariant);
368 resultSock = socket(AF_INET, SOCK_STREAM, 0);
370 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
371 fprintf(stderr, "Listening socket's path name is too long.\n");
374 resultSock = socket(AF_UNIX, SOCK_STREAM, 0);
377 ASSERT(resultSock >= 0);
378 connectStatus = connect(resultSock, (struct sockaddr *) &sa.unixVariant,
380 if(connectStatus >= 0) {
384 * Most likely (errno == ENOENT || errno == ECONNREFUSED)
385 * and no FCGI application server is running.
393 *--------------------------------------------------------------
397 * Pass through to the unix read function.
400 * Returns number of byes read, 0, or -1 failure: errno
401 * contains actual error.
406 *--------------------------------------------------------------
408 int OS_Read(int fd, char * buf, size_t len)
410 return(read(fd, buf, len));
414 *--------------------------------------------------------------
418 * Pass through to unix write function.
421 * Returns number of byes read, 0, or -1 failure: errno
422 * contains actual error.
427 *--------------------------------------------------------------
429 int OS_Write(int fd, char * buf, size_t len)
431 return(write(fd, buf, len));
435 *----------------------------------------------------------------------
439 * Spawns a new FastCGI listener process.
442 * 0 if success, -1 if error.
445 * Child process spawned.
447 *----------------------------------------------------------------------
449 int OS_SpawnChild(char *appPath, int listenFd)
458 if(forkResult == 0) {
460 * Close STDIN unconditionally. It's used by the parent
461 * process for CGI communication. The FastCGI applciation
462 * will be replacing this with the FastCGI listenFd IF
463 * STDIN_FILENO is the same as FCGI_LISTENSOCK_FILENO
464 * (which it is on Unix). Regardless, STDIN, STDOUT, and
465 * STDERR will be closed as the FastCGI process uses a
466 * multiplexed socket in their place.
471 * If the listenFd is already the value of FCGI_LISTENSOCK_FILENO
472 * we're set. If not, change it so the child knows where to
473 * get the listen socket from.
475 if(listenFd != FCGI_LISTENSOCK_FILENO) {
476 dup2(listenFd, FCGI_LISTENSOCK_FILENO);
480 close(STDOUT_FILENO);
481 close(STDERR_FILENO);
484 * We're a child. Exec the application.
486 * XXX: entire environment passes through
488 execl(appPath, appPath, NULL);
490 * XXX: Can't do this as we've already closed STDERR!!!
500 *--------------------------------------------------------------
502 * OS_AsyncReadStdin --
504 * This initiates an asynchronous read on the standard
507 * The abstraction is necessary because Windows NT does not
508 * have a clean way of "select"ing a file descriptor for
512 * -1 if error, 0 otherwise.
515 * Asynchronous bit is set in the readfd variable and
516 * request is enqueued.
518 *--------------------------------------------------------------
520 int OS_AsyncReadStdin(void *buf, int len, OS_AsyncProc procPtr,
521 ClientData clientData)
523 int index = AIO_RD_IX(STDIN_FILENO);
526 ASSERT(asyncIoTable[index].inUse == 0);
527 asyncIoTable[index].procPtr = procPtr;
528 asyncIoTable[index].clientData = clientData;
529 asyncIoTable[index].fd = STDIN_FILENO;
530 asyncIoTable[index].len = len;
531 asyncIoTable[index].offset = 0;
532 asyncIoTable[index].buf = buf;
533 asyncIoTable[index].inUse = 1;
534 FD_SET(STDIN_FILENO, &readFdSet);
535 if(STDIN_FILENO > maxFd)
536 maxFd = STDIN_FILENO;
540 static void GrowAsyncTable(void)
542 int oldTableSize = asyncIoTableSize;
544 asyncIoTableSize = asyncIoTableSize * 2;
545 asyncIoTable = (AioInfo *)realloc(asyncIoTable, asyncIoTableSize * sizeof(AioInfo));
546 if(asyncIoTable == NULL) {
550 memset((char *) &asyncIoTable[oldTableSize], 0,
551 oldTableSize * sizeof(AioInfo));
556 *--------------------------------------------------------------
560 * This initiates an asynchronous read on the file
561 * handle which may be a socket or named pipe.
563 * We also must save the ProcPtr and ClientData, so later
564 * when the io completes, we know who to call.
566 * We don't look at any results here (the ReadFile may
567 * return data if it is cached) but do all completion
568 * processing in OS_Select when we get the io completion
569 * port done notifications. Then we call the callback.
572 * -1 if error, 0 otherwise.
575 * Asynchronous I/O operation is queued for completion.
577 *--------------------------------------------------------------
579 int OS_AsyncRead(int fd, int offset, void *buf, int len,
580 OS_AsyncProc procPtr, ClientData clientData)
582 int index = AIO_RD_IX(fd);
584 ASSERT(asyncIoTable != NULL);
590 if(index >= asyncIoTableSize) {
594 ASSERT(asyncIoTable[index].inUse == 0);
595 asyncIoTable[index].procPtr = procPtr;
596 asyncIoTable[index].clientData = clientData;
597 asyncIoTable[index].fd = fd;
598 asyncIoTable[index].len = len;
599 asyncIoTable[index].offset = offset;
600 asyncIoTable[index].buf = buf;
601 asyncIoTable[index].inUse = 1;
602 FD_SET(fd, &readFdSet);
607 *--------------------------------------------------------------
611 * This initiates an asynchronous write on the "fake" file
612 * descriptor (which may be a file, socket, or named pipe).
613 * We also must save the ProcPtr and ClientData, so later
614 * when the io completes, we know who to call.
616 * We don't look at any results here (the WriteFile generally
617 * completes immediately) but do all completion processing
618 * in OS_DoIo when we get the io completion port done
619 * notifications. Then we call the callback.
622 * -1 if error, 0 otherwise.
625 * Asynchronous I/O operation is queued for completion.
627 *--------------------------------------------------------------
629 int OS_AsyncWrite(int fd, int offset, void *buf, int len,
630 OS_AsyncProc procPtr, ClientData clientData)
632 int index = AIO_WR_IX(fd);
639 if(index >= asyncIoTableSize) {
643 ASSERT(asyncIoTable[index].inUse == 0);
644 asyncIoTable[index].procPtr = procPtr;
645 asyncIoTable[index].clientData = clientData;
646 asyncIoTable[index].fd = fd;
647 asyncIoTable[index].len = len;
648 asyncIoTable[index].offset = offset;
649 asyncIoTable[index].buf = buf;
650 asyncIoTable[index].inUse = 1;
651 FD_SET(fd, &writeFdSet);
656 *--------------------------------------------------------------
660 * Closes the descriptor. This is a pass through to the
664 * 0 for success, -1 on failure
669 *--------------------------------------------------------------
677 int index = AIO_RD_IX(fd);
679 FD_CLR(fd, &readFdSet);
680 FD_CLR(fd, &readFdSetPost);
681 if (asyncIoTable[index].inUse != 0) {
682 asyncIoTable[index].inUse = 0;
685 FD_CLR(fd, &writeFdSet);
686 FD_CLR(fd, &writeFdSetPost);
687 index = AIO_WR_IX(fd);
688 if (asyncIoTable[index].inUse != 0) {
689 asyncIoTable[index].inUse = 0;
700 *--------------------------------------------------------------
704 * Cancel outstanding asynchronous reads and prevent subsequent
705 * reads from completing.
708 * Socket or file is shutdown. Return values mimic Unix shutdown:
709 * 0 success, -1 failure
711 *--------------------------------------------------------------
713 int OS_CloseRead(int fd)
715 if(asyncIoTable[AIO_RD_IX(fd)].inUse != 0) {
716 asyncIoTable[AIO_RD_IX(fd)].inUse = 0;
717 FD_CLR(fd, &readFdSet);
720 return shutdown(fd, 0);
724 *--------------------------------------------------------------
728 * This function was formerly OS_Select. It's purpose is
729 * to pull I/O completion events off the queue and dispatch
730 * them to the appropriate place.
736 * Handlers are called.
738 *--------------------------------------------------------------
740 int OS_DoIo(struct timeval *tmo)
742 int fd, len, selectStatus;
743 OS_AsyncProc procPtr;
744 ClientData clientData;
747 fd_set writeFdSetCpy;
750 FD_ZERO(&readFdSetCpy);
751 FD_ZERO(&writeFdSetCpy);
753 for(fd = 0; fd <= maxFd; fd++) {
754 if(FD_ISSET(fd, &readFdSet)) {
755 FD_SET(fd, &readFdSetCpy);
757 if(FD_ISSET(fd, &writeFdSet)) {
758 FD_SET(fd, &writeFdSetCpy);
763 * If there were no completed events from a prior call, see if there's
766 if(numRdPosted == 0 && numWrPosted == 0) {
767 selectStatus = select((maxFd+1), &readFdSetCpy, &writeFdSetCpy,
769 if(selectStatus < 0) {
773 for(fd = 0; fd <= maxFd; fd++) {
775 * Build up a list of completed events. We'll work off of
776 * this list as opposed to looping through the read and write
777 * fd sets since they can be affected by a callbacl routine.
779 if(FD_ISSET(fd, &readFdSetCpy)) {
781 FD_SET(fd, &readFdSetPost);
782 FD_CLR(fd, &readFdSet);
785 if(FD_ISSET(fd, &writeFdSetCpy)) {
787 FD_SET(fd, &writeFdSetPost);
788 FD_CLR(fd, &writeFdSet);
793 if(numRdPosted == 0 && numWrPosted == 0)
796 for(fd = 0; fd <= maxFd; fd++) {
798 * Do reads and dispatch callback.
800 if(FD_ISSET(fd, &readFdSetPost)
801 && asyncIoTable[AIO_RD_IX(fd)].inUse) {
804 FD_CLR(fd, &readFdSetPost);
805 aioPtr = &asyncIoTable[AIO_RD_IX(fd)];
807 len = read(aioPtr->fd, aioPtr->buf, aioPtr->len);
809 procPtr = aioPtr->procPtr;
810 aioPtr->procPtr = NULL;
811 clientData = aioPtr->clientData;
814 (*procPtr)(clientData, len);
818 * Do writes and dispatch callback.
820 if(FD_ISSET(fd, &writeFdSetPost) &&
821 asyncIoTable[AIO_WR_IX(fd)].inUse) {
824 FD_CLR(fd, &writeFdSetPost);
825 aioPtr = &asyncIoTable[AIO_WR_IX(fd)];
827 len = write(aioPtr->fd, aioPtr->buf, aioPtr->len);
829 procPtr = aioPtr->procPtr;
830 aioPtr->procPtr = NULL;
831 clientData = aioPtr->clientData;
833 (*procPtr)(clientData, len);
840 * Not all systems have strdup().
841 * @@@ autoconf should determine whether or not this is needed, but for now..
843 static char * str_dup(const char * str)
845 char * sdup = (char *) malloc(strlen(str) + 1);
854 *----------------------------------------------------------------------
858 * Checks if a client address is in a list of allowed addresses
861 * TRUE if address list is empty or client address is present
862 * in the list, FALSE otherwise.
864 *----------------------------------------------------------------------
866 static int ClientAddrOK(struct sockaddr_in *saPtr, const char *clientList)
869 char *clientListCopy, *cur, *next;
871 if (clientList == NULL || *clientList == '\0') {
875 clientListCopy = str_dup(clientList);
877 for (cur = clientListCopy; cur != NULL; cur = next) {
878 next = strchr(cur, ',');
882 if (inet_addr(cur) == saPtr->sin_addr.s_addr) {
888 free(clientListCopy);
893 *----------------------------------------------------------------------
897 * On platforms that implement concurrent calls to accept
898 * on a shared listening ipcFd, returns 0. On other platforms,
899 * acquires an exclusive lock across all processes sharing a
900 * listening ipcFd, blocking until the lock has been acquired.
903 * 0 for successful call, -1 in case of system error (fatal).
906 * This process now has the exclusive lock.
908 *----------------------------------------------------------------------
910 static int AcquireLock(int sock, int fail_on_intr)
915 lock.l_type = F_WRLCK;
917 lock.l_whence = SEEK_SET;
920 if (fcntl(sock, F_SETLKW, &lock) != -1)
922 } while (errno == EINTR && !fail_on_intr);
932 *----------------------------------------------------------------------
936 * On platforms that implement concurrent calls to accept
937 * on a shared listening ipcFd, does nothing. On other platforms,
938 * releases an exclusive lock acquired by AcquireLock.
941 * 0 for successful call, -1 in case of system error (fatal).
944 * This process no longer holds the lock.
946 *----------------------------------------------------------------------
948 static int ReleaseLock(int sock)
953 lock.l_type = F_UNLCK;
955 lock.l_whence = SEEK_SET;
958 if (fcntl(sock, F_SETLK, &lock) != -1)
960 } while (errno == EINTR);
969 /**********************************************************************
970 * Determine if the errno resulting from a failed accept() warrants a
971 * retry or exit(). Based on Apache's http_main.c accept() handling
972 * and Stevens' Unix Network Programming Vol 1, 2nd Ed, para. 15.6.
974 static int is_reasonable_accept_errno (const int error)
978 /* EPROTO on certain older kernels really means ECONNABORTED, so
979 * we need to ignore it for them. See discussion in new-httpd
980 * archives nh.9701 search for EPROTO. Also see nh.9603, search
981 * for EPROTO: There is potentially a bug in Solaris 2.x x<6, and
982 * other boxes that implement tcp sockets in userland (i.e. on top of
983 * STREAMS). On these systems, EPROTO can actually result in a fatal
984 * loop. See PR#981 for example. It's hard to handle both uses of
991 /* Linux generates the rest of these, other tcp stacks (i.e.
992 * bsd) tend to hide them behind getsockopt() interfaces. They
993 * occur when the net goes sour or the client disconnects after the
994 * three-way handshake has been done in the kernel but before
995 * userland has picked up the socket. */
1015 /**********************************************************************
1016 * This works around a problem on Linux 2.0.x and SCO Unixware (maybe
1017 * others?). When a connect() is made to a Unix Domain socket, but its
1018 * not accept()ed before the web server gets impatient and close()s, an
1019 * accept() results in a valid file descriptor, but no data to read.
1020 * This causes a block on the first read() - which never returns!
1022 * Another approach to this is to write() to the socket to provoke a
1023 * SIGPIPE, but this is a pain because of the FastCGI protocol, the fact
1024 * that whatever is written has to be universally ignored by all FastCGI
1025 * web servers, and a SIGPIPE handler has to be installed which returns
1026 * (or SIGPIPE is ignored).
1028 * READABLE_UNIX_FD_DROP_DEAD_TIMEVAL = 2,0 by default.
1030 * Making it shorter is probably safe, but I'll leave that to you. Making
1031 * it 0,0 doesn't work reliably. The shorter you can reliably make it,
1032 * the faster your application will be able to recover (waiting 2 seconds
1033 * may _cause_ the problem when there is a very high demand). At any rate,
1034 * this is better than perma-blocking.
1036 static int is_af_unix_keeper(const int fd)
1038 struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
1042 FD_SET(fd, &read_fds);
1044 return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
1048 *----------------------------------------------------------------------
1052 * Accepts a new FastCGI connection. This routine knows whether
1053 * we're dealing with TCP based sockets or NT Named Pipes for IPC.
1056 * -1 if the operation fails, otherwise this is a valid IPC fd.
1059 * New IPC connection is accepted.
1061 *----------------------------------------------------------------------
1063 int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
1067 struct sockaddr_un un;
1068 struct sockaddr_in in;
1072 if (AcquireLock(listen_sock, fail_on_intr))
1078 socklen_t len = sizeof(sa);
1080 int len = sizeof(sa);
1082 socket = accept(listen_sock, (struct sockaddr *)&sa, &len);
1083 } while (socket < 0 && errno == EINTR && !fail_on_intr);
1086 if (!is_reasonable_accept_errno(errno)) {
1087 int errnoSave = errno;
1088 ReleaseLock(listen_sock);
1094 else { /* socket >= 0 */
1097 if (sa.in.sin_family != AF_INET)
1101 /* No replies to outgoing data, so disable Nagle */
1102 setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set));
1105 /* Check that the client IP address is approved */
1106 if (ClientAddrOK(&sa.in, webServerAddrs))
1113 if (ReleaseLock(listen_sock))
1116 if (sa.in.sin_family != AF_UNIX || is_af_unix_keeper(socket))
1120 } /* while(1) - lock */
1126 *----------------------------------------------------------------------
1130 * OS IPC routine to close an IPC connection.
1136 * IPC connection is closed.
1138 *----------------------------------------------------------------------
1140 int OS_IpcClose(int ipcFd)
1142 return OS_Close(ipcFd);
1146 *----------------------------------------------------------------------
1150 * Determines whether this process is a FastCGI process or not.
1153 * Returns 1 if FastCGI, 0 if not.
1158 *----------------------------------------------------------------------
1160 int OS_IsFcgi(int sock)
1163 struct sockaddr_in in;
1164 struct sockaddr_un un;
1167 socklen_t len = sizeof(sa);
1169 int len = sizeof(sa);
1174 if (getpeername(sock, (struct sockaddr *)&sa, &len) != 0 && errno == ENOTCONN) {
1183 *----------------------------------------------------------------------
1187 * Sets selected flag bits in an open file descriptor.
1189 *----------------------------------------------------------------------
1191 void OS_SetFlags(int fd, int flags)
1194 if((val = fcntl(fd, F_GETFL, 0)) < 0) {
1198 if(fcntl(fd, F_SETFL, val) < 0) {