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