PERFORCE change 81514 for review

soc-tyler soc-tyler at FreeBSD.org
Fri Aug 5 18:44:49 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=81514

Change 81514 by soc-tyler at soc-tyler_launchd on 2005/08/05 18:44:33

	Move pathnames.h to the includes folder, add the doxygen template for 
	later, put init code on the backburner now, since it's not what's 
	causing the daemon to exit. Line 546 fails for some reason, calls 
	line 558 and doesn't allow launchd(8) to init. launchd(8) exits via 
	the switch on line 389. Damn. 

Affected files ...

.. //depot/projects/soc2005/launchd/Makefile#11 edit
.. //depot/projects/soc2005/launchd/includes/launchd.h#7 edit
.. //depot/projects/soc2005/launchd/includes/pathnames.h#1 add
.. //depot/projects/soc2005/launchd/init.c#8 edit
.. //depot/projects/soc2005/launchd/launchd.c#10 edit
.. //depot/projects/soc2005/launchd/launchd.doxy#1 add
.. //depot/projects/soc2005/launchd/liblaunch.c#3 edit
.. //depot/projects/soc2005/launchd/pathnames.h#2 delete

Differences ...

==== //depot/projects/soc2005/launchd/Makefile#11 (text+ko) ====


==== //depot/projects/soc2005/launchd/includes/launchd.h#7 (text+ko) ====

@@ -1,4 +1,31 @@
 /*
+ * $FreeBSD$
+ *
+ * Copyright (c) 2005 R. Tyler Ballance <tyler at tamu.edu> All rights reserved.
+ *
+ *	Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
  * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
@@ -20,6 +47,7 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
+
 #ifndef __LAUNCHD_H__
 #define __LAUNCHD_H__
 
@@ -38,6 +66,7 @@
 
 int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata);
 
+/* note: the following functions are defined in ./init.c */
 void init_boot(bool sflag, bool vflag, bool xflag);
 void init_pre_kevent(void);
 bool init_check_pid(pid_t);
@@ -45,6 +74,7 @@
 void clean_ttys(void);
 void catatonia(void);
 void death(void);
+/* </init.c> */
 
 #ifdef _BUILD_DARWIN_
 extern mach_port_t launchd_bootstrap_port;

==== //depot/projects/soc2005/launchd/init.c#8 (text+ko) ====

@@ -230,11 +230,15 @@
 		 */
 		if (getsecuritylevel() == 0)
 			setsecuritylevel(1);
-
+/* XXX: I'm not exactly sure what this macro call's purpose is, so I'm
+ * not going to touch it until it's time to execute launchd(8) as PID 1
+ */
+#ifndef _LAUNCHD_
 		TAILQ_FOREACH(s, &sessions, tqe) {
 			if (s->se_process == 0)
 				session_launch(s);
 		}
+#endif
 	}
 }
 
@@ -450,6 +454,10 @@
  * Bring the system up single user.
  */
 void single_user(void) {
+/* XXX: I'm not touching this until it's time to hack launchd(8) into
+ * becoming PID #1
+ */
+#ifndef _LAUNCHD_
 	pid_t pid, wpid;
 	int status;
 	sigset_t mask;
@@ -568,7 +576,7 @@
 			if (errno == EINTR)
 				continue;
 			warning("wait for single-user shell failed: %m; restarting");
-			//return (state_func_t) single_user;
+			return (state_func_t) single_user;
 		}
 		if (wpid == pid && WIFSTOPPED(status)) {
 			warning("init: shell stopped, restarting\n");
@@ -577,8 +585,8 @@
 		}
 	} while (wpid != pid && !requested_transition);
 
-	//if (requested_transition)
-		//return (state_func_t) requested_transition;
+	if (requested_transition)
+		return (state_func_t) requested_transition;
 
 	if (!WIFEXITED(status)) {
 		if (WTERMSIG(status) == SIGKILL) {
@@ -590,18 +598,21 @@
 			_exit(0);
 		} else {
 			warning("single user shell terminated, restarting");
-			//return (state_func_t) single_user;
+			return (state_func_t) single_user;
 		}
 	}
 
 	runcom_mode = FASTBOOT;
