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

source_changes at macosforge.org source_changes at macosforge.org
Fri May 1 10:47:55 PDT 2009


Revision: 23916
          http://trac.macosforge.org/projects/launchd/changeset/23916
Author:   dsorresso at apple.com
Date:     2009-05-01 10:47:54 -0700 (Fri, 01 May 2009)
Log Message:
-----------
<rdar://problem/6845376> We're still leaving zombies around when logging out

Modified Paths:
--------------
    trunk/launchd/src/launchd.c
    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	2009-04-30 23:34:49 UTC (rev 23915)
+++ trunk/launchd/src/launchd.c	2009-05-01 17:47:54 UTC (rev 23916)
@@ -164,15 +164,9 @@
 	if( pid1_magic ) {
 		if( low_level_debug ) {
 			g_console = stdout;
-		} else {
-			if( !launchd_assumes((g_console = fopen(_PATH_CONSOLE, "w")) != NULL) ) {
-				g_console = stdout;
-			} else {
-				_fd(fileno(g_console));
-			}
+		} else if( launchd_assumes((g_console = fopen(_PATH_CONSOLE, "w")) != NULL) ) {
+			_fd(fileno(g_console));
 		}
-	} else {
-		g_console = stdout;
 	}
 
 	if (NULL == getenv("PATH")) {
@@ -205,9 +199,9 @@
 	}
 
 	if( pid1_magic ) {
-		runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** launchd[1] has started up. ***");
+		runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** launchd[1] has started up. ***");
 		if( g_use_gmalloc ) {
-			runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Using libgmalloc ***");
+			runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Using libgmalloc ***");
 		}
 
 		if( g_verbose_boot ) {
@@ -215,7 +209,7 @@
 		}
 
 		if( g_shutdown_debugging ) {
-			runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Shutdown debugging is enabled. ***");
+			runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Shutdown debugging is enabled. ***");
 		}
 
 		/* PID 1 doesn't have a flat namespace. */
@@ -304,7 +298,7 @@
 	
 	switch ((p = fork())) {
 		case -1:
-			runtime_syslog(LOG_ERR | LOG_CONSOLE_FORCE, "Can't fork PID 1 copy for crash debugging: %m");
+			runtime_syslog(LOG_ERR | LOG_CONSOLE, "Can't fork PID 1 copy for crash debugging: %m");
 			return p;
 		case 0:
 			return p;
@@ -339,10 +333,14 @@
 		/* Neuter our bootstrap port so that the shell doesn't try talking to us while
 		 * we're blocked waiting on it.
 		 */
-		fflush(g_console);
+		if( g_console ) {
+			fflush(g_console);
+		}
 		task_set_bootstrap_port(mach_task_self(), MACH_PORT_NULL);
 		if( basic_fork() != 0 ) {
-			fflush(g_console);
+			if( g_console ) {
+				fflush(g_console);
+			}
 			return true;
 		}
 	} else {
@@ -435,7 +433,7 @@
 	};
 	
 	if( !launchd_assumes(setaudit_addr(&auinfo, sizeof(auinfo)) != -1) ) {
-		runtime_syslog(LOG_WARNING | LOG_CONSOLE_FORCE, "Could not set audit session: %s.", strerror(errno));
+		runtime_syslog(LOG_WARNING | LOG_CONSOLE, "Could not set audit session: %s.", strerror(errno));
 		_exit(EXIT_FAILURE);
 	}
 

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2009-04-30 23:34:49 UTC (rev 23915)
+++ trunk/launchd/src/launchd_core_logic.c	2009-05-01 17:47:54 UTC (rev 23916)
@@ -3057,7 +3057,7 @@
 	va_list ap;
 
 	va_start(ap, msg);
-	runtime_vsyslog(&attr, false, msg, ap);
+	runtime_vsyslog(&attr, msg, ap);
 	va_end(ap);
 }
 
