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

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 14 09:06:10 PDT 2007


Revision: 23333
          http://trac.macosforge.org/projects/launchd/changeset/23333
Author:   zarzycki at apple.com
Date:     2007-08-14 09:06:10 -0700 (Tue, 14 Aug 2007)

Log Message:
-----------
<rdar://problem/5321044> Bug: launchd_core_logic.c:3012 (23294):2: kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) != -1

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

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2007-08-13 23:05:27 UTC (rev 23332)
+++ trunk/launchd/src/launchd_core_logic.c	2007-08-14 16:06:10 UTC (rev 23333)
@@ -3044,22 +3044,31 @@
 		return;
 	}
 
-	if (si->fd == -1) {
-		if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) {
-			which_path = parentdir_path;
-			si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY));
+	do {
+		if (si->fd == -1) {
+			if ((si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY))) == -1) {
+				which_path = parentdir_path;
+				si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY));
+			}
 		}
-	}
 
-	if (si->fd == -1) {
-		return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", which_path);
-	}
+		if (si->fd == -1) {
+			return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", which_path);
+		}
 
-	job_log(j, LOG_DEBUG, "Watching Vnode: %d", si->fd);
-	if (!job_assumes(j, kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) != -1)) {
-		/* Extra logging for 5321044 */
-		job_log(j, LOG_ERR, "Bug (5321044): si->why == %u si->fd == %d fflags = 0x%x j == %p", si->why, si->fd, fflags, j);
-	}
+		job_log(j, LOG_DEBUG, "Watching Vnode: %d", si->fd);
+
+		if (kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) == -1) {
+			/*
+			 * The FD can be revoked between the open() and kevent().
+			 * This is similar to the inability for kevents to be
+			 * attached to short lived zombie processes after fork()
+			 * but before kevent().
+			 */
+			job_assumes(j, runtime_close(si->fd) == 0);
+			si->fd = -1;
+		}
+	} while (si->fd == -1);
 }
 
 void

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2007-08-13 23:05:27 UTC (rev 23332)
+++ trunk/launchd/src/launchd_runtime.c	2007-08-14 16:06:10 UTC (rev 23333)
@@ -720,22 +720,17 @@
 
 	r = kevent(mainkq, &kev, 1, &kev, 1, NULL);
 
-#define BUG_5321044_RESEARCH 1
-#if BUG_5321044_RESEARCH
-	if (r != 1) {
-		runtime_syslog(LOG_ERR, "Bug (5321044): kevent_mod() == %d", r);
+	if (!launchd_assumes(r == 1)) {
 		return -1;
 	}
 
 	if (launchd_assumes(kev.flags & EV_ERROR)) {
-		if ((flags & EV_ADD) && kev.data) {
-			runtime_syslog(LOG_ERR, "Bug (5321044): See next line.");
+		if ((flags & EV_ADD) && !launchd_assumes(kev.data == 0)) {
 			log_kevent_struct(LOG_ERR, &kev, 0);
 			errno = kev.data;
 			return -1;
 		}
 	}
-#endif
 
 	return r;
 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070814/14a3c5f1/attachment.html


More information about the launchd-changes mailing list