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.22 2001/03/27 13:18:08 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 */
59 #include "fcgiappmisc.h"
72 * This structure holds an entry for each oustanding async I/O operation.
75 OS_AsyncProc procPtr; /* callout completion procedure */
76 ClientData clientData; /* caller private data */
85 * Entries in the async I/O table are allocated 2 per file descriptor.
87 * Read Entry Index = fd * 2
88 * Write Entry Index = (fd * 2) + 1
90 #define AIO_RD_IX(fd) (fd * 2)
91 #define AIO_WR_IX(fd) ((fd * 2) + 1)
93 static int asyncIoInUse = FALSE;
94 static int asyncIoTableSize = 16;
95 static AioInfo *asyncIoTable = NULL;
97 static int libInitialized = FALSE;
99 static fd_set readFdSet;
100 static fd_set writeFdSet;
102 static fd_set readFdSetPost;
103 static int numRdPosted = 0;
104 static fd_set writeFdSetPost;
105 static int numWrPosted = 0;
106 static int volatile maxFd = -1;
110 *--------------------------------------------------------------
114 * Set up the OS library for use.
116 * NOTE: This function is really only needed for application
117 * asynchronous I/O. It will most likely change in the
118 * future to setup the multi-threaded environment.
121 * Returns 0 if success, -1 if not.
124 * Async I/O table allocated and initialized.
126 *--------------------------------------------------------------
128 int OS_LibInit(int stdioFds[3])
133 asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
134 if(asyncIoTable == NULL) {
138 memset((char *) asyncIoTable, 0,
139 asyncIoTableSize * sizeof(AioInfo));
142 FD_ZERO(&writeFdSet);
143 FD_ZERO(&readFdSetPost);
144 FD_ZERO(&writeFdSetPost);
145 libInitialized = TRUE;
151 *--------------------------------------------------------------
155 * Shutdown the OS library.
161 * Memory freed, fds closed.
163 *--------------------------------------------------------------
165 void OS_LibShutdown()
172 libInitialized = FALSE;
178 *----------------------------------------------------------------------
180 * OS_BuildSockAddrUn --
182 * Using the pathname bindPath, fill in the sockaddr_un structure
183 * *servAddrPtr and the length of this structure *servAddrLen.
185 * The format of the sockaddr_un structure changed incompatibly in
186 * 4.3BSD Reno. Digital UNIX supports both formats, other systems
187 * support one or the other.
190 * 0 for normal return, -1 for failure (bindPath too long).
192 *----------------------------------------------------------------------
195 static int OS_BuildSockAddrUn(const char *bindPath,
196 struct sockaddr_un *servAddrPtr,
199 int bindPathLen = strlen(bindPath);
201 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
202 if(bindPathLen >= sizeof(servAddrPtr->sun_path)) {
205 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
206 if(bindPathLen > sizeof(servAddrPtr->sun_path)) {
210 memset((char *) servAddrPtr, 0, sizeof(*servAddrPtr));
211 servAddrPtr->sun_family = AF_UNIX;
212 memcpy(servAddrPtr->sun_path, bindPath, bindPathLen);
213 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
214 *servAddrLen = sizeof(servAddrPtr->sun_len)
215 + sizeof(servAddrPtr->sun_family)
217 servAddrPtr->sun_len = *servAddrLen;
218 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
219 *servAddrLen = sizeof(servAddrPtr->sun_family) + bindPathLen;
224 union SockAddrUnion {
225 struct sockaddr_un unixVariant;
226 struct sockaddr_in inetVariant;
231 * OS_CreateLocalIpcFd --
233 * This procedure is responsible for creating the listener socket
234 * on Unix for local process communication. It will create a
235 * domain socket or a TCP/IP socket bound to "localhost" and return
236 * a file descriptor to it to the caller.
239 * Listener socket created. This call returns either a valid
240 * file descriptor or -1 on error.
245 *----------------------------------------------------------------------
247 int OS_CreateLocalIpcFd(const char *bindPath, int backlog)
249 int listenSock, servLen;
250 union SockAddrUnion sa;
254 char host[MAXPATHLEN];
256 strcpy(host, bindPath);
257 if((tp = strchr(host, ':')) != 0) {
259 if((port = atoi(tp)) == 0) {
265 if(tcp && (*host && strcmp(host, "localhost") != 0)) {
266 fprintf(stderr, "To start a service on a TCP port can not "
267 "specify a host name.\n"
268 "You should either use \"localhost:<port>\" or "
269 " just use \":<port>.\"\n");
274 listenSock = socket(AF_INET, SOCK_STREAM, 0);
275 if(listenSock >= 0) {
277 if(setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR,
278 (char *) &flag, sizeof(flag)) < 0) {
279 fprintf(stderr, "Can't set SO_REUSEADDR.\n");
284 listenSock = socket(AF_UNIX, SOCK_STREAM, 0);
291 * Bind the listening socket.
294 memset((char *) &sa.inetVariant, 0, sizeof(sa.inetVariant));
295 sa.inetVariant.sin_family = AF_INET;
296 sa.inetVariant.sin_addr.s_addr = htonl(INADDR_ANY);
297 sa.inetVariant.sin_port = htons(port);
298 servLen = sizeof(sa.inetVariant);
301 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
302 fprintf(stderr, "Listening socket's path name is too long.\n");
306 if(bind(listenSock, (struct sockaddr *) &sa.unixVariant, servLen) < 0
307 || listen(listenSock, backlog) < 0) {
308 perror("bind/listen");
317 *----------------------------------------------------------------------
321 * Create the socket and connect to the remote application if
324 * This was lifted from the cgi-fcgi application and was abstracted
325 * out because Windows NT does not have a domain socket and must
326 * use a named pipe which has a different API altogether.
329 * -1 if fail or a valid file descriptor if connection succeeds.
332 * Remote connection established.
334 *----------------------------------------------------------------------
336 int OS_FcgiConnect(char *bindPath)
338 union SockAddrUnion sa;
339 int servLen, resultSock;
342 char host[MAXPATHLEN];
346 strcpy(host, bindPath);
347 if((tp = strchr(host, ':')) != 0) {
349 if((port = atoi(tp)) == 0) {
357 if((hp = gethostbyname((*host ? host : "localhost"))) == NULL) {
358 fprintf(stderr, "Unknown host: %s\n", bindPath);
361 sa.inetVariant.sin_family = AF_INET;
362 memcpy(&sa.inetVariant.sin_addr, hp->h_addr, hp->h_length);
363 sa.inetVariant.sin_port = htons(port);
364 servLen = sizeof(sa.inetVariant);
365 resultSock = socket(AF_INET, SOCK_STREAM, 0);
367 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
368 fprintf(stderr, "Listening socket's path name is too long.\n");
371 resultSock = socket(AF_UNIX, SOCK_STREAM, 0);
374 ASSERT(resultSock >= 0);
375 connectStatus = connect(resultSock, (struct sockaddr *) &sa.unixVariant,
377 if(connectStatus >= 0) {
381 * Most likely (errno == ENOENT || errno == ECONNREFUSED)
382 * and no FCGI application server is running.
391 *--------------------------------------------------------------
395 * Pass through to the unix read function.
398 * Returns number of byes read, 0, or -1 failure: errno
399 * contains actual error.
404 *--------------------------------------------------------------
406 int OS_Read(int fd, char * buf, size_t len)
408 return(read(fd, buf, len));
412 *--------------------------------------------------------------
416 * Pass through to unix write function.
419 * Returns number of byes read, 0, or -1 failure: errno
420 * contains actual error.
425 *--------------------------------------------------------------
427 int OS_Write(int fd, char * buf, size_t len)
429 return(write(fd, buf, len));
434 *----------------------------------------------------------------------
438 * Spawns a new FastCGI listener process.
441 * 0 if success, -1 if error.
444 * Child process spawned.
446 *----------------------------------------------------------------------
448 int OS_SpawnChild(char *appPath, int listenFd)
457 if(forkResult == 0) {
459 * Close STDIN unconditionally. It's used by the parent
460 * process for CGI communication. The FastCGI applciation
461 * will be replacing this with the FastCGI listenFd IF
462 * STDIN_FILENO is the same as FCGI_LISTENSOCK_FILENO
463 * (which it is on Unix). Regardless, STDIN, STDOUT, and
464 * STDERR will be closed as the FastCGI process uses a
465 * multiplexed socket in their place.
470 * If the listenFd is already the value of FCGI_LISTENSOCK_FILENO
471 * we're set. If not, change it so the child knows where to
472 * get the listen socket from.
474 if(listenFd != FCGI_LISTENSOCK_FILENO) {
475 dup2(listenFd, FCGI_LISTENSOCK_FILENO);
479 close(STDOUT_FILENO);
480 close(STDERR_FILENO);
483 * We're a child. Exec the application.
485 * XXX: entire environment passes through
487 execl(appPath, appPath, NULL);
489 * 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));
557 *--------------------------------------------------------------
561 * This initiates an asynchronous read on the file
562 * handle which may be a socket or named pipe.
564 * We also must save the ProcPtr and ClientData, so later
565 * when the io completes, we know who to call.
567 * We don't look at any results here (the ReadFile may
568 * return data if it is cached) but do all completion
569 * processing in OS_Select when we get the io completion
570 * port done notifications. Then we call the callback.
573 * -1 if error, 0 otherwise.
576 * Asynchronous I/O operation is queued for completion.
578 *--------------------------------------------------------------
580 int OS_AsyncRead(int fd, int offset, void *buf, int len,
581 OS_AsyncProc procPtr, ClientData clientData)
583 int index = AIO_RD_IX(fd);
585 ASSERT(asyncIoTable != NULL);
591 if(index >= asyncIoTableSize) {
595 ASSERT(asyncIoTable[index].inUse == 0);
596 asyncIoTable[index].procPtr = procPtr;
597 asyncIoTable[index].clientData = clientData;
598 asyncIoTable[index].fd = fd;
599 asyncIoTable[index].len = len;
600 asyncIoTable[index].offset = offset;
601 asyncIoTable[index].buf = buf;
602 asyncIoTable[index].inUse = 1;
603 FD_SET(fd, &readFdSet);
608 *--------------------------------------------------------------
612 * This initiates an asynchronous write on the "fake" file
613 * descriptor (which may be a file, socket, or named pipe).
614 * We also must save the ProcPtr and ClientData, so later
615 * when the io completes, we know who to call.
617 * We don't look at any results here (the WriteFile generally
618 * completes immediately) but do all completion processing
619 * in OS_DoIo when we get the io completion port done
620 * notifications. Then we call the callback.
623 * -1 if error, 0 otherwise.
626 * Asynchronous I/O operation is queued for completion.
628 *--------------------------------------------------------------
630 int OS_AsyncWrite(int fd, int offset, void *buf, int len,
631 OS_AsyncProc procPtr, ClientData clientData)
633 int index = AIO_WR_IX(fd);
640 if(index >= asyncIoTableSize) {
644 ASSERT(asyncIoTable[index].inUse == 0);
645 asyncIoTable[index].procPtr = procPtr;
646 asyncIoTable[index].clientData = clientData;
647 asyncIoTable[index].fd = fd;
648 asyncIoTable[index].len = len;
649 asyncIoTable[index].offset = offset;
650 asyncIoTable[index].buf = buf;
651 asyncIoTable[index].inUse = 1;
652 FD_SET(fd, &writeFdSet);
657 *--------------------------------------------------------------
661 * Closes the descriptor. This is a pass through to the
665 * 0 for success, -1 on failure
670 *--------------------------------------------------------------
678 int index = AIO_RD_IX(fd);
680 FD_CLR(fd, &readFdSet);
681 FD_CLR(fd, &readFdSetPost);
682 if (asyncIoTable[index].inUse != 0) {
683 asyncIoTable[index].inUse = 0;
686 FD_CLR(fd, &writeFdSet);
687 FD_CLR(fd, &writeFdSetPost);
688 index = AIO_WR_IX(fd);
689 if (asyncIoTable[index].inUse != 0) {
690 asyncIoTable[index].inUse = 0;
701 *--------------------------------------------------------------
705 * Cancel outstanding asynchronous reads and prevent subsequent
706 * reads from completing.
709 * Socket or file is shutdown. Return values mimic Unix shutdown:
710 * 0 success, -1 failure
712 *--------------------------------------------------------------
714 int OS_CloseRead(int fd)
716 if(asyncIoTable[AIO_RD_IX(fd)].inUse != 0) {
717 asyncIoTable[AIO_RD_IX(fd)].inUse = 0;
718 FD_CLR(fd, &readFdSet);
721 return shutdown(fd, 0);
726 *--------------------------------------------------------------
730 * This function was formerly OS_Select. It's purpose is
731 * to pull I/O completion events off the queue and dispatch
732 * them to the appropriate place.
738 * Handlers are called.
740 *--------------------------------------------------------------
742 int OS_DoIo(struct timeval *tmo)
744 int fd, len, selectStatus;
745 OS_AsyncProc procPtr;
746 ClientData clientData;
749 fd_set writeFdSetCpy;
752 FD_ZERO(&readFdSetCpy);
753 FD_ZERO(&writeFdSetCpy);
755 for(fd = 0; fd <= maxFd; fd++) {
756 if(FD_ISSET(fd, &readFdSet)) {
757 FD_SET(fd, &readFdSetCpy);
759 if(FD_ISSET(fd, &writeFdSet)) {
760 FD_SET(fd, &writeFdSetCpy);
765 * If there were no completed events from a prior call, see if there's
768 if(numRdPosted == 0 && numWrPosted == 0) {
769 selectStatus = select((maxFd+1), &readFdSetCpy, &writeFdSetCpy,
771 if(selectStatus < 0) {
775 for(fd = 0; fd <= maxFd; fd++) {
777 * Build up a list of completed events. We'll work off of
778 * this list as opposed to looping through the read and write
779 * fd sets since they can be affected by a callbacl routine.
781 if(FD_ISSET(fd, &readFdSetCpy)) {
783 FD_SET(fd, &readFdSetPost);
784 FD_CLR(fd, &readFdSet);
787 if(FD_ISSET(fd, &writeFdSetCpy)) {
789 FD_SET(fd, &writeFdSetPost);
790 FD_CLR(fd, &writeFdSet);
795 if(numRdPosted == 0 && numWrPosted == 0)
798 for(fd = 0; fd <= maxFd; fd++) {
800 * Do reads and dispatch callback.
802 if(FD_ISSET(fd, &readFdSetPost)
803 && asyncIoTable[AIO_RD_IX(fd)].inUse) {
806 FD_CLR(fd, &readFdSetPost);
807 aioPtr = &asyncIoTable[AIO_RD_IX(fd)];
809 len = read(aioPtr->fd, aioPtr->buf, aioPtr->len);
811 procPtr = aioPtr->procPtr;
812 aioPtr->procPtr = NULL;
813 clientData = aioPtr->clientData;
816 (*procPtr)(clientData, len);
820 * Do writes and dispatch callback.
822 if(FD_ISSET(fd, &writeFdSetPost) &&
823 asyncIoTable[AIO_WR_IX(fd)].inUse) {
826 FD_CLR(fd, &writeFdSetPost);
827 aioPtr = &asyncIoTable[AIO_WR_IX(fd)];
829 len = write(aioPtr->fd, aioPtr->buf, aioPtr->len);
831 procPtr = aioPtr->procPtr;
832 aioPtr->procPtr = NULL;
833 clientData = aioPtr->clientData;
835 (*procPtr)(clientData, len);
842 * Not all systems have strdup().
843 * @@@ autoconf should determine whether or not this is needed, but for now..
845 char * str_dup(const char * str)
847 char * sdup = (char *) malloc(strlen(str) + 1);
857 *----------------------------------------------------------------------
861 * Checks if a client address is in a list of allowed addresses
864 * TRUE if address list is empty or client address is present
865 * in the list, FALSE otherwise.
867 *----------------------------------------------------------------------
869 static int ClientAddrOK(struct sockaddr_in *saPtr, const char *clientList)
872 char *clientListCopy, *cur, *next;
874 if (clientList == NULL || *clientList == '\0') {
878 clientListCopy = str_dup(clientList);
880 for (cur = clientListCopy; cur != NULL; cur = next) {
881 next = strchr(cur, ',');
885 if (inet_addr(cur) == saPtr->sin_addr.s_addr) {
891 free(clientListCopy);
897 *----------------------------------------------------------------------
901 * On platforms that implement concurrent calls to accept
902 * on a shared listening ipcFd, returns 0. On other platforms,
903 * acquires an exclusive lock across all processes sharing a
904 * listening ipcFd, blocking until the lock has been acquired.
907 * 0 for successful call, -1 in case of system error (fatal).
910 * This process now has the exclusive lock.
912 *----------------------------------------------------------------------
914 static int AcquireLock(int sock, int fail_on_intr)
919 lock.l_type = F_WRLCK;
921 lock.l_whence = SEEK_SET;
924 if (fcntl(sock, F_SETLKW, &lock) != -1)
926 } while (errno == EINTR && !fail_on_intr);
936 *----------------------------------------------------------------------
940 * On platforms that implement concurrent calls to accept
941 * on a shared listening ipcFd, does nothing. On other platforms,
942 * releases an exclusive lock acquired by AcquireLock.
945 * 0 for successful call, -1 in case of system error (fatal).
948 * This process no longer holds the lock.
950 *----------------------------------------------------------------------
952 static int ReleaseLock(int sock)
957 lock.l_type = F_UNLCK;
959 lock.l_whence = SEEK_SET;
962 if (fcntl(sock, F_SETLK, &lock) != -1)
964 } while (errno == EINTR);
974 /**********************************************************************
975 * Determine if the errno resulting from a failed accept() warrants a
976 * retry or exit(). Based on Apache's http_main.c accept() handling
977 * and Stevens' Unix Network Programming Vol 1, 2nd Ed, para. 15.6.
979 static int is_reasonable_accept_errno (const int error)
983 /* EPROTO on certain older kernels really means ECONNABORTED, so
984 * we need to ignore it for them. See discussion in new-httpd
985 * archives nh.9701 search for EPROTO. Also see nh.9603, search
986 * for EPROTO: There is potentially a bug in Solaris 2.x x<6, and
987 * other boxes that implement tcp sockets in userland (i.e. on top of
988 * STREAMS). On these systems, EPROTO can actually result in a fatal
989 * loop. See PR#981 for example. It's hard to handle both uses of
996 /* Linux generates the rest of these, other tcp stacks (i.e.
997 * bsd) tend to hide them behind getsockopt() interfaces. They
998 * occur when the net goes sour or the client disconnects after the
999 * three-way handshake has been done in the kernel but before
1000 * userland has picked up the socket. */
1020 /**********************************************************************
1021 * This works around a problem on Linux 2.0.x and SCO Unixware (maybe
1022 * others?). When a connect() is made to a Unix Domain socket, but its
1023 * not accept()ed before the web server gets impatient and close()s, an
1024 * accept() results in a valid file descriptor, but no data to read.
1025 * This causes a block on the first read() - which never returns!
1027 * Another approach to this is to write() to the socket to provoke a
1028 * SIGPIPE, but this is a pain because of the FastCGI protocol, the fact
1029 * that whatever is written has to be universally ignored by all FastCGI
1030 * web servers, and a SIGPIPE handler has to be installed which returns
1031 * (or SIGPIPE is ignored).
1033 * READABLE_UNIX_FD_DROP_DEAD_TIMEVAL = 2,0 by default.
1035 * Making it shorter is probably safe, but I'll leave that to you. Making
1036 * it 0,0 doesn't work reliably. The shorter you can reliably make it,
1037 * the faster your application will be able to recover (waiting 2 seconds
1038 * may _cause_ the problem when there is a very high demand). At any rate,
1039 * this is better than perma-blocking.
1041 static int is_af_unix_keeper(const int fd)
1043 struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
1047 FD_SET(fd, &read_fds);
1049 return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
1053 *----------------------------------------------------------------------
1057 * Accepts a new FastCGI connection. This routine knows whether
1058 * we're dealing with TCP based sockets or NT Named Pipes for IPC.
1061 * -1 if the operation fails, otherwise this is a valid IPC fd.
1064 * New IPC connection is accepted.
1066 *----------------------------------------------------------------------
1068 int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
1072 struct sockaddr_un un;
1073 struct sockaddr_in in;
1077 if (AcquireLock(listen_sock, fail_on_intr))
1083 socklen_t len = sizeof(sa);
1085 int len = sizeof(sa);
1087 socket = accept(listen_sock, (struct sockaddr *)&sa, &len);
1088 } while (socket < 0 && errno == EINTR && !fail_on_intr);
1091 if (!is_reasonable_accept_errno(errno)) {
1092 int errnoSave = errno;
1093 ReleaseLock(listen_sock);
1099 else { /* socket >= 0 */
1102 if (sa.in.sin_family != AF_INET)
1106 /* No replies to outgoing data, so disable Nagle */
1107 setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set));
1110 /* Check that the client IP address is approved */
1111 if (ClientAddrOK(&sa.in, webServerAddrs))
1118 if (ReleaseLock(listen_sock))
1121 if (sa.in.sin_family != AF_UNIX || is_af_unix_keeper(socket))
1125 } /* while(1) - lock */
1131 *----------------------------------------------------------------------
1135 * OS IPC routine to close an IPC connection.
1141 * IPC connection is closed.
1143 *----------------------------------------------------------------------
1145 int OS_IpcClose(int ipcFd)
1147 return OS_Close(ipcFd);
1152 *----------------------------------------------------------------------
1156 * Determines whether this process is a FastCGI process or not.
1159 * Returns 1 if FastCGI, 0 if not.
1164 *----------------------------------------------------------------------
1166 int OS_IsFcgi(int sock)
1169 struct sockaddr_in in;
1170 struct sockaddr_un un;
1173 socklen_t len = sizeof(sa);
1175 int len = sizeof(sa);
1179 if (getpeername(sock, (struct sockaddr *)&sa, &len) != 0 && errno == ENOTCONN) {
1188 *----------------------------------------------------------------------
1192 * Sets selected flag bits in an open file descriptor.
1194 *----------------------------------------------------------------------
1196 void OS_SetFlags(int fd, int flags)
1199 if((val = fcntl(fd, F_GETFL, 0)) < 0) {
1203 if(fcntl(fd, F_SETFL, val) < 0) {