Revision: 23915 http://trac.macosforge.org/projects/launchd/changeset/23915 Author: dsorresso@apple.com Date: 2009-04-30 16:34:49 -0700 (Thu, 30 Apr 2009) Log Message: ----------- Using sysctl(2) instead of IOKit to get boot args. Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-04-30 19:33:32 UTC (rev 23914) +++ trunk/launchd/src/launchctl.c 2009-04-30 23:34:49 UTC (rev 23915) @@ -178,7 +178,6 @@ static void fix_bogus_file_metadata(void); static void do_file_init(void) __attribute__((constructor)); static void setup_system_context(void); -static void tell_launchd_about_boot_args(void); static void handle_system_bootstrapper_crashes_separately(void); static void fatal_signal_handler(int sig, siginfo_t *si, void *uap); @@ -265,8 +264,7 @@ static bool rootuser_context; static bool bootstrapping_system; static bool bootstrapping_peruser; -static bool g_shutdown_debugging = false; -static bool g_booting_verbose = false; +static bool g_verbose_boot = false; static bool g_job_overrides_db_has_changed = false; static CFMutableDictionaryRef g_job_overrides_db = NULL; @@ -1889,7 +1887,7 @@ void handle_system_bootstrapper_crashes_separately(void) { - if( !g_booting_verbose ) { + if( !g_verbose_boot ) { return; } @@ -1971,7 +1969,6 @@ assumes(fwexec(rcserver_tool, NULL) != -1); } - tell_launchd_about_boot_args(); read_launchd_conf(); handle_system_bootstrapper_crashes_separately(); @@ -3080,44 +3077,6 @@ bootstrap_port = rootbs; } -static void -tell_launchd_about_boot_args(void) -{ - CFTypeRef value = NULL; - do { - io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); - if( !assumes(entry != IO_OBJECT_NULL) ) { - break; - } - - value = IORegistryEntryCreateCFProperty(entry, CFSTR("boot-args"), kCFAllocatorDefault, 0); - if( !assumes(value != NULL) ) { - break; - } - - IOObjectRelease(entry); - } while( 0 ); - - if( value ) { - /* Normally I'd just use CFStringFind(), but the compiler whines about it returning a - * struct with -Wall. - */ - CFRange range = { 0, CFStringGetLength(value) }; - CFRange found_range = { 0, 0 }; - - g_booting_verbose = CFStringFindWithOptions(value, CFSTR("-v"), range, 0, &found_range); - CFRelease(value); - - if( g_booting_verbose ) { - assumes(vproc_swap_integer(NULL, VPROC_GSK_VERBOSE_BOOT, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); - - if( g_shutdown_debugging ) { - assumes(vproc_swap_integer(NULL, VPROC_GSK_SHUTDOWN_DEBUGGING, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); - } - } - } -} - int submit_cmd(int argc, char *const argv[]) { @@ -4093,8 +4052,11 @@ if (stat("/AppleInternal", &sb) == 0 && stat("/var/db/disableAppleInternal", &sb) == -1) { do_apple_internal_magic = true; } - - if( stat("/var/db/.launchd_shutdown_debugging", &sb) == 0 ) { - g_shutdown_debugging = true; + + char bootargs[128]; + size_t len = 0; + int r = sysctlbyname("kern.bootargs", bootargs, &len, NULL, 0); + if( r == 0 && strnstr(bootargs, "-v", len) != NULL ) { + g_verbose_boot = true; } } Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2009-04-30 19:33:32 UTC (rev 23914) +++ trunk/launchd/src/launchd.c 2009-04-30 23:34:49 UTC (rev 23915) @@ -210,6 +210,14 @@ runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Using libgmalloc ***"); } + if( g_verbose_boot ) { + runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Verbose boot, will log to /dev/console. ***"); + } + + if( g_shutdown_debugging ) { + runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Shutdown debugging is enabled. ***"); + } + /* PID 1 doesn't have a flat namespace. */ g_flat_mach_namespace = false; } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-04-30 19:33:32 UTC (rev 23914) +++ trunk/launchd/src/launchd_core_logic.c 2009-04-30 23:34:49 UTC (rev 23915) @@ -3008,7 +3008,7 @@ return NULL; } #endif - + /* * The whole job removal logic needs to be consolidated. The fact that * a job can be removed from just about anywhere makes it easy to have @@ -7168,18 +7168,6 @@ case VPROC_GSK_WAITFORDEBUGGER: j->wait4debugger_oneshot = inval; break; - case VPROC_GSK_SHUTDOWN_DEBUGGING: - if( pid1_magic && j->is_bootstrapper && inval ) { - runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Shutdown debugging is enabled. ***"); - g_shutdown_debugging = inval; - } - break; - case VPROC_GSK_VERBOSE_BOOT: - if( pid1_magic && j->is_bootstrapper && inval ) { - g_verbose_boot = inval; - runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Verbose boot, will log to /dev/console. ***"); - } - break; case VPROC_GSK_PERUSER_SUSPEND: if( job_assumes(j, pid1_magic && ldc->euid == 0) ) { mach_port_t junk = MACH_PORT_NULL; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-04-30 19:33:32 UTC (rev 23914) +++ trunk/launchd/src/launchd_runtime.c 2009-04-30 23:34:49 UTC (rev 23915) @@ -1829,6 +1829,17 @@ g_log_pid1_shutdown = true; } + char bootargs[128]; + size_t len = sizeof(bootargs); + int r = pid1_magic ? sysctlbyname("kern.bootargs", bootargs, &len, NULL, 0) : -1; + if( r == 0 && strnstr(bootargs, "-v", len) != NULL ) { + g_verbose_boot = true; + } + + if( pid1_magic && g_verbose_boot && stat("/var/db/.launchd_shutdown_debugging", &sb) == 0 ) { + g_shutdown_debugging = true; + } + if( stat("/var/db/.launchd_log_strict_usage", &sb) == 0 ) { g_log_strict_usage = true; }