-	//return (state_func_t) runcom;
+	return (state_func_t) runcom;
+#endif
 }
 
 /*
  * Run the system startup script.
  */
 void runcom(void) {
+/* XXX: I'm not touching this until it's time to get launchd(8) to act as PID 1 */
+#ifndef _LAUNCHD_
 	pid_t pid, wpid;
 	int status;
 	char *argv[4];
@@ -641,25 +652,25 @@
 		while (waitpid(-1, (int *) 0, WNOHANG) > 0)
 			continue;
 		sleep(STALL_TIMEOUT);
-		//return (state_func_t) single_user;
+		return (state_func_t) single_user;
 	}
 
 	/*
 	 * Copied from single_user().  This is a bit paranoid.
 	 */
-	//requested_transition = 0;
+	requested_transition = 0;
 	
 	do {
 		if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1)
 			collect_child(wpid);
 		if (wpid == -1) {
-			//if (requested_transition == death)
-				//return (state_func_t) death;
+			if (requested_transition == death)
+				return (state_func_t) death;
 			if (errno == EINTR)
 				continue;
 			warning("wait for %s on %s failed: %m; going to single user mode",
 				_PATH_BSHELL, _PATH_RUNCOM);
-			//return (state_func_t) single_user;
+			return (state_func_t) single_user;
 		}
 		if (wpid == pid && WIFSTOPPED(status)) {
 			warning("init: %s on %s stopped, restarting\n",
@@ -682,16 +693,17 @@
 	if (!WIFEXITED(status)) {
 		warning("%s on %s terminated abnormally, going to single user mode",
 			_PATH_BSHELL, _PATH_RUNCOM);
-		//return (state_func_t) single_user;
+		return (state_func_t) single_user;
 	}
 
-	//if (WEXITSTATUS(status))
-		//return (state_func_t) single_user;
+	if (WEXITSTATUS(status))
+		return (state_func_t) single_user;
 
 	runcom_mode = AUTOBOOT;		/* the default */
 	/* NB: should send a message to the session logger to avoid blocking. */
 	logwtmp("~", "reboot", "");
-	//return (state_func_t) read_ttys;
+	return (state_func_t) read_ttys;
+#endif
 }
 
 /*
@@ -1057,6 +1069,8 @@
 void
 collect_child(pid_t pid)
 {
+/* XXX: Don't touch this until we want launchd(8) as PID 1 */
+#ifndef _LAUNCHD_
 	session_t *sp, *sprev, *snext;
 
 	if (! sessions)
@@ -1089,6 +1103,7 @@
 	sp->se_process = pid;
 	sp->se_started = time((time_t *) 0);
 	add_session(sp);
+#endif
 }
 
 /*
@@ -1097,6 +1112,8 @@
 void
 transition_handler(int sig)
 {
+/* XXX: Don't touch this until we want launchd(8) as PID 1 */
+#ifndef _LAUNCHD_
 
 	switch (sig) {
 	case SIGHUP:
@@ -1118,6 +1135,7 @@
 		requested_transition = 0;
 		break;
 	}
+#endif
 }
 
 /*
@@ -1126,6 +1144,8 @@
 state_func_t
 multi_user(void)
 {
+/* XXX: Don't touch this until we want launchd(8) as PID 1 */
+#ifndef _LAUNCHD_
 	pid_t pid;
 	session_t *sp;
 
@@ -1158,6 +1178,9 @@
 			collect_child(pid);
 
 	return (state_func_t) requested_transition;
+#endif
+// XXX: return NULL just to make -Wall STFU
+	return NULL; // remove later, for PID 1 work
 }
 
 /*
@@ -1333,6 +1356,8 @@
 int
 runshutdown(void)
 {
+/* XXX: Don't touch this until we want launchd(8) as PID 1 */
+#ifndef _LAUNCHD_
 	pid_t pid, wpid;
 	int status;
 	int shutdowntimeout;
