Revision
23898
Author
dsorresso@apple.com
Date
2009-04-16 15:18:10 -0700 (Thu, 16 Apr 2009)

Log Message

<rdar://problem/6787653> launchd's periodic sync() seems to be bad for shutdown time when it happens during shutdown.

Modified Paths

Diff

Modified: trunk/launchd/src/launchd.c (23897 => 23898)


--- trunk/launchd/src/launchd.c	2009-04-15 21:27:54 UTC (rev 23897)
+++ trunk/launchd/src/launchd.c	2009-04-16 22:18:10 UTC (rev 23898)
@@ -112,7 +112,6 @@
 static bool re_exec_in_single_user_mode;
 static void *crash_addr;
 static pid_t crash_pid;
-static unsigned int g_sync_frequency = 30;
 
 bool shutdown_in_progress;
 bool fake_shutdown_in_progress;
@@ -121,6 +120,7 @@
 char g_my_label[128] = "__Uninitialized__";
 char g_launchd_database_dir[PATH_MAX];
 FILE *g_console = NULL;
+int32_t g_sync_frequency = 30;
 
 int
 main(int argc, char *const *argv)
@@ -263,6 +263,7 @@
 		sleep(g_sync_frequency);
 	}
 	
+	runtime_syslog(LOG_DEBUG, "Update thread exiting.");
 	return NULL;
 }
 

Modified: trunk/launchd/src/launchd_core_logic.c (23897 => 23898)


--- trunk/launchd/src/launchd_core_logic.c	2009-04-15 21:27:54 UTC (rev 23897)
+++ trunk/launchd/src/launchd_core_logic.c	2009-04-16 22:18:10 UTC (rev 23898)
@@ -982,6 +982,10 @@
 	
 	if (jm->parentmgr == NULL && pid1_magic) {
 		jobmgr_assumes(jm, kevent_mod((uintptr_t)jm, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, 5, jm));
+	#if !TARGET_OS_EMBEDDED
+		/* Kill the update thread. */
+		jobmgr_assumes(jm, __sync_sub_and_fetch(&g_sync_frequency, 30) == 0);
+	#endif
 	}
 
 	return jobmgr_do_garbage_collection(jm);

Modified: trunk/launchd/src/launchd_runtime.h (23897 => 23898)


--- trunk/launchd/src/launchd_runtime.h	2009-04-15 21:27:54 UTC (rev 23897)
+++ trunk/launchd/src/launchd_runtime.h	2009-04-16 22:18:10 UTC (rev 23898)
@@ -108,6 +108,7 @@
 extern bool g_log_per_user_shutdown;
 extern bool g_log_strict_usage;
 extern bool g_embedded_shutdown_log;
+extern int32_t g_sync_frequency;
 extern pid_t g_wsp;
 
 mach_port_t runtime_get_kernel_port(void);