Bugzilla bug 119340: an inelegant but more reliable way to kill the

multithreaded 'selfserv' process on Linux.
Modified files:
    cmd/selfserv/selfserv.c tests/common/init.sh tests/ssl/ssl.sh
This commit is contained in:
wtc%netscape.com 2002-01-23 03:18:57 +00:00
Родитель 9a32eb82a3
Коммит bd2bc25ec1
3 изменённых файлов: 49 добавлений и 9 удалений

Просмотреть файл

@ -141,6 +141,15 @@ static int requestCert;
static int verbose;
static SECItem bigBuf;
static const char *pidFile;
/*
* On Linux, the first thread we create writes its pid to a file.
* (See bug 119340 for why we do this.)
*/
#ifdef LINUX
static PRInt32 threadIndex;
#endif
static PRThread * acceptorThread;
static PRLogModuleInfo *lm;
@ -420,6 +429,27 @@ thread_wrapper(void * arg)
{
perThread * slot = (perThread *)arg;
#ifdef LINUX /* bug 119403 */
if (pidFile && PR_AtomicIncrement(&threadIndex) == 1) {
char *pidFile2;
FILE *tmpfile;
pidFile2 = PORT_Alloc(PORT_Strlen(pidFile) + 3);
if (pidFile2 == NULL) {
return; /* failed */
}
strcpy(pidFile2, pidFile);
strcat(pidFile2, ".2");
tmpfile=fopen(pidFile2,"w+");
if (tmpfile) {
fprintf(tmpfile,"%d",getpid());
fclose(tmpfile);
}
PORT_Free(pidFile2);
}
#endif /* LINUX */
slot->rv = (* slot->startFunc)(slot->a, slot->b, slot->c);
/* notify the thread exit handler. */
@ -1384,7 +1414,6 @@ main(int argc, char **argv)
char * cipherString= NULL;
const char * dir = ".";
char * passwd = NULL;
const char * pidFile = NULL;
char * tmp;
char * envString;
PRFileDesc * listen_sock;

Просмотреть файл

@ -300,11 +300,6 @@ if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
tee ${LOGFILE}
KILL="kill"
if [ "${OS_ARCH}" = "Linux" ]; then
#on linux the selfserv needs up to 30 seconds to fully die and free
#the socket
SLEEP="sleep 5" # taking the chance and trying on the tinderboxes
fi
if [ `uname -s` = "SunOS" ]; then
PS="/usr/5bin/ps"
else
@ -389,7 +384,7 @@ if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
export PATH LD_LIBRARY_PATH SHLIB_PATH LIBPATH
export DOMSUF HOSTADDR
export KILL SLEEP PS
export KILL PS
export MOZILLA_ROOT SECURITY_ROOT DIST TESTDIR OBJDIR HOSTDIR QADIR
export LOGFILE SCRIPTNAME

Просмотреть файл

@ -141,13 +141,29 @@ wait_for_selfserv()
########################################################################
kill_selfserv()
{
${KILL} `cat ${SERVERPID}`
# Bug 119340: This is an inelegant but more reliable way to ensure
# that a multithreaded process on Linux has been completely killed.
# Recall that each thread is a process on Linux. Instead of killing
# the primary thread, we kill the first thread created by selfserv and
# let the thread manager take care of terminating the other threads in
# selfserv. The assumption we rely on is that the primary thread is
# the last one to go because it's the parent of the thread manager.
#
# On Linux, the first thread created by selfserv writes its pid to the
# {SERVERPID}.2 file.
if [ "${OS_ARCH}" = "Linux" ]; then
${KILL} `cat ${SERVERPID}.2`
else
${KILL} `cat ${SERVERPID}`
fi
wait `cat ${SERVERPID}`
if [ ${fileout} -eq 1 ]; then
cat ${SERVEROUTFILE}
fi
${SLEEP} #FIXME linux waits 30 seconds - find a shorter way (sockets free)
rm ${SERVERPID}
if [ "${OS_ARCH}" = "Linux" ]; then
rm ${SERVERPID}.2
fi
}
########################### start_selfserv #############################