* userv - overlord.c
* daemon main program, collects request and forks handlers
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1997,1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
#include <fnmatch.h>
#include <sys/wait.h>
#include <sys/types.h>
-#include <sys/time.h>
#include <sys/stat.h>
#include <sys/socket.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
+#include <time.h>
#include <dirent.h>
#include <sys/un.h>
pid_t overlordpid;
static pid_t checkpid= -1, detachpid= -1;
-static sig_atomic_t needcheck= 1;
+static sig_atomic_t needcheck= 1; /* 2 means we half-expect the server to be down */
static void checkstalepipes(void) {
/* There is an unimportant race here. If there is a stale pipe but
} else if (!WIFEXITED(status)) {
syslog(LOG_ERR,"call pid %ld died due to unknown reason, code %d",
(long)r,status);
+ } else if (WEXITSTATUS(status)==10) {
+ needcheck= 2;
} else if (WEXITSTATUS(status)>12) {
if (WEXITSTATUS(status)>24)
syslog(LOG_ERR,"call pid %ld exited with status %d >24",
(long)r,WEXITSTATUS(status));
checkstalepipes();
+ needcheck= 1;
}
}
}
r= sigprocmask(how,&set,0); assert(!r);
}
-static void NONRETURNING docheck(void) {
+static void NONRETURNING docheck(int needwanted) {
#ifndef DEBUG
/* This subprocess exits with status 0 if the parent should die,
* 1 if it should not, and something else if it fails horribly.
r= connect(sfd,(struct sockaddr*)&ssockname,sizeof(ssockname));
if (r) {
- if (errno == ECONNREFUSED || errno == ENOENT)
- { syslog(LOG_WARNING,"real uservd daemon is not running: %m"); exit(0); }
+ if (errno == ECONNREFUSED || errno == ENOENT) {
+ if (needwanted != 2)
+ syslog(LOG_WARNING,"real uservd daemon is not running: %m");
+ exit(0);
+ }
syslog(LOG_ERR,"unable to connect to uservd daemon: %m"); exit(1);
}
request_mbuf.clientpid= -1;
request_mbuf.serviceuserlen= 0;
request_mbuf.servicelen= 0;
- request_mbuf.lognamelen= 0;
+ request_mbuf.loginnamelen= 0;
request_mbuf.spoofed= 0;
request_mbuf.cwdlen= 0;
request_mbuf.overridelen= -1;
for (;;) {
if (needcheck) {
- assert(checkpid==-1);
- for (;;) {
+ while (checkpid==-1) {
checkpid= fork();
if (checkpid!=-1) {
- if (!checkpid) docheck();
+ if (!checkpid) docheck(needcheck);
break;
} else if (errno==EAGAIN) {
syslog(LOG_ERR,"fork for check - will wait and retry: %m");