-static void
-closeall(void)
-{
- int i;
-
- for (i = getdtablesize() - 1; i >= 0; i--) close(i);
-
- open("/dev/null", O_RDWR, 0);
- dup(0);
- dup(0);
-}
-
-static void
-detach(void)
-{
- signal(SIGINT, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
- setsid();
-}
-
-static void
-catch_sighup(int x)
-{
- global.reset = RESET_CONFIG;
-}
-
-static void
-catch_siginfo(int x)
-{
- global.reset = RESET_NETWORK;
-}
-
-static void
-send_reset(void)
-{
- struct module_list *mod;
-
- for (mod = Moduleq.tqh_first; mod != NULL; mod = mod->entries.tqe_next)
- {
- if (mod->reset != NULL) mod->reset();
- }
-}
-
-/*
- * perform timed activities and set next run-loop timeout
- */
-static void
-timed_events(struct timeval **run)
-{
- time_t now, delta, t;
- static struct timeval next;
-
- now = time(NULL);
-
- *run = NULL;
- next.tv_sec = 0;
- next.tv_usec = 0;
-
- if (time_start == 0)
- {
- /* startup */
- time_start = now;
- time_last = now;
- mark_last = now;
- ping_last = now;
- }
-
- /*
- * At startup, we try sending a notification once a second.
- * Once it succeeds, we set the Libc global __notify_78945668_info__ to 0
- * which lets Libc's localtime calculations use notifyd to invalidate
- * cached timezones. This prevents a deadlock in localtime.
- */
- if (__notify_78945668_info__ < 0)
- {
- if (notify_post("com.apple.system.syslogd") == NOTIFY_STATUS_OK) __notify_78945668_info__ = 0;
- else next.tv_sec = 1;
- }
-
- if (time_last > now)
- {
- /*
- * Despite Albert Einstein's assurance, time has gone backward.
- * Reset "last" times to current time.
- */
- time_last = now;
- mark_last = now;
- ping_last = now;
- }
-
- /*
- * Tickle bsd_out module to flush duplicates.
- */
- if (global.bsd_flush_time > 0)
- {
- bsd_flush_duplicates(now);
- bsd_close_idle_files(now);
- if (global.bsd_flush_time > 0)
- {
- if (next.tv_sec == 0) next.tv_sec = global.bsd_flush_time;
- else if (global.bsd_flush_time < next.tv_sec) next.tv_sec = global.bsd_flush_time;
- }
- }
-
- /*
- * Tickle asl_store to sweep file cache
- */
- if (global.asl_store_ping_time > 0)
- {
- delta = now - ping_last;
- if (delta >= global.asl_store_ping_time)
- {
- db_ping_store();
- bsd_close_idle_files(now);
- ping_last = now;
- t = global.asl_store_ping_time;
- }
- else
- {
- t = global.asl_store_ping_time - delta;
- }
-
- if (next.tv_sec == 0) next.tv_sec = t;
- else if (t < next.tv_sec) next.tv_sec = t;
- }
-
- /*
- * Send MARK
- */
- if (global.mark_time > 0)
- {
- delta = now - mark_last;
- if (delta >= global.mark_time)
- {
- asl_mark();
- mark_last = now;
- t = global.mark_time;
- }
- else
- {
- t = global.mark_time - delta;
- }
-
- if (next.tv_sec == 0) next.tv_sec = t;
- else if (t < next.tv_sec) next.tv_sec = t;
- }
-
- /*
- * set output timeout parameter if runloop needs to have a timer
- */
- if (next.tv_sec > 0) *run = &next;
-
- time_last = now;
-}
-