[launchd-changes] [23466] trunk/launchd/src

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 12 16:16:29 PST 2007


Revision: 23466
          http://trac.macosforge.org/projects/launchd/changeset/23466
Author:   zarzycki at apple.com
Date:     2007-12-12 16:16:27 -0800 (Wed, 12 Dec 2007)

Log Message:
-----------
Misc logging updates.

Modified Paths:
--------------
    trunk/launchd/src/launchd.c
    trunk/launchd/src/launchd.h
    trunk/launchd/src/launchd_core_logic.c
    trunk/launchd/src/launchd_runtime.c
    trunk/launchd/src/launchd_runtime.h

Modified: trunk/launchd/src/launchd.c
===================================================================
--- trunk/launchd/src/launchd.c	2007-12-12 21:54:32 UTC (rev 23465)
+++ trunk/launchd/src/launchd.c	2007-12-13 00:16:27 UTC (rev 23466)
@@ -99,8 +99,7 @@
 static void *crash_addr;
 static pid_t crash_pid;
 
-static bool shutdown_in_progress = false;
-bool debug_shutdown_hangs = false;
+bool shutdown_in_progress = false;
 bool network_up = false;
 
 int
@@ -246,7 +245,6 @@
 launchd_shutdown(void)
 {
 	struct timeval tvnow;
-	struct stat sb;
 
 	if (shutdown_in_progress) {
 		return;
@@ -254,14 +252,13 @@
 
 	shutdown_in_progress = true;
 
-	if (getpid() == 1 && stat("/var/db/debugShutdownHangs", &sb) != -1) {
+	if (getpid() == 1) {
 		/*
 		 * When this changes to a more sustainable API, update this:
 		 * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown
 		 */
 		runtime_setlogmask(LOG_UPTO(LOG_DEBUG));
 		prep_shutdown_log_dir();
-		debug_shutdown_hangs = true;
 	}
 
 	if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) {

Modified: trunk/launchd/src/launchd.h
===================================================================
--- trunk/launchd/src/launchd.h	2007-12-12 21:54:32 UTC (rev 23465)
+++ trunk/launchd/src/launchd.h	2007-12-13 00:16:27 UTC (rev 23466)
@@ -31,7 +31,7 @@
 struct kevent;
 struct conncb;
 
-extern bool debug_shutdown_hangs;
+extern bool shutdown_in_progress;
 extern bool network_up;
 
 bool init_check_pid(pid_t);

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2007-12-12 21:54:32 UTC (rev 23465)
+++ trunk/launchd/src/launchd_core_logic.c	2007-12-13 00:16:27 UTC (rev 23466)
@@ -710,7 +710,7 @@
 		}
 	}
 
-	if (debug_shutdown_hangs && jm->parentmgr == NULL && getpid() == 1) {
+	if (do_apple_internal_logging() && jm->parentmgr == NULL && getpid() == 1) {
 		runtime_set_timeout(still_alive_with_check, 5);
 	}
 
@@ -4294,7 +4294,7 @@
 jobmgr_log_stray_children(jobmgr_t jm)
 {
 	int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
-	size_t i, kp_cnt, len = 10*1024*1024;
+	size_t i, kp_cnt = 0, kp_skipped = 0, len = 10*1024*1024;
 	struct kinfo_proc *kp;
 
 	if (jm->parentmgr || getpid() != 1) {
@@ -4318,6 +4318,7 @@
 		const char *n = kp[i].kp_proc.p_comm;
 
 		if (p_i == 0 || p_i == 1) {
+			kp_skipped++;
 			continue;
 		}
 
@@ -4330,6 +4331,10 @@
 	}
 
 out:
+	if (kp_cnt == kp_skipped) {
+		jobmgr_log(jm, LOG_DEBUG, "No stray processes at shutdown");
+	}
+
 	free(kp);
 }
 
@@ -4766,7 +4771,7 @@
 	int wstatus;
 	pid_t sp;
 
-	if (!debug_shutdown_hangs) {
+	if (!do_apple_internal_logging()) {
 		return;
 	}
 	
@@ -6702,7 +6707,7 @@
 do_unmounts(void)
 {
 	struct statfs buf[250];
-	int i, found, returned;
+	int r, i, found, returned;
 
 	do {
 		returned = getfsstat(buf, sizeof(buf), MNT_NOWAIT);
@@ -6720,8 +6725,11 @@
 				continue;
 			}
 
-			runtime_syslog(LOG_DEBUG, "About to unmount: %s", buf[i].f_mntonname);
-			if (launchd_assumes(unmount(buf[i].f_mntonname, 0) != -1)) {
+			r = unmount(buf[i].f_mntonname, 0);
+
+			runtime_syslog(LOG_DEBUG, "unmount(\"%s\", 0): %s", buf[i].f_mntonname, r == -1 ? strerror(errno) : "Success");
+
+			if (r != -1) {
 				found++;
 			}
 		}

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2007-12-12 21:54:32 UTC (rev 23465)
+++ trunk/launchd/src/launchd_runtime.c	2007-12-13 00:16:27 UTC (rev 23466)
@@ -1131,7 +1131,7 @@
 int
 runtime_fsync(int fd)
 {
-	if (debug_shutdown_hangs) {
+	if (do_apple_internal_logging()) {
 		return fcntl(fd, F_FULLFSYNC, NULL);
 	} else {
 		return fsync(fd);
@@ -1169,19 +1169,13 @@
 	static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER;
 	static struct timeval shutdown_start;
 	static struct timeval prev_msg;
-	static int apple_internal_logging = 1;
 	struct timeval tvnow, tvd_total, tvd_msg_delta = { 0, 0 };
-	struct stat sb;
 	int saved_errno = errno;
 	char newmsg[10000];
 	size_t i, j;
 
-	if (apple_internal_logging == 1) {
-		apple_internal_logging = stat("/AppleInternal", &sb);
-	}
-
 	if (attr->priority == LOG_APPLEONLY) {
-		if (apple_internal_logging == 0) {
+		if (do_apple_internal_logging()) {
 			attr->priority = LOG_NOTICE;
 		} else {
 			return;
@@ -1192,7 +1186,7 @@
 		goto out;
 	}
 
-	if (!(debug_shutdown_hangs && getpid() == 1)) {
+	if (getpid() != 1 || !shutdown_in_progress) {
 		vsnprintf(newmsg, sizeof(newmsg), message, args);
 		logmsg_add(attr, saved_errno, newmsg);
 		goto out;
@@ -1567,3 +1561,16 @@
 
 	launchd_mport_deallocate(mhs);
 }
+
+bool
+do_apple_internal_logging(void)
+{
+	static int apple_internal_logging = 1;
+	struct stat sb;
+
+	if (apple_internal_logging == 1) {
+		apple_internal_logging = stat("/AppleInternal", &sb);
+	}
+
+	return (apple_internal_logging == 0);
+}

Modified: trunk/launchd/src/launchd_runtime.h
===================================================================
--- trunk/launchd/src/launchd_runtime.h	2007-12-12 21:54:32 UTC (rev 23465)
+++ trunk/launchd/src/launchd_runtime.h	2007-12-13 00:16:27 UTC (rev 23466)
@@ -123,6 +123,7 @@
 const char *reboot_flags_to_C_names(unsigned int flags);
 const char *proc_flags_to_C_names(unsigned int flags);
 
+bool do_apple_internal_logging(void);
 
 int kevent_bulk_mod(struct kevent *kev, size_t kev_cnt);
 int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071212/e49f8183/attachment-0001.html


More information about the launchd-changes mailing list