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.14 1999/08/12 23:56:11 roberts Exp $";
23 #include "fcgi_config.h"
25 #include <arpa/inet.h>
28 #include <fcntl.h> /* for fcntl */
30 #include <memory.h> /* for memchr() */
31 #include <netinet/tcp.h>
37 #include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
48 #ifdef HAVE_SYS_SOCKET_H
49 #include <sys/socket.h> /* for getpeername */
58 #include "fcgiappmisc.h"
71 * This structure holds an entry for each oustanding async I/O operation.
74 OS_AsyncProc procPtr; /* callout completion procedure */
75 ClientData clientData; /* caller private data */
84 * Entries in the async I/O table are allocated 2 per file descriptor.
86 * Read Entry Index = fd * 2
87 * Write Entry Index = (fd * 2) + 1
89 #define AIO_RD_IX(fd) (fd * 2)
90 #define AIO_WR_IX(fd) ((fd * 2) + 1)
92 static int asyncIoTableSize = 16;
93 static AioInfo *asyncIoTable = NULL;
95 static int libInitialized = FALSE;
97 static fd_set readFdSet;
98 static fd_set writeFdSet;
100 static fd_set readFdSetPost;
101 static int numRdPosted = 0;
102 static fd_set writeFdSetPost;
103 static int numWrPosted = 0;
104 static int volatile maxFd = -1;
108 *--------------------------------------------------------------
112 * Set up the OS library for use.
114 * NOTE: This function is really only needed for application
115 * asynchronous I/O. It will most likely change in the
116 * future to setup the multi-threaded environment.
119 * Returns 0 if success, -1 if not.
122 * Async I/O table allocated and initialized.
124 *--------------------------------------------------------------
126 int OS_LibInit(int stdioFds[3])
131 asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
132 if(asyncIoTable == NULL) {
136 memset((char *) asyncIoTable, 0,
137 asyncIoTableSize * sizeof(AioInfo));
140 FD_ZERO(&writeFdSet);
141 FD_ZERO(&readFdSetPost);
142 FD_ZERO(&writeFdSetPost);
143 libInitialized = TRUE;
149 *--------------------------------------------------------------
153 * Shutdown the OS library.
159 * Memory freed, fds closed.
161 *--------------------------------------------------------------
163 void OS_LibShutdown()
170 libInitialized = FALSE;
176 *----------------------------------------------------------------------
178 * OS_BuildSockAddrUn --
180 * Using the pathname bindPath, fill in the sockaddr_un structure
181 * *servAddrPtr and the length of this structure *servAddrLen.
183 * The format of the sockaddr_un structure changed incompatibly in
184 * 4.3BSD Reno. Digital UNIX supports both formats, other systems
185 * support one or the other.
188 * 0 for normal return, -1 for failure (bindPath too long).
190 *----------------------------------------------------------------------
193 static int OS_BuildSockAddrUn(const char *bindPath,
194 struct sockaddr_un *servAddrPtr,
197 int bindPathLen = strlen(bindPath);
199 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
200 if(bindPathLen >= sizeof(servAddrPtr->sun_path)) {
203 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
204 if(bindPathLen > sizeof(servAddrPtr->sun_path)) {
208 memset((char *) servAddrPtr, 0, sizeof(*servAddrPtr));
209 servAddrPtr->sun_family = AF_UNIX;
210 memcpy(servAddrPtr->sun_path, bindPath, bindPathLen);
211 #ifdef HAVE_SOCKADDR_UN_SUN_LEN /* 4.3BSD Reno and later: BSDI, DEC */
212 *servAddrLen = sizeof(servAddrPtr->sun_len)
213 + sizeof(servAddrPtr->sun_family)
215 servAddrPtr->sun_len = *servAddrLen;
216 #else /* 4.3 BSD Tahoe: Solaris, HPUX, DEC, ... */
217 *servAddrLen = sizeof(servAddrPtr->sun_family) + bindPathLen;
222 union SockAddrUnion {
223 struct sockaddr_un unixVariant;
224 struct sockaddr_in inetVariant;
229 * OS_CreateLocalIpcFd --
231 * This procedure is responsible for creating the listener socket
232 * on Unix for local process communication. It will create a
233 * domain socket or a TCP/IP socket bound to "localhost" and return
234 * a file descriptor to it to the caller.
237 * Listener socket created. This call returns either a valid
238 * file descriptor or -1 on error.
243 *----------------------------------------------------------------------
245 int OS_CreateLocalIpcFd(const char *bindPath, int backlog)
247 int listenSock, servLen;
248 union SockAddrUnion sa;
252 char host[MAXPATHLEN];
254 strcpy(host, bindPath);
255 if((tp = strchr(host, ':')) != 0) {
257 if((port = atoi(tp)) == 0) {
263 if(tcp && (*host && strcmp(host, "localhost") != 0)) {
264 fprintf(stderr, "To start a service on a TCP port can not "
265 "specify a host name.\n"
266 "You should either use \"localhost:<port>\" or "
267 " just use \":<port>.\"\n");
272 listenSock = socket(AF_INET, SOCK_STREAM, 0);
273 if(listenSock >= 0) {
275 if(setsockopt(listenSock, SOL_SOCKET, SO_REUSEADDR,
276 (char *) &flag, sizeof(flag)) < 0) {
277 fprintf(stderr, "Can't set SO_REUSEADDR.\n");
282 listenSock = socket(AF_UNIX, SOCK_STREAM, 0);
289 * Bind the listening socket.
292 memset((char *) &sa.inetVariant, 0, sizeof(sa.inetVariant));
293 sa.inetVariant.sin_family = AF_INET;
294 sa.inetVariant.sin_addr.s_addr = htonl(INADDR_ANY);
295 sa.inetVariant.sin_port = htons(port);
296 servLen = sizeof(sa.inetVariant);
299 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
300 fprintf(stderr, "Listening socket's path name is too long.\n");
304 if(bind(listenSock, (struct sockaddr *) &sa.unixVariant, servLen) < 0
305 || listen(listenSock, backlog) < 0) {
306 perror("bind/listen");
315 *----------------------------------------------------------------------
319 * Create the socket and connect to the remote application if
322 * This was lifted from the cgi-fcgi application and was abstracted
323 * out because Windows NT does not have a domain socket and must
324 * use a named pipe which has a different API altogether.
327 * -1 if fail or a valid file descriptor if connection succeeds.
330 * Remote connection established.
332 *----------------------------------------------------------------------
334 int OS_FcgiConnect(char *bindPath)
336 union SockAddrUnion sa;
337 int servLen, resultSock;
340 char host[MAXPATHLEN];
344 strcpy(host, bindPath);
345 if((tp = strchr(host, ':')) != 0) {
347 if((port = atoi(tp)) == 0) {
355 if((hp = gethostbyname((*host ? host : "localhost"))) == NULL) {
356 fprintf(stderr, "Unknown host: %s\n", bindPath);
359 sa.inetVariant.sin_family = AF_INET;
360 memcpy(&sa.inetVariant.sin_addr, hp->h_addr, hp->h_length);
361 sa.inetVariant.sin_port = htons(port);
362 servLen = sizeof(sa.inetVariant);
363 resultSock = socket(AF_INET, SOCK_STREAM, 0);
365 if(OS_BuildSockAddrUn(bindPath, &sa.unixVariant, &servLen)) {
366 fprintf(stderr, "Listening socket's path name is too long.\n");
369 resultSock = socket(AF_UNIX, SOCK_STREAM, 0);
372 assert(resultSock >= 0);
373 connectStatus = connect(resultSock, (struct sockaddr *) &sa.unixVariant,
375 if(connectStatus >= 0) {
379 * Most likely (errno == ENOENT || errno == ECONNREFUSED)
380 * and no FCGI application server is running.
389 *--------------------------------------------------------------
393 * Pass through to the unix read function.
396 * Returns number of byes read, 0, or -1 failure: errno
397 * contains actual error.
402 *--------------------------------------------------------------
404 int OS_Read(int fd, char * buf, size_t len)
406 return(read(fd, buf, len));
410 *--------------------------------------------------------------
414 * Pass through to unix write function.
417 * Returns number of byes read, 0, or -1 failure: errno
418 * contains actual error.
423 *--------------------------------------------------------------
425 int OS_Write(int fd, char * buf, size_t len)
427 return(write(fd, buf, len));
432 *----------------------------------------------------------------------
436 * Spawns a new FastCGI listener process.
439 * 0 if success, -1 if error.
442 * Child process spawned.
444 *----------------------------------------------------------------------
446 int OS_SpawnChild(char *appPath, int listenFd)
455 if(forkResult == 0) {
457 * Close STDIN unconditionally. It's used by the parent
458 * process for CGI communication. The FastCGI applciation
459 * will be replacing this with the FastCGI listenFd IF
460 * STDIN_FILENO is the same as FCGI_LISTENSOCK_FILENO
461 * (which it is on Unix). Regardless, STDIN, STDOUT, and
462 * STDERR will be closed as the FastCGI process uses a
463 * multiplexed socket in their place.
468 * If the listenFd is already the value of FCGI_LISTENSOCK_FILENO
469 * we're set. If not, change it so the child knows where to
470 * get the listen socket from.
472 if(listenFd != FCGI_LISTENSOCK_FILENO) {
473 dup2(listenFd, FCGI_LISTENSOCK_FILENO);
477 close(STDOUT_FILENO);
478 close(STDERR_FILENO);
481 * We're a child. Exec the application.
483 * XXX: entire environment passes through
485 execl(appPath, appPath, NULL);
487 * XXX: Can't do this as we've already closed STDERR!!!
498 *--------------------------------------------------------------
500 * OS_AsyncReadStdin --
502 * This initiates an asynchronous read on the standard
505 * The abstraction is necessary because Windows NT does not
506 * have a clean way of "select"ing a file descriptor for
510 * -1 if error, 0 otherwise.
513 * Asynchronous bit is set in the readfd variable and
514 * request is enqueued.
516 *--------------------------------------------------------------
518 int OS_AsyncReadStdin(void *buf, int len, OS_AsyncProc procPtr,
519 ClientData clientData)
521 int index = AIO_RD_IX(STDIN_FILENO);
523 ASSERT(asyncIoTable[index].inUse == 0);
524 asyncIoTable[index].procPtr = procPtr;
525 asyncIoTable[index].clientData = clientData;
526 asyncIoTable[index].fd = STDIN_FILENO;
527 asyncIoTable[index].len = len;
528 asyncIoTable[index].offset = 0;
529 asyncIoTable[index].buf = buf;
530 asyncIoTable[index].inUse = 1;
531 FD_SET(STDIN_FILENO, &readFdSet);
532 if(STDIN_FILENO > maxFd)
533 maxFd = STDIN_FILENO;
537 static void GrowAsyncTable(void)
539 int oldTableSize = asyncIoTableSize;
541 asyncIoTableSize = asyncIoTableSize * 2;
542 asyncIoTable = (AioInfo *)realloc(asyncIoTable, asyncIoTableSize * sizeof(AioInfo));
543 if(asyncIoTable == NULL) {
547 memset((char *) &asyncIoTable[oldTableSize], 0,
548 oldTableSize * sizeof(AioInfo));
554 *--------------------------------------------------------------
558 * This initiates an asynchronous read on the file
559 * handle which may be a socket or named pipe.
561 * We also must save the ProcPtr and ClientData, so later
562 * when the io completes, we know who to call.
564 * We don't look at any results here (the ReadFile may
565 * return data if it is cached) but do all completion
566 * processing in OS_Select when we get the io completion
567 * port done notifications. Then we call the callback.
570 * -1 if error, 0 otherwise.
573 * Asynchronous I/O operation is queued for completion.
575 *--------------------------------------------------------------
577 int OS_AsyncRead(int fd, int offset, void *buf, int len,
578 OS_AsyncProc procPtr, ClientData clientData)
580 int index = AIO_RD_IX(fd);
582 ASSERT(asyncIoTable != NULL);
587 if(index >= asyncIoTableSize) {
591 ASSERT(asyncIoTable[index].inUse == 0);
592 asyncIoTable[index].procPtr = procPtr;
593 asyncIoTable[index].clientData = clientData;
594 asyncIoTable[index].fd = fd;
595 asyncIoTable[index].len = len;
596 asyncIoTable[index].offset = offset;
597 asyncIoTable[index].buf = buf;
598 asyncIoTable[index].inUse = 1;
599 FD_SET(fd, &readFdSet);
604 *--------------------------------------------------------------
608 * This initiates an asynchronous write on the "fake" file
609 * descriptor (which may be a file, socket, or named pipe).
610 * We also must save the ProcPtr and ClientData, so later
611 * when the io completes, we know who to call.
613 * We don't look at any results here (the WriteFile generally
614 * completes immediately) but do all completion processing
615 * in OS_DoIo when we get the io completion port done
616 * notifications. Then we call the callback.
619 * -1 if error, 0 otherwise.
622 * Asynchronous I/O operation is queued for completion.
624 *--------------------------------------------------------------
626 int OS_AsyncWrite(int fd, int offset, void *buf, int len,
627 OS_AsyncProc procPtr, ClientData clientData)
629 int index = AIO_WR_IX(fd);
634 if(index >= asyncIoTableSize) {
638 ASSERT(asyncIoTable[index].inUse == 0);
639 asyncIoTable[index].procPtr = procPtr;
640 asyncIoTable[index].clientData = clientData;
641 asyncIoTable[index].fd = fd;
642 asyncIoTable[index].len = len;
643 asyncIoTable[index].offset = offset;
644 asyncIoTable[index].buf = buf;
645 asyncIoTable[index].inUse = 1;
646 FD_SET(fd, &writeFdSet);
651 *--------------------------------------------------------------
655 * Closes the descriptor. This is a pass through to the
659 * 0 for success, -1 on failure
664 *--------------------------------------------------------------
668 int index = AIO_RD_IX(fd);
670 FD_CLR(fd, &readFdSet);
671 FD_CLR(fd, &readFdSetPost);
672 if(asyncIoTable[index].inUse != 0) {
673 asyncIoTable[index].inUse = 0;
676 FD_CLR(fd, &writeFdSet);
677 FD_CLR(fd, &writeFdSetPost);
678 index = AIO_WR_IX(fd);
679 if(asyncIoTable[index].inUse != 0) {
680 asyncIoTable[index].inUse = 0;
688 *--------------------------------------------------------------
692 * Cancel outstanding asynchronous reads and prevent subsequent
693 * reads from completing.
696 * Socket or file is shutdown. Return values mimic Unix shutdown:
697 * 0 success, -1 failure
699 *--------------------------------------------------------------
701 int OS_CloseRead(int fd)
703 if(asyncIoTable[AIO_RD_IX(fd)].inUse != 0) {
704 asyncIoTable[AIO_RD_IX(fd)].inUse = 0;
705 FD_CLR(fd, &readFdSet);
708 return shutdown(fd, 0);
713 *--------------------------------------------------------------
717 * This function was formerly OS_Select. It's purpose is
718 * to pull I/O completion events off the queue and dispatch
719 * them to the appropriate place.
725 * Handlers are called.
727 *--------------------------------------------------------------
729 int OS_DoIo(struct timeval *tmo)
731 int fd, len, selectStatus;
732 OS_AsyncProc procPtr;
733 ClientData clientData;
736 fd_set writeFdSetCpy;
738 FD_ZERO(&readFdSetCpy);
739 FD_ZERO(&writeFdSetCpy);
741 for(fd = 0; fd <= maxFd; fd++) {
742 if(FD_ISSET(fd, &readFdSet)) {
743 FD_SET(fd, &readFdSetCpy);
745 if(FD_ISSET(fd, &writeFdSet)) {
746 FD_SET(fd, &writeFdSetCpy);
751 * If there were no completed events from a prior call, see if there's
754 if(numRdPosted == 0 && numWrPosted == 0) {
755 selectStatus = select((maxFd+1), &readFdSetCpy, &writeFdSetCpy,
757 if(selectStatus < 0) {
761 for(fd = 0; fd <= maxFd; fd++) {
763 * Build up a list of completed events. We'll work off of
764 * this list as opposed to looping through the read and write
765 * fd sets since they can be affected by a callbacl routine.
767 if(FD_ISSET(fd, &readFdSetCpy)) {
769 FD_SET(fd, &readFdSetPost);
770 FD_CLR(fd, &readFdSet);
773 if(FD_ISSET(fd, &writeFdSetCpy)) {
775 FD_SET(fd, &writeFdSetPost);
776 FD_CLR(fd, &writeFdSet);
781 if(numRdPosted == 0 && numWrPosted == 0)
784 for(fd = 0; fd <= maxFd; fd++) {
786 * Do reads and dispatch callback.
788 if(FD_ISSET(fd, &readFdSetPost)
789 && asyncIoTable[AIO_RD_IX(fd)].inUse) {
792 FD_CLR(fd, &readFdSetPost);
793 aioPtr = &asyncIoTable[AIO_RD_IX(fd)];
795 len = read(aioPtr->fd, aioPtr->buf, aioPtr->len);
797 procPtr = aioPtr->procPtr;
798 aioPtr->procPtr = NULL;
799 clientData = aioPtr->clientData;
802 (*procPtr)(clientData, len);
806 * Do writes and dispatch callback.
808 if(FD_ISSET(fd, &writeFdSetPost) &&
809 asyncIoTable[AIO_WR_IX(fd)].inUse) {
812 FD_CLR(fd, &writeFdSetPost);
813 aioPtr = &asyncIoTable[AIO_WR_IX(fd)];
815 len = write(aioPtr->fd, aioPtr->buf, aioPtr->len);
817 procPtr = aioPtr->procPtr;
818 aioPtr->procPtr = NULL;
819 clientData = aioPtr->clientData;
821 (*procPtr)(clientData, len);
829 *----------------------------------------------------------------------
833 * Checks if a client address is in a list of allowed addresses
836 * TRUE if address list is empty or client address is present
837 * in the list, FALSE otherwise.
839 *----------------------------------------------------------------------
841 static int ClientAddrOK(struct sockaddr_in *saPtr, const char *clientList)
844 char *clientListCopy, *cur, *next;
845 char *newString = NULL;
848 if(clientList == NULL || *clientList == '\0') {
852 strLen = strlen(clientList);
853 clientListCopy = (char *)malloc(strLen + 1);
854 assert(newString != NULL);
855 memcpy(newString, clientList, strLen);
856 newString[strLen] = '\000';
858 for(cur = clientListCopy; cur != NULL; cur = next) {
859 next = strchr(cur, ',');
863 if(inet_addr(cur) == saPtr->sin_addr.s_addr) {
868 free(clientListCopy);
874 *----------------------------------------------------------------------
878 * On platforms that implement concurrent calls to accept
879 * on a shared listening ipcFd, returns 0. On other platforms,
880 * acquires an exclusive lock across all processes sharing a
881 * listening ipcFd, blocking until the lock has been acquired.
884 * 0 for successful call, -1 in case of system error (fatal).
887 * This process now has the exclusive lock.
889 *----------------------------------------------------------------------
891 static int AcquireLock(int sock, int fail_on_intr)
896 lock.l_type = F_WRLCK;
898 lock.l_whence = SEEK_SET;
901 if (fcntl(sock, F_SETLKW, &lock) != -1)
903 } while (errno == EINTR && !fail_on_intr);
913 *----------------------------------------------------------------------
917 * On platforms that implement concurrent calls to accept
918 * on a shared listening ipcFd, does nothing. On other platforms,
919 * releases an exclusive lock acquired by AcquireLock.
922 * 0 for successful call, -1 in case of system error (fatal).
925 * This process no longer holds the lock.
927 *----------------------------------------------------------------------
929 static int ReleaseLock(int sock)
934 lock.l_type = F_UNLCK;
936 lock.l_whence = SEEK_SET;
939 if (fcntl(sock, F_SETLK, &lock) != -1)
941 } while (errno == EINTR);
951 /**********************************************************************
952 * Determine if the errno resulting from a failed accept() warrants a
953 * retry or exit(). Based on Apache's http_main.c accept() handling
954 * and Stevens' Unix Network Programming Vol 1, 2nd Ed, para. 15.6.
956 static int is_reasonable_accept_errno (const int error)
960 /* EPROTO on certain older kernels really means ECONNABORTED, so
961 * we need to ignore it for them. See discussion in new-httpd
962 * archives nh.9701 search for EPROTO. Also see nh.9603, search
963 * for EPROTO: There is potentially a bug in Solaris 2.x x<6, and
964 * other boxes that implement tcp sockets in userland (i.e. on top of
965 * STREAMS). On these systems, EPROTO can actually result in a fatal
966 * loop. See PR#981 for example. It's hard to handle both uses of
973 /* Linux generates the rest of these, other tcp stacks (i.e.
974 * bsd) tend to hide them behind getsockopt() interfaces. They
975 * occur when the net goes sour or the client disconnects after the
976 * three-way handshake has been done in the kernel but before
977 * userland has picked up the socket. */
997 /**********************************************************************
998 * This works around a problem on Linux 2.0.x and SCO Unixware (maybe
999 * others?). When a connect() is made to a Unix Domain socket, but its
1000 * not accept()ed before the web server gets impatient and close()s, an
1001 * accept() results in a valid file descriptor, but no data to read.
1002 * This causes a block on the first read() - which never returns!
1004 * Another approach to this is to write() to the socket to provoke a
1005 * SIGPIPE, but this is a pain because of the FastCGI protocol, the fact
1006 * that whatever is written has to be universally ignored by all FastCGI
1007 * web servers, and a SIGPIPE handler has to be installed which returns
1008 * (or SIGPIPE is ignored).
1010 * READABLE_UNIX_FD_DROP_DEAD_TIMEVAL = 2,0 by default.
1012 * Making it shorter is probably safe, but I'll leave that to you. Making
1013 * it 0,0 doesn't work reliably. The shorter you can reliably make it,
1014 * the faster your application will be able to recover (waiting 2 seconds
1015 * may _cause_ the problem when there is a very high demand). At any rate,
1016 * this is better than perma-blocking.
1018 static int is_af_unix_keeper(const int fd)
1020 struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
1024 FD_SET(fd, &read_fds);
1026 return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
1030 *----------------------------------------------------------------------
1034 * Accepts a new FastCGI connection. This routine knows whether
1035 * we're dealing with TCP based sockets or NT Named Pipes for IPC.
1038 * -1 if the operation fails, otherwise this is a valid IPC fd.
1041 * New IPC connection is accepted.
1043 *----------------------------------------------------------------------
1045 int OS_Accept(int listen_sock, int fail_on_intr, const char *webServerAddrs)
1049 struct sockaddr_un un;
1050 struct sockaddr_in in;
1054 if (AcquireLock(listen_sock, fail_on_intr))
1060 socklen_t len = sizeof(sa);
1062 int len = sizeof(sa);
1064 socket = accept(listen_sock, (struct sockaddr *)&sa, &len);
1065 } while (socket < 0 && errno == EINTR && !fail_on_intr);
1068 if (!is_reasonable_accept_errno(errno)) {
1069 int errnoSave = errno;
1070 ReleaseLock(listen_sock);
1076 else { /* socket >= 0 */
1079 if (sa.in.sin_family != AF_INET)
1083 /* No replies to outgoing data, so disable Nagle */
1084 setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, (char *)&set, sizeof(set));
1087 /* Check that the client IP address is approved */
1088 if (ClientAddrOK(&sa.in, webServerAddrs))
1095 if (ReleaseLock(listen_sock))
1098 if (sa.in.sin_family != AF_UNIX || is_af_unix_keeper(socket))
1102 } /* while(1) - lock */
1108 *----------------------------------------------------------------------
1112 * OS IPC routine to close an IPC connection.
1118 * IPC connection is closed.
1120 *----------------------------------------------------------------------
1122 int OS_IpcClose(int ipcFd)
1124 return OS_Close(ipcFd);
1129 *----------------------------------------------------------------------
1133 * Determines whether this process is a FastCGI process or not.
1136 * Returns 1 if FastCGI, 0 if not.
1141 *----------------------------------------------------------------------
1143 int OS_IsFcgi(int sock)
1146 struct sockaddr_in in;
1147 struct sockaddr_un un;
1150 socklen_t len = sizeof(sa);
1152 int len = sizeof(sa);
1155 if (getpeername(sock, (struct sockaddr *)&sa, &len) != 0 && errno == ENOTCONN) {
1164 *----------------------------------------------------------------------
1168 * Sets selected flag bits in an open file descriptor.
1170 *----------------------------------------------------------------------
1172 void OS_SetFlags(int fd, int flags)
1175 if((val = fcntl(fd, F_GETFL, 0)) < 0) {
1179 if(fcntl(fd, F_SETFL, val) < 0) {