@@ -3499,7 +3499,7 @@
 				jobmgr_assumes(root_jobmgr, runtime_close(s_no_hang_fd) != -1);
 				s_no_hang_fd = _fd(_no_hang_fd);
 			}
-		} else if( kev->ident == (uintptr_t)fileno(g_console) ) {
+		} else if( pid1_magic && g_console && kev->ident == (uintptr_t)fileno(g_console) ) {
 			int cfd = -1;
 			if( low_level_debug ) {
 				if( jobmgr_assumes(jm, (stdout = freopen(_PATH_CONSOLE, "w", stdout)) != NULL) ) {
@@ -3511,8 +3511,11 @@
 					cfd = fileno(g_console);
 				}
 			}
-			jobmgr_assumes(jm, kevent_mod((uintptr_t)cfd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1);
-			_fd(cfd);
+			
+			if( cfd != -1 ) {
+				jobmgr_assumes(jm, kevent_mod((uintptr_t)cfd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1);
+				_fd(cfd);
+			}
 		}
 		break;
 	default:
@@ -4382,12 +4385,9 @@
 void
 job_logv(job_t j, int pri, int err, const char *msg, va_list ap)
 {
-	bool log_to_console = pri & LOG_CONSOLE;
-	int _pri = pri & ~LOG_CONSOLE;
-	
 	const char *label2use = j ? j->label : "com.apple.launchd.NULL";
 	const char *mgr2use = j ? j->mgr->name : "NULL";
-	struct runtime_syslog_attr attr = { g_my_label, label2use, mgr2use, _pri, getuid(), getpid(), j ? j->p : 0 };
+	struct runtime_syslog_attr attr = { g_my_label, label2use, mgr2use, pri, getuid(), getpid(), j ? j->p : 0 };
 	char *newmsg;
 	int oldmask = 0;
 	size_t newmsgsz;
@@ -4422,7 +4422,7 @@
 		oldmask = setlogmask(LOG_UPTO(LOG_DEBUG));
 	}
 
-	runtime_vsyslog(&attr, log_to_console, newmsg, ap);
+	runtime_vsyslog(&attr, newmsg, ap);
 
 	if( j && unlikely(j->debug) ) {
 		setlogmask(oldmask);
@@ -4500,12 +4500,9 @@
 	if (jm->parentmgr) {
 		jobmgr_logv(jm->parentmgr, pri, 0, newmsg, ap);
 	} else {
-		bool log_to_console = pri & LOG_CONSOLE;
-		int _pri = pri & ~LOG_CONSOLE;
-		
-		struct runtime_syslog_attr attr = { g_my_label, g_my_label, jm->name, _pri, getuid(), getpid(), getpid() };
+		struct runtime_syslog_attr attr = { g_my_label, g_my_label, jm->name, pri, getuid(), getpid(), getpid() };
 
-		runtime_vsyslog(&attr, log_to_console, newmsg, ap);
+		runtime_vsyslog(&attr, newmsg, ap);
 	}
 }
 
@@ -5595,16 +5592,20 @@
 					if( !ji->stopped ) {
 						job_log(ji, LOG_DEBUG, "Stopping job.");
 						job_stop(ji);
-						if( !ji->clean_kill ) {
-							unkilled_cnt++;
-						}
+						unkilled_cnt++;
 					} else {
 						if( ji->clean_kill ) {
 							job_log(ji, LOG_DEBUG, "Job was clean and sent SIGKILL.");
+							if( !ji->clean_exit_timer_expired ) {
+								/* Give jobs that were clean and sent SIGKILL 1 second to exit after receipt. */
+								unkilled_cnt++;
+							} else {
+								job_log(ji, LOG_ERR, "Job was clean, killed and has not exited after 1 second. Moving on.");
+							}
 						} else {
 							job_log(ji, LOG_DEBUG, "Job was sent SIGTERM%s.", ji->sent_sigkill ? " and SIGKILL" : "");
+							unkilled_cnt += !ji->sent_sigkill;
 						}
-						unkilled_cnt += !ji->sent_sigkill;
 					}
 				} else {
 					job_log(ji, LOG_DEBUG, "Job is active: %s", active);
@@ -5960,7 +5961,9 @@
 			bootstrapper->stdoutpath = strdup(_PATH_CONSOLE);
 			bootstrapper->stderrpath = strdup(_PATH_CONSOLE);
 
-			jobmgr_assumes(jm, kevent_mod((uintptr_t)fileno(g_console), EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1);
+			if( g_console ) {
+				jobmgr_assumes(jm, kevent_mod((uintptr_t)fileno(g_console), EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1);
+			}
 		}
 	}
 

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2009-04-30 23:34:49 UTC (rev 23915)
+++ trunk/launchd/src/launchd_runtime.c	2009-05-01 17:47:54 UTC (rev 23916)
@@ -1246,14 +1246,11 @@
 void
 runtime_syslog(int pri, const char *message, ...)
 {
-	bool log_to_console = (( pri & LOG_CONSOLE ) && g_verbose_boot) || ( pri & LOG_CONSOLE_FORCE );
-	int _pri = pri & ~(LOG_CONSOLE | LOG_CONSOLE_FORCE);
-	
 	struct runtime_syslog_attr attr = {
 		g_my_label, 
 		g_my_label,
 		pid1_magic ? "System" : "Background",
-		_pri, 
+		pri, 
 		getuid(), 
 		getpid(), 
 		getpid()
@@ -1261,16 +1258,17 @@
 	va_list ap;
 
 	va_start(ap, message);
-	runtime_vsyslog(&attr, log_to_console, message, ap);
+	runtime_vsyslog(&attr, message, ap);
 
 	va_end(ap);
 }
 
 void
-runtime_vsyslog(struct runtime_syslog_attr *attr, bool echo_to_console, const char *message, va_list args)
+runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args)
 {
 	int saved_errno = errno;
 	char newmsg[10000];
+	bool echo_to_console= false;
 
 	if (attr->priority == LOG_APPLEONLY) {
 		if (do_apple_internal_logging) {
@@ -1282,6 +1280,11 @@
 		attr->priority = g_log_strict_usage ? LOG_NOTICE : LOG_DEBUG;
 	}
 
+	if( attr->priority & LOG_CONSOLE ) {
+		echo_to_console = true;
+		attr->priority &= ~LOG_CONSOLE;
+	}
+
 	if (!(LOG_MASK(attr->priority) & internal_mask_pri)) {
 		return;
 	}

Modified: trunk/launchd/src/launchd_runtime.h
===================================================================
--- trunk/launchd/src/launchd_runtime.h	2009-04-30 23:34:49 UTC (rev 23915)
+++ trunk/launchd/src/launchd_runtime.h	2009-05-01 17:47:54 UTC (rev 23916)
@@ -153,7 +153,6 @@
 #define LOG_APPLEONLY		0x4141504c /* AAPL in hex */
 #define LOG_SCOLDING		0x3030493b
 #define LOG_CONSOLE			(1 << 31)
-#define LOG_CONSOLE_FORCE	(1 << 30)
 
 struct runtime_syslog_attr {
 	const char *from_name;
@@ -168,7 +167,7 @@
 int runtime_setlogmask(int maskpri);
 void runtime_closelog(void);
 void runtime_syslog(int pri, const char *message, ...) __attribute__((format(printf, 2, 3)));
-void runtime_vsyslog(struct runtime_syslog_attr *attr, bool log_to_console, const char *message, va_list args) __attribute__((format(printf, 3, 0)));
+void runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args) __attribute__((format(printf, 2, 0)));
 void runtime_log_push(void);
 
 int64_t runtime_get_wall_time(void) __attribute__((warn_unused_result));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-changes/attachments/20090501/01eefb9a/attachment.html>


More information about the launchd-changes mailing list