*** include/sigfix.h.ORIG Wed Aug 16 17:38:42 2000 --- include/sigfix.h Sat Dec 2 01:13:59 2000 *************** *** 23,34 **** memset(&sa, 0, sizeof(sa)); sa.sa_handler = func; sigemptyset(&sa.sa_mask); ! #ifdef SA_RESETHAND ! sa.sa_flags |= SA_RESETHAND; ! #endif ! #ifdef SA_NODEFER ! sa.sa_flags |= SA_NODEFER; ! #endif #ifdef SA_RESTART sa.sa_flags |= SA_RESTART; #endif --- 23,39 ---- memset(&sa, 0, sizeof(sa)); sa.sa_handler = func; sigemptyset(&sa.sa_mask); ! /* ! Do not use SA_RESETHAND: it prevents reinstalling the handler after the ! a signal has been catched! ! Do not use SA_NODEFER: it blocking the caught signal while executing the ! handler! ! */ ! ! /* ! Silently restart an interrupted system call: not really necessary but ! smoothes the execution path. ! */ #ifdef SA_RESTART sa.sa_flags |= SA_RESTART; #endif *** server/socket.c.ORIG Wed Aug 16 17:38:43 2000 --- server/socket.c Sat Dec 2 00:19:58 2000 *************** *** 320,329 **** } if (servermode == THREADED && (acceptor < 0 && errno != EAGAIN)) { ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_ERROR, 0, "server exiting: fork failed"); hadsigint = 1; } /* Wait for any signal to arrive, esp SIGCHLD and SIGHUP. SIGHUP */ /* will cause a re-read of the config file, everything else: loop. */ if (!hadfatalsig && !hadsigint && !hadresetsig && *infd != S5InvalidIOHandle) { --- 320,332 ---- } if (servermode == THREADED && (acceptor < 0 && errno != EAGAIN)) { ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_ERROR, 0, "server exiting: fork failed (errno=%d)", errno); hadsigint = 1; } + /* try again to fork in case a child terminates, otherwise DoFork() is never reached! */ + if (acceptor < 0) acceptor = 0; + /* Wait for any signal to arrive, esp SIGCHLD and SIGHUP. SIGHUP */ /* will cause a re-read of the config file, everything else: loop. */ if (!hadfatalsig && !hadsigint && !hadresetsig && *infd != S5InvalidIOHandle) { *************** *** 462,471 **** MUTEX_LOCK(conn_mutex); nconns--; ! if (hadresetsig) { nservers--; MUTEX_UNLOCK(conn_mutex); ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: I have to go."); THREAD_EXIT(0); } MUTEX_UNLOCK(conn_mutex); --- 465,475 ---- MUTEX_LOCK(conn_mutex); nconns--; ! if (nconns == 0 && hadresetsig) { ! /* exit thread only if no open connections exist */ nservers--; MUTEX_UNLOCK(conn_mutex); ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: I have to go (after DoWork)."); THREAD_EXIT(0); } MUTEX_UNLOCK(conn_mutex); *************** *** 479,490 **** exit(-1); } ! if (hadresetsig) { nservers--; S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: Releasing semaphore/mutex"); semrelease(asem); MUTEX_UNLOCK(accept_mutex); ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: I have to go."); THREAD_EXIT(0); } --- 483,495 ---- exit(-1); } ! if (nconns == 0 && hadresetsig) { ! /* exit thread only if no open connections exist */ nservers--; S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: Releasing semaphore/mutex"); semrelease(asem); MUTEX_UNLOCK(accept_mutex); ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: I have to go (accept-loop)."); THREAD_EXIT(0); } *************** *** 493,499 **** len = sizeof(source); memset(&source, 0, len); if ((afd = AcceptConnection(in, &source.sa, &len)) == S5InvalidIOHandle) { - nservers--; if (errno != ETIMEDOUT) { hadresetsig = 1; aerrno = -1; --- 498,503 ---- *************** *** 508,524 **** semrelease(asem); MUTEX_UNLOCK(accept_mutex); ! if (aerrno <= 0) { ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_DEBUG(15), 0, "DoThreadWork: Exiting"); THREAD_EXIT(aerrno); } MUTEX_LOCK(conn_mutex); nconns++; MUTEX_UNLOCK(conn_mutex); break; ! } ! } } #endif --- 512,534 ---- semrelease(asem); MUTEX_UNLOCK(accept_mutex); ! if (aerrno < 0) { ! /* no timeout, a real error */ ! nservers--; ! S5LogUpdate(S5LogDefaultHandle, S5_LOG_WARNING, 0, "DoThreadWork: Exiting (errno=%d)", errno); THREAD_EXIT(aerrno); } + if (aerrno == 0) { /* accept timeout */ + aerrno = 1; /* reset to initial value */ + continue; /* while - try again to accept */ + } MUTEX_LOCK(conn_mutex); nconns++; MUTEX_UNLOCK(conn_mutex); break; ! } /* while */ ! } /* for */ } #endif