chiark / gitweb /
[PATCH] clarify the shortcomings of %e
[elogind.git] / udevd.c
1 /*
2  * udevd.c - hotplug event serializer
3  *
4  * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
5  * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
6  *
7  *
8  *      This program is free software; you can redistribute it and/or modify it
9  *      under the terms of the GNU General Public License as published by the
10  *      Free Software Foundation version 2 of the License.
11  *
12  *      This program is distributed in the hope that it will be useful, but
13  *      WITHOUT ANY WARRANTY; without even the implied warranty of
14  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *      General Public License for more details.
16  *
17  *      You should have received a copy of the GNU General Public License along
18  *      with this program; if not, write to the Free Software Foundation, Inc.,
19  *      675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #include <stddef.h>
24 #include <signal.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <dirent.h>
32 #include <fcntl.h>
33 #include <sys/select.h>
34 #include <sys/wait.h>
35 #include <sys/time.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <sys/un.h>
39 #include <sys/sysinfo.h>
40 #include <sys/stat.h>
41
42 #include "list.h"
43 #include "udev_libc_wrapper.h"
44 #include "udev.h"
45 #include "udev_version.h"
46 #include "udev_utils.h"
47 #include "udevd.h"
48 #include "logging.h"
49
50 /* global variables*/
51 static int udevsendsock;
52 static pid_t sid;
53
54 static int pipefds[2];
55 static long startup_time;
56 static unsigned long long expected_seqnum = 0;
57 static volatile int sigchilds_waiting;
58 static volatile int run_msg_q;
59 static volatile int sig_flag;
60 static int run_exec_q;
61
62 static LIST_HEAD(msg_list);
63 static LIST_HEAD(exec_list);
64 static LIST_HEAD(running_list);
65
66 static void exec_queue_manager(void);
67 static void msg_queue_manager(void);
68 static void user_sighandler(void);
69 static void reap_sigchilds(void);
70 char *udev_bin;
71
72 #ifdef USE_LOG
73 void log_message (int level, const char *format, ...)
74 {
75         va_list args;
76
77         va_start(args, format);
78         vsyslog(level, format, args);
79         va_end(args);
80 }
81 #endif
82
83 #define msg_dump(msg) \
84         dbg("msg_dump: sequence %llu, '%s', '%s', '%s'", \
85         msg->seqnum, msg->action, msg->devpath, msg->subsystem);
86
87 static void msg_dump_queue(void)
88 {
89 #ifdef DEBUG
90         struct hotplug_msg *msg;
91
92         list_for_each_entry(msg, &msg_list, node)
93                 dbg("sequence %llu in queue", msg->seqnum);
94 #endif
95 }
96
97 static void run_queue_delete(struct hotplug_msg *msg)
98 {
99         list_del(&msg->node);
100         free(msg);
101 }
102
103 /* orders the message in the queue by sequence number */
104 static void msg_queue_insert(struct hotplug_msg *msg)
105 {
106         struct hotplug_msg *loop_msg;
107         struct sysinfo info;
108
109         if (msg->seqnum == 0) {
110                 dbg("no SEQNUM, move straight to the exec queue");
111                 list_add(&msg->node, &exec_list);
112                 run_exec_q = 1;
113                 return;
114         }
115
116         /* sort message by sequence number into list */
117         list_for_each_entry_reverse(loop_msg, &msg_list, node) {
118                 if (loop_msg->seqnum < msg->seqnum)
119                         break;
120
121                 if (loop_msg->seqnum == msg->seqnum) {
122                         dbg("ignoring duplicate message seq %llu", msg->seqnum);
123                         return;
124                 }
125         }
126
127         /* store timestamp of queuing */
128         sysinfo(&info);
129         msg->queue_time = info.uptime;
130
131         list_add(&msg->node, &loop_msg->node);
132         dbg("queued message seq %llu", msg->seqnum);
133
134         /* run msg queue manager */
135         run_msg_q = 1;
136
137         return;
138 }
139
140 /* forks event and removes event from run queue when finished */
141 static void udev_run(struct hotplug_msg *msg)
142 {
143         char *const argv[] = { "udev", msg->subsystem, NULL };
144         pid_t pid;
145
146         pid = fork();
147         switch (pid) {
148         case 0:
149                 /* child */
150                 close(udevsendsock);
151                 logging_close();
152
153                 setpriority(PRIO_PROCESS, 0, UDEV_PRIORITY);
154                 execve(udev_bin, argv, msg->envp);
155                 dbg("exec of child failed");
156                 _exit(1);
157                 break;
158         case -1:
159                 dbg("fork of child failed");
160                 run_queue_delete(msg);
161                 break;
162         default:
163                 /* get SIGCHLD in main loop */
164                 dbg("==> exec seq %llu [%d] working at '%s'", msg->seqnum, pid, msg->devpath);
165                 msg->pid = pid;
166         }
167 }
168
169 static int running_processes(void)
170 {
171         int f;
172         static char buf[4096];
173         int len;
174         int running;
175         const char *pos;
176
177         f = open("/proc/stat", O_RDONLY);
178         if (f == -1)
179                 return -1;
180
181         len = read(f, buf, sizeof(buf));
182         close(f);
183
184         if (len <= 0)
185                 return -1;
186         else
187                 buf[len] = '\0';
188
189         pos = strstr(buf, "procs_running ");
190         if (pos == NULL)
191                 return -1;
192
193         if (sscanf(pos, "procs_running %u", &running) != 1)
194                 return -1;
195
196         return running;
197 }
198
199 /* return the number of process es in our session, count only until limit */
200 static int running_processes_in_session(pid_t session, int limit)
201 {
202         DIR *dir;
203         struct dirent *dent;
204         int running = 0;
205
206         dir = opendir("/proc");
207         if (!dir)
208                 return -1;
209
210         /* read process info from /proc */
211         for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
212                 int f;
213                 char procdir[64];
214                 char line[256];
215                 const char *pos;
216                 char state;
217                 pid_t ppid, pgrp, sess;
218                 int len;
219
220                 if (!isdigit(dent->d_name[0]))
221                         continue;
222
223                 snprintf(procdir, sizeof(procdir), "/proc/%s/stat", dent->d_name);
224                 procdir[sizeof(procdir)-1] = '\0';
225
226                 f = open(procdir, O_RDONLY);
227                 if (f == -1)
228                         continue;
229
230                 len = read(f, line, sizeof(line));
231                 close(f);
232
233                 if (len <= 0)
234                         continue;
235                 else
236                         line[len] = '\0';
237
238                 /* skip ugly program name */
239                 pos = strrchr(line, ')') + 2;
240                 if (pos == NULL)
241                         continue;
242
243                 if (sscanf(pos, "%c %d %d %d ", &state, &ppid, &pgrp, &sess) != 4)
244                         continue;
245
246                 /* count only processes in our session */
247                 if (sess != session)
248                         continue;
249
250                 /* count only running, no sleeping processes */
251                 if (state != 'R')
252                         continue;
253
254                 running++;
255                 if (limit > 0 && running >= limit)
256                         break;
257         }
258         closedir(dir);
259
260         return running;
261 }
262
263 static int compare_devpath(const char *running, const char *waiting)
264 {
265         int i;
266
267         for (i = 0; i < PATH_SIZE; i++) {
268                 /* identical device event found */
269                 if (running[i] == '\0' && waiting[i] == '\0')
270                         return 1;
271
272                 /* parent device event found */
273                 if (running[i] == '\0' && waiting[i] == '/')
274                         return 2;
275
276                 /* child device event found */
277                 if (running[i] == '/' && waiting[i] == '\0')
278                         return 3;
279
280                 /* no matching event */
281                 if (running[i] != waiting[i])
282                         break;
283         }
284
285         return 0;
286 }
287
288 /* returns still running task for the same device, its parent or its physical device */
289 static struct hotplug_msg *running_with_devpath(struct hotplug_msg *msg)
290 {
291         struct hotplug_msg *loop_msg;
292
293         if (msg->devpath == NULL)
294                 return NULL;
295
296         list_for_each_entry(loop_msg, &running_list, node) {
297                 if (loop_msg->devpath == NULL)
298                         continue;
299
300                 /* return running parent/child device event */
301                 if (compare_devpath(loop_msg->devpath, msg->devpath) != 0)
302                         return loop_msg;
303
304                 /* return running physical device event */
305                 if (msg->physdevpath && msg->action && strcmp(msg->action, "add") == 0)
306                         if (compare_devpath(loop_msg->devpath, msg->physdevpath) != 0)
307                                 return loop_msg;
308         }
309
310         return NULL;
311 }
312
313 /* exec queue management routine executes the events and serializes events in the same sequence */
314 static void exec_queue_manager(void)
315 {
316         struct hotplug_msg *loop_msg;
317         struct hotplug_msg *tmp_msg;
318         struct hotplug_msg *msg;
319         int running;
320
321         running = running_processes();
322         dbg("%d processes runnning on system", running);
323         if (running < 0)
324                 running = THROTTLE_MAX_RUNNING_CHILDS;
325
326         list_for_each_entry_safe(loop_msg, tmp_msg, &exec_list, node) {
327                 /* check running processes in our session and possibly throttle */
328                 if (running >= THROTTLE_MAX_RUNNING_CHILDS) {
329                         running = running_processes_in_session(sid, THROTTLE_MAX_RUNNING_CHILDS+10);
330                         dbg("%d processes running in session", running);
331                         if (running >= THROTTLE_MAX_RUNNING_CHILDS) {
332                                 dbg("delay seq %llu, cause too many processes already running", loop_msg->seqnum);
333                                 return;
334                         }
335                 }
336
337                 msg = running_with_devpath(loop_msg);
338                 if (!msg) {
339                         /* move event to run list */
340                         list_move_tail(&loop_msg->node, &running_list);
341                         udev_run(loop_msg);
342                         running++;
343                         dbg("moved seq %llu to running list", loop_msg->seqnum);
344                 } else {
345                         dbg("delay seq %llu (%s), cause seq %llu (%s) is still running",
346                             loop_msg->seqnum, loop_msg->devpath, msg->seqnum, msg->devpath);
347                 }
348         }
349 }
350
351 static void msg_move_exec(struct hotplug_msg *msg)
352 {
353         list_move_tail(&msg->node, &exec_list);
354         run_exec_q = 1;
355         expected_seqnum = msg->seqnum+1;
356         dbg("moved seq %llu to exec, next expected is %llu",
357                 msg->seqnum, expected_seqnum);
358 }
359
360 /* msg queue management routine handles the timeouts and dispatches the events */
361 static void msg_queue_manager(void)
362 {
363         struct hotplug_msg *loop_msg;
364         struct hotplug_msg *tmp_msg;
365         struct sysinfo info;
366         long msg_age = 0;
367         static int timeout = EVENT_INIT_TIMEOUT_SEC;
368         static int init = 1;
369
370         dbg("msg queue manager, next expected is %llu", expected_seqnum);
371 recheck:
372         list_for_each_entry_safe(loop_msg, tmp_msg, &msg_list, node) {
373                 /* move event with expected sequence to the exec list */
374                 if (loop_msg->seqnum == expected_seqnum) {
375                         msg_move_exec(loop_msg);
376                         continue;
377                 }
378
379                 /* see if we are in the initialization phase and wait for the very first events */
380                 if (init && (info.uptime - startup_time >= INIT_TIME_SEC)) {
381                         init = 0;
382                         timeout = EVENT_TIMEOUT_SEC;
383                         dbg("initialization phase passed, set timeout to %i seconds", EVENT_TIMEOUT_SEC);
384                 }
385
386                 /* move event with expired timeout to the exec list */
387                 sysinfo(&info);
388                 msg_age = info.uptime - loop_msg->queue_time;
389                 dbg("seq %llu is %li seconds old", loop_msg->seqnum, msg_age);
390                 if (msg_age >= timeout) {
391                         msg_move_exec(loop_msg);
392                         goto recheck;
393                 } else {
394                         break;
395                 }
396         }
397
398         msg_dump_queue();
399
400         /* set timeout for remaining queued events */
401         if (list_empty(&msg_list) == 0) {
402                 struct itimerval itv = {{0, 0}, {timeout - msg_age, 0}};
403                 dbg("next event expires in %li seconds", timeout - msg_age);
404                 setitimer(ITIMER_REAL, &itv, NULL);
405         }
406 }
407
408 /* receive the udevsend message and do some sanity checks */
409 static struct hotplug_msg *get_udevsend_msg(void)
410 {
411         static struct udevsend_msg usend_msg;
412         struct hotplug_msg *msg;
413         int bufpos;
414         int i;
415         ssize_t size;
416         struct msghdr smsg;
417         struct cmsghdr *cmsg;
418         struct iovec iov;
419         struct ucred *cred;
420         char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
421         int envbuf_size;
422
423         memset(&usend_msg, 0x00, sizeof(struct udevsend_msg));
424         iov.iov_base = &usend_msg;
425         iov.iov_len = sizeof(struct udevsend_msg);
426
427         memset(&smsg, 0x00, sizeof(struct msghdr));
428         smsg.msg_iov = &iov;
429         smsg.msg_iovlen = 1;
430         smsg.msg_control = cred_msg;
431         smsg.msg_controllen = sizeof(cred_msg);
432
433         size = recvmsg(udevsendsock, &smsg, 0);
434         if (size <  0) {
435                 if (errno != EINTR)
436                         dbg("unable to receive udevsend message");
437                 return NULL;
438         }
439         cmsg = CMSG_FIRSTHDR(&smsg);
440         cred = (struct ucred *) CMSG_DATA(cmsg);
441
442         if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
443                 dbg("no sender credentials received, message ignored");
444                 return NULL;
445         }
446
447         if (cred->uid != 0) {
448                 dbg("sender uid=%i, message ignored", cred->uid);
449                 return NULL;
450         }
451
452         if (strncmp(usend_msg.magic, UDEV_MAGIC, sizeof(UDEV_MAGIC)) != 0 ) {
453                 dbg("message magic '%s' doesn't match, ignore it", usend_msg.magic);
454                 return NULL;
455         }
456
457         envbuf_size = size - offsetof(struct udevsend_msg, envbuf);
458         dbg("envbuf_size=%i", envbuf_size);
459         msg = malloc(sizeof(struct hotplug_msg) + envbuf_size);
460         if (msg == NULL)
461                 return NULL;
462
463         memset(msg, 0x00, sizeof(struct hotplug_msg) + envbuf_size);
464
465         /* copy environment buffer and reconstruct envp */
466         memcpy(msg->envbuf, usend_msg.envbuf, envbuf_size);
467         bufpos = 0;
468         for (i = 0; (bufpos < envbuf_size) && (i < HOTPLUG_NUM_ENVP-2); i++) {
469                 int keylen;
470                 char *key;
471
472                 key = &msg->envbuf[bufpos];
473                 keylen = strlen(key);
474                 msg->envp[i] = key;
475                 bufpos += keylen + 1;
476                 dbg("add '%s' to msg.envp[%i]", msg->envp[i], i);
477
478                 /* remember some keys for further processing */
479                 if (strncmp(key, "ACTION=", 7) == 0)
480                         msg->action = &key[7];
481
482                 if (strncmp(key, "DEVPATH=", 8) == 0)
483                         msg->devpath = &key[8];
484
485                 if (strncmp(key, "SUBSYSTEM=", 10) == 0)
486                         msg->subsystem = &key[10];
487
488                 if (strncmp(key, "SEQNUM=", 7) == 0)
489                         msg->seqnum = strtoull(&key[7], NULL, 10);
490
491                 if (strncmp(key, "PHYSDEVPATH=", 12) == 0)
492                         msg->physdevpath = &key[12];
493         }
494         msg->envp[i++] = "UDEVD_EVENT=1";
495         msg->envp[i] = NULL;
496
497         return msg;
498 }
499
500 static void asmlinkage sig_handler(int signum)
501 {
502         int rc;
503
504         switch (signum) {
505                 case SIGINT:
506                 case SIGTERM:
507                         exit(20 + signum);
508                         break;
509                 case SIGALRM:
510                         /* set flag, then write to pipe if needed */
511                         run_msg_q = 1;
512                         goto do_write;
513                         break;
514                 case SIGCHLD:
515                         /* set flag, then write to pipe if needed */
516                         sigchilds_waiting = 1;
517                         goto do_write;
518                         break;
519         }
520
521 do_write:
522         /* if pipe is empty, write to pipe to force select to return
523          * immediately when it gets called
524          */
525         if (!sig_flag) {
526                 rc = write(pipefds[1],&signum,sizeof(signum));
527                 if (rc >= 0)
528                         sig_flag = 1;
529         }
530 }
531
532 static void udev_done(int pid)
533 {
534         /* find msg associated with pid and delete it */
535         struct hotplug_msg *msg;
536
537         list_for_each_entry(msg, &running_list, node) {
538                 if (msg->pid == pid) {
539                         dbg("<== exec seq %llu came back", msg->seqnum);
540                         run_queue_delete(msg);
541
542                         /* we want to run the exec queue manager since there may
543                          * be events waiting with the devpath of the one that
544                          * just finished
545                          */
546                         run_exec_q = 1;
547                         return;
548                 }
549         }
550 }
551
552 static void reap_sigchilds(void)
553 {
554         while(1) {
555                 int pid = waitpid(-1, NULL, WNOHANG);
556                 if ((pid == -1) || (pid == 0))
557                         break;
558                 udev_done(pid);
559         }
560 }
561
562 /* just read everything from the pipe and clear the flag,
563  * the flags was set in the signal handler
564  */
565 static void user_sighandler(void)
566 {
567         int sig;
568
569         while(1) {
570                 int rc = read(pipefds[0], &sig, sizeof(sig));
571                 if (rc < 0)
572                         break;
573
574                 sig_flag = 0;
575         }
576 }
577
578 static int init_udevsend_socket(void)
579 {
580         struct sockaddr_un saddr;
581         socklen_t addrlen;
582         const int feature_on = 1;
583         int retval;
584
585         memset(&saddr, 0x00, sizeof(saddr));
586         saddr.sun_family = AF_LOCAL;
587         /* use abstract namespace for socket path */
588         strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
589         addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
590
591         udevsendsock = socket(AF_LOCAL, SOCK_DGRAM, 0);
592         if (udevsendsock == -1) {
593                 dbg("error getting socket, %s", strerror(errno));
594                 return -1;
595         }
596
597         /* the bind takes care of ensuring only one copy running */
598         retval = bind(udevsendsock, (struct sockaddr *) &saddr, addrlen);
599         if (retval < 0) {
600                 dbg("bind failed, %s", strerror(errno));
601                 close(udevsendsock);
602                 return -1;
603         }
604
605         /* enable receiving of the sender credentials */
606         setsockopt(udevsendsock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
607
608         return 0;
609 }
610
611 int main(int argc, char *argv[], char *envp[])
612 {
613         struct sysinfo info;
614         int maxsockplus;
615         int retval;
616         int fd;
617         struct sigaction act;
618         fd_set readfds;
619         const char *udevd_expected_seqnum;
620
621         logging_init("udevd");
622         dbg("version %s", UDEV_VERSION);
623
624         if (getuid() != 0) {
625                 dbg("need to be root, exit");
626                 goto exit;
627         }
628
629         /* daemonize on request */
630         if (argc == 2 && strcmp(argv[1], "-d") == 0) {
631                 pid_t pid;
632
633                 pid = fork();
634                 switch (pid) {
635                 case 0:
636                         dbg("damonized fork running");
637                         break;
638                 case -1:
639                         dbg("fork of daemon failed");
640                         goto exit;
641                 default:
642                         logging_close();
643                         exit(0);
644                 }
645         }
646
647         /* become session leader */
648         sid = setsid();
649         dbg("our session is %d", sid);
650
651         /* make sure we don't lock any path */
652         chdir("/");
653         umask(umask(077) | 022);
654
655         /*set a reasonable scheduling priority for the daemon */
656         setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY);
657
658         /* Set fds to dev/null */
659         fd = open( "/dev/null", O_RDWR );
660         if (fd >= 0)  {
661                 dup2(fd, 0);
662                 dup2(fd, 1);
663                 dup2(fd, 2);
664                 if (fd > 2)
665                         close(fd);
666         } else
667                 dbg("error opening /dev/null %s", strerror(errno));
668
669         /* setup signal handler pipe */
670         retval = pipe(pipefds);
671         if (retval < 0) {
672                 dbg("error getting pipes: %s", strerror(errno));
673                 goto exit;
674         }
675
676         retval = fcntl(pipefds[0], F_SETFL, O_NONBLOCK);
677         if (retval < 0) {
678                 dbg("error fcntl on read pipe: %s", strerror(errno));
679                 goto exit;
680         }
681         retval = fcntl(pipefds[0], F_SETFD, FD_CLOEXEC);
682         if (retval < 0)
683                 dbg("error fcntl on read pipe: %s", strerror(errno));
684
685         retval = fcntl(pipefds[1], F_SETFL, O_NONBLOCK);
686         if (retval < 0) {
687                 dbg("error fcntl on write pipe: %s", strerror(errno));
688                 goto exit;
689         }
690         retval = fcntl(pipefds[1], F_SETFD, FD_CLOEXEC);
691         if (retval < 0)
692                 dbg("error fcntl on write pipe: %s", strerror(errno));
693
694         /* set signal handlers */
695         memset(&act, 0x00, sizeof(struct sigaction));
696         act.sa_handler = (void (*) (int))sig_handler;
697         sigemptyset(&act.sa_mask);
698         act.sa_flags = SA_RESTART;
699         sigaction(SIGINT, &act, NULL);
700         sigaction(SIGTERM, &act, NULL);
701         sigaction(SIGALRM, &act, NULL);
702         sigaction(SIGCHLD, &act, NULL);
703
704         if (init_udevsend_socket() < 0) {
705                 if (errno == EADDRINUSE)
706                         dbg("another udevd running, exit");
707                 else
708                         dbg("error initialising udevsend socket: %s", strerror(errno));
709
710                 goto exit;
711         }
712
713         /* possible override of udev binary, used for testing */
714         udev_bin = getenv("UDEV_BIN");
715         if (udev_bin != NULL)
716                 dbg("udev binary is set to '%s'", udev_bin);
717         else
718                 udev_bin = UDEV_BIN;
719
720         /* possible init of expected_seqnum value */
721         udevd_expected_seqnum = getenv("UDEVD_EXPECTED_SEQNUM");
722         if (udevd_expected_seqnum != NULL) {
723                 expected_seqnum = strtoull(udevd_expected_seqnum, NULL, 10);
724                 dbg("initialize expected_seqnum to %llu", expected_seqnum);
725         }
726
727         /* get current time to provide shorter timeout on startup */
728         sysinfo(&info);
729         startup_time = info.uptime;
730
731         FD_ZERO(&readfds);
732         FD_SET(udevsendsock, &readfds);
733         FD_SET(pipefds[0], &readfds);
734         maxsockplus = udevsendsock+1;
735         while (1) {
736                 struct hotplug_msg *msg;
737
738                 fd_set workreadfds = readfds;
739                 retval = select(maxsockplus, &workreadfds, NULL, NULL, NULL);
740
741                 if (retval < 0) {
742                         if (errno != EINTR)
743                                 dbg("error in select: %s", strerror(errno));
744                         continue;
745                 }
746
747                 if (FD_ISSET(udevsendsock, &workreadfds)) {
748                         msg = get_udevsend_msg();
749                         if (msg)
750                                 msg_queue_insert(msg);
751                 }
752
753                 if (FD_ISSET(pipefds[0], &workreadfds))
754                         user_sighandler();
755
756                 if (sigchilds_waiting) {
757                         sigchilds_waiting = 0;
758                         reap_sigchilds();
759                 }
760
761                 if (run_msg_q) {
762                         run_msg_q = 0;
763                         msg_queue_manager();
764                 }
765
766                 if (run_exec_q) {
767                          /* clean up running_list before calling exec_queue_manager() */
768                         if (sigchilds_waiting) {
769                                 sigchilds_waiting = 0;
770                                 reap_sigchilds();
771                         }
772
773                         run_exec_q = 0;
774                         exec_queue_manager();
775                 }
776         }
777
778 exit:
779         logging_close();
780         return 1;
781 }