Revision
23415
Author
zarzycki@apple.com
Date
2007-09-19 11:39:28 -0700 (Wed, 19 Sep 2007)

Log Message

<rdar://problem/5492240> Code audit: order of operations problem can hang shutdown

Modified Paths

Diff

Modified: trunk/launchd/src/launchd_core_logic.c (23414 => 23415)


--- trunk/launchd/src/launchd_core_logic.c	2007-09-19 17:47:36 UTC (rev 23414)
+++ trunk/launchd/src/launchd_core_logic.c	2007-09-19 18:39:28 UTC (rev 23415)
@@ -2015,7 +2015,7 @@
 		j->weird_bootstrap = false;
 	}
 
-	if (j->log_redirect_fd && (!j->wait4pipe_eof || j->mgr->shutting_down)) {
+	if (j->log_redirect_fd && !j->wait4pipe_eof) {
 		job_assumes(j, runtime_close(j->log_redirect_fd) != -1);
 		j->log_redirect_fd = 0;
 	}
@@ -3844,14 +3844,20 @@
 {
 	struct machservice *ms;
 
-	if (j->wait4pipe_eof && j->log_redirect_fd) {
-		return "Standard out/error is still valid";
-	}
-
 	if (j->p) {
 		return "PID is still valid";
 	}
 
+	if (j->mgr->shutting_down && j->log_redirect_fd) {
+		job_assumes(j, runtime_close(j->log_redirect_fd) != -1);
+		j->log_redirect_fd = 0;
+	}
+
+	if (j->log_redirect_fd) {
+		job_assumes(j, j->wait4pipe_eof);
+		return "Standard out/error is still valid";
+	}
+
 	if (j->priv_port_has_senders) {
 		return "Privileged Port still has outstanding senders";
 	}