Finished mbtask threads

This commit is contained in:
Michiel Broek 2003-12-24 12:00:00 +00:00
parent 71df4a5d22
commit fb927af2bd
3 changed files with 25 additions and 26 deletions

View File

@ -658,11 +658,9 @@ int checktasks(int onsig)
*/ */
void start_shutdown(int onsig) void start_shutdown(int onsig)
{ {
Syslog('+', "Trigger shutdown on signal %s", SigName[onsig]); Syslog('s', "Trigger shutdown on signal %s", SigName[onsig]);
signal(onsig, SIG_IGN); signal(onsig, SIG_IGN);
G_Shutdown = TRUE; G_Shutdown = TRUE;
if (nodaemon && (onsig == SIGINT))
die(SIGTERM);
} }
@ -719,8 +717,7 @@ void die(int onsig)
* Now stop the threads * Now stop the threads
*/ */
T_Shutdown = TRUE; T_Shutdown = TRUE;
if (cmd_run || ping_run || sched_run) Syslog('+', "Signal all threads to stop");
Syslog('+', "Waiting for threads to stop");
/* /*
* Wait at most 2 seconds for the threads, internal they are * Wait at most 2 seconds for the threads, internal they are
@ -730,6 +727,7 @@ void die(int onsig)
while ((cmd_run || ping_run || sched_run) && (time(NULL) < now)) { while ((cmd_run || ping_run || sched_run) && (time(NULL) < now)) {
sleep(1); sleep(1);
} }
Syslog('+', "All threads stopped");
/* /*
* Free memory * Free memory
@ -931,7 +929,6 @@ void start_scheduler(void)
struct passwd *pw; struct passwd *pw;
char *cmd = NULL; char *cmd = NULL;
int rc; int rc;
pthread_attr_t attr;
InitFidonet(); InitFidonet();
@ -953,7 +950,7 @@ void start_scheduler(void)
* Setup UNIX Datagram socket * Setup UNIX Datagram socket
*/ */
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
Syslog('?', "$Can't create socket"); WriteError("$Can't create socket");
die(MBERR_INIT_ERROR); die(MBERR_INIT_ERROR);
} }
@ -964,7 +961,7 @@ void start_scheduler(void)
if (bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { if (bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
close(sock); close(sock);
sock = -1; sock = -1;
Syslog('?', "$Can't bind socket %s", spath); WriteError("$Can't bind socket %s", spath);
die(MBERR_INIT_ERROR); die(MBERR_INIT_ERROR);
} }
@ -986,22 +983,24 @@ void start_scheduler(void)
initnl(); initnl();
sem_set((char *)"scanout", TRUE); sem_set((char *)"scanout", TRUE);
if (!TCFG.max_tcp && !pots_lines && !isdn_lines) { if (!TCFG.max_tcp && !pots_lines && !isdn_lines) {
Syslog('?', "ERROR: this system cannot connect to other systems, check setup"); Syslog('?', "WARNING: this system cannot connect to other systems, check setup");
} }
/* /*
* Install threads * Install the threads that do the real work.
*/ */
pthread_attr_init(&attr); if ((rc = pthread_create(&p_thread[0], NULL, (void (*))ping_thread, NULL))) {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); WriteError("$pthread_create ping_thread rc=%d", rc);
rc = pthread_create(&p_thread[0], NULL, (void (*))ping_thread, NULL); die(SIGTERM);
Syslog('l', "pthread_create ping_thread rc=%d", rc); } else if ((rc = pthread_create(&p_thread[1], NULL, (void (*))cmd_thread, NULL))) {
rc = pthread_create(&p_thread[1], NULL, (void (*))cmd_thread, NULL); WriteError("$pthread_create cmd_thread rc=%d", rc);
Syslog('l', "pthread_create cmd_thread rc=%d", rc); die(SIGTERM);
rc = pthread_create(&p_thread[2], NULL, (void (*))scheduler, NULL); } else if ((rc = pthread_create(&p_thread[2], NULL, (void (*))scheduler, NULL))) {
Syslog('l', "pthread_create scheduler rc=%d", rc); WriteError("$pthread_create scheduler rc=%d", rc);
pthread_attr_destroy(&attr); die(SIGTERM);
} else {
Syslog('+', "All threads installed"); Syslog('+', "All threads installed");
}
/* /*
* Sleep until we die * Sleep until we die
@ -1034,7 +1033,7 @@ void *scheduler(void)
double loadavg[3]; double loadavg[3];
pp_list *tpl; pp_list *tpl;
Syslog('+', "Starting scheduler thread with pid %d", (int)getpid()); Syslog('+', "Starting scheduler thread");
sched_run = TRUE; sched_run = TRUE;
pw = getpwuid(getuid()); pw = getpwuid(getuid());
@ -1471,7 +1470,7 @@ int main(int argc, char **argv)
* For debugging, run in foreground mode * For debugging, run in foreground mode
*/ */
mypid = getpid(); mypid = getpid();
scheduler(); start_scheduler();
} else { } else {
/* /*
* Server initialization is complete. Now we can fork the * Server initialization is complete. Now we can fork the

View File

@ -339,7 +339,7 @@ void *ping_thread(void)
static time_t pingsend; static time_t pingsend;
time_t now; time_t now;
Syslog('+', "Starting ping thread with pid %d", (int)getpid()); Syslog('+', "Starting ping thread");
pingresult[1] = pingresult[2] = FALSE; pingresult[1] = pingresult[2] = FALSE;
pingnr = 2; pingnr = 2;
internet = FALSE; internet = FALSE;

View File

@ -584,7 +584,7 @@ void *cmd_thread(void)
struct pollfd pfd; struct pollfd pfd;
static char buf[2048]; static char buf[2048];
Syslog('+', "Starting cmd thread with pid %d", (int)getpid()); Syslog('+', "Starting cmd thread");
cmd_run = TRUE; cmd_run = TRUE;
while (! T_Shutdown) { while (! T_Shutdown) {
@ -601,9 +601,9 @@ void *cmd_thread(void)
/* /*
* Poll can be interrupted by a finished child so that's not a real error. * Poll can be interrupted by a finished child so that's not a real error.
*/ */
// if (errno != EINTR) { if (errno != EINTR) {
Syslog('?', "$poll() rc=%d sock=%d, events=%04x", rc, sock, pfd.revents); Syslog('?', "$poll() rc=%d sock=%d, events=%04x", rc, sock, pfd.revents);
// } }
} else if (rc) { } else if (rc) {
if (pfd.revents & POLLIN) { if (pfd.revents & POLLIN) {
/* /*