@@ -1466,6 +1491,9 @@
 		warning("%s returned status %d", _PATH_RUNDOWN, status);
 
 	return status;
+#endif
+// XXX: return 0 just to make -Wall STFU
+	return 0; // remove later, for PID 1 work
 }
 
 static char *

==== //depot/projects/soc2005/launchd/launchd.c#10 (text+ko) ====

@@ -49,6 +49,7 @@
  */
 
 #ifdef _BUILD_DARWIN_
+
 #include <Security/Authorization.h>
 #include <Security/AuthorizationTags.h>
 #include <Security/AuthSession.h>
@@ -110,8 +111,17 @@
 #define LAUNCHD_REWARD_JOB_RUN_TIME 60
 #define LAUNCHD_FAILED_EXITS_THRESHOLD 10
 #define PID1LAUNCHD_CONF "/etc/launchd.conf"
+/* XXX: will we really need a local launchd.conf? */
 #define LAUNCHD_CONF ".launchd.conf"
+
+/* XXX: if _LAUNCHD_ is defined, then I'm working with the source code, so the 
+ *	the relevant launchctl(1) executable is in our current working dir. 
+ */
+#ifdef _LAUNCHD_
+#define LAUNCHCTL_PATH "./launchctl/launchctl"
+#else
 #define LAUNCHCTL_PATH "/sbin/launchctl"
+#endif
 
 #ifdef _BUILD_DARWIN_
 #define SECURITY_LIB "/System/Library/Frameworks/Security.framework/Versions/A/Security"
@@ -120,6 +130,11 @@
 
 extern char **environ;
 
+//! launchd's job callback datastruct
+/*!
+ * this structure contains all the necessary data for one of the job callbacks
+ * such as the PID, the kqueue callback (kq_callback)
+ */
 struct jobcb {
 	kq_callback kqjob_callback;
 	TAILQ_ENTRY(jobcb) tqe;
@@ -370,7 +385,7 @@
 				exit(EXIT_SUCCESS);
 			}
 		}
-
+		// XXX: error: delays gdb step-through
 		switch (kevent(mainkq, NULL, 0, &kev, 1, timeoutp)) {
 		case -1:
 			syslog(LOG_DEBUG, "kevent(): %m");
@@ -379,6 +394,7 @@
 			(*((kq_callback *)kev.udata))(kev.udata, &kev);
 			break;
 		case 0:
+		// XXX: timeoutp == 0, launchd(8) exits normally
 			if (timeoutp)
 				exit(EXIT_SUCCESS);
 			else
@@ -539,6 +555,7 @@
 				goto out_bad;
 			}
 		} else {
+			// XXX: launchd[12139]: mkdir("/var/launchd/1001"): Permission denied
 			syslog(LOG_ERR, "mkdir(\"%s\"): %m", LAUNCHD_SOCK_PREFIX);
 			goto out_bad;
 		}

==== //depot/projects/soc2005/launchd/liblaunch.c#3 (text+ko) ====

@@ -1,4 +1,31 @@
 /*
+ * $FreeBSD$
+ *
+ * Copyright (c) 2005 R. Tyler Ballance <tyler at tamu.edu> All rights reserved.
+ *
+ *	Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * 
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
  * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
@@ -20,6 +47,7 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
+ 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/fcntl.h>
@@ -35,6 +63,12 @@
 #include "launch.h"
 #include "launch_priv.h"
 
+//! the core data structure behind launchd(8)
+/*! 
+ * _launch_data is typedef'd to launch_data_t which is the versitile data
+ * structure behind the entire application, allowing for a linked list, a 
+ * string, array, etc
+ */
 struct _launch_data {
 	launch_data_type_t type;
 	union {


More information about the p4-projects mailing list