Revision: 23091 http://trac.macosforge.org/projects/launchd/changeset/23091 Author: zarzycki@apple.com Date: 2007-02-20 06:01:28 -0800 (Tue, 20 Feb 2007) Log Message: ----------- More flag decoding. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-20 14:01:28 UTC (rev 23091) @@ -580,9 +580,12 @@ if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); } else if (getpid() == 1) { - jobmgr_log(jm, LOG_DEBUG, "About to call reboot(0x%x).", jm->reboot_flags); + jobmgr_log(jm, LOG_DEBUG, "About to call: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); + runtime_closelog(); jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); + runtime_closelog(); } else { + runtime_closelog(); jobmgr_log(jm, LOG_DEBUG, "About to exit."); exit(EXIT_SUCCESS); } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_runtime.c 2007-02-20 14:01:28 UTC (rev 23091) @@ -41,6 +41,7 @@ #include <sys/queue.h> #include <sys/socket.h> #include <sys/mount.h> +#include <sys/reboot.h> #include <bsm/libbsm.h> #include <malloc/malloc.h> #include <unistd.h> @@ -149,6 +150,45 @@ } const char * +reboot_flags_to_C_names(unsigned int flags) +{ +#define MAX_RB_STR "RB_ASKNAME|RB_SINGLE|RB_NOSYNC|RB_KDB|RB_HALT|RB_INITNAME|RB_DFLTROOT|RB_ALTBOOT|RB_UNIPROC|RB_SAFEBOOT|RB_UPSDELAY|0xdeadbeeffeedface" + static char flags_buf[sizeof(MAX_RB_STR)]; + char *flags_off = NULL; + + if (flags) while (flags) { + if (flags_off) { + *flags_off = '|'; + flags_off++; + *flags_off = '\0'; + } else { + flags_off = flags_buf; + } + +#define FLAGIF(f) if (flags & f) { flags_off += sprintf(flags_off, #f); flags &= ~f; } + + FLAGIF(RB_ASKNAME) + else FLAGIF(RB_SINGLE) + else FLAGIF(RB_NOSYNC) + else FLAGIF(RB_KDB) + else FLAGIF(RB_HALT) + else FLAGIF(RB_INITNAME) + else FLAGIF(RB_DFLTROOT) + else FLAGIF(RB_ALTBOOT) + else FLAGIF(RB_UNIPROC) + else FLAGIF(RB_SAFEBOOT) + else FLAGIF(RB_UPSDELAY) + else { + flags_off += sprintf(flags_off, "0x%x", flags); + flags = 0; + } + return flags_buf; + } else { + return "RB_AUTOBOOT"; + } +} + +const char * signal_to_C_name(unsigned int sig) { static char unknown[25]; @@ -214,8 +254,6 @@ flags_off = flags_buf; } -#define FLAGIF(f) if (flags & f) { flags_off += sprintf(flags_off, #f); flags &= ~f; } - FLAGIF(EV_ADD) else FLAGIF(EV_DELETE) else FLAGIF(EV_ENABLE) @@ -852,12 +890,22 @@ } } +static FILE *ourlogfile; + void runtime_openlog(const char *ident, int logopt, int facility) { openlog(ident, logopt, facility); } +void +runtime_closelog(void) +{ + if (ourlogfile) { + fflush(ourlogfile); + } +} + int runtime_setlogmask(int maskpri) { @@ -880,7 +928,6 @@ runtime_vsyslog(int priority, const char *message, va_list args) { static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; - static FILE *ourlogfile = NULL; static struct timeval shutdown_start = { 0, 0 }; struct timeval tvnow, tvd; int saved_errno = errno; @@ -940,6 +987,4 @@ strcpy(newmsg + j, "\n"); vfprintf(ourlogfile, newmsg, args); - - fflush(ourlogfile); } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_runtime.h 2007-02-20 14:01:28 UTC (rev 23091) @@ -66,10 +66,14 @@ bool runtime_get_caller_creds(struct ldcred *ldc); const char *signal_to_C_name(unsigned int sig); +const char *reboot_flags_to_C_names(unsigned int flags); + int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); void runtime_openlog(const char *ident, int logopt, int facility); +void runtime_closelog(void); + int runtime_setlogmask(int maskpri); void runtime_syslog(int priority, const char *message, ...) __attribute__((format(printf, 2, 3))); void runtime_vsyslog(int priority, const char *message, va_list args) __attribute__((format(printf, 2, 0)));