PERFORCE change 88606 for review

soc-tyler soc-tyler at FreeBSD.org
Fri Dec 23 02:47:02 PST 2005


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

Change 88606 by soc-tyler at soc-tyler_launchd on 2005/12/23 10:46:02

	Merge changes, sync with perforce repo. Still locks up in some kqueue calls.

Affected files ...

.. //depot/projects/soc2005/launchd/includes/launch.h#15 edit
.. //depot/projects/soc2005/launchd/includes/launch_priv.h#5 edit
.. //depot/projects/soc2005/launchd/includes/launchd.h#12 edit
.. //depot/projects/soc2005/launchd/includes/launchd_core_logic.h#2 edit
.. //depot/projects/soc2005/launchd/includes/launchd_unix_ipc.h#2 edit
.. //depot/projects/soc2005/launchd/includes/pathnames.h#4 edit
.. //depot/projects/soc2005/launchd/init.c#13 edit
.. //depot/projects/soc2005/launchd/launchctl/launchctl.c#25 edit
.. //depot/projects/soc2005/launchd/launchd.c#27 edit
.. //depot/projects/soc2005/launchd/launchd_core_logic.c#2 edit
.. //depot/projects/soc2005/launchd/launchd_unix_ipc.c#2 edit
.. //depot/projects/soc2005/launchd/liblaunch.c#17 edit

Differences ...

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

@@ -40,12 +40,11 @@
 #define LAUNCHD_PATH "/sbin/launchd"
 #endif
 
-
-/* Keep Mac OS/Darwin specific code in for reference purposes, but don't build it */
 #if defined(__APPLE__) && defined(__MACH__)
 #define _BUILD_DARWIN_
 #endif
 
+
 #define LAUNCH_KEY_SUBMITJOB			"SubmitJob"
 #define LAUNCH_KEY_REMOVEJOB			"RemoveJob"
 #define LAUNCH_KEY_STARTJOB			"StartJob"
@@ -62,13 +61,13 @@
 #define LAUNCH_JOBKEY_TIMEOUT			"TimeOut"
 #define LAUNCH_JOBKEY_INITGROUPS		"InitGroups"
 #define LAUNCH_JOBKEY_SOCKETS			"Sockets"
-#define LAUNCH_JOBKEY_EVENTSOURCES		"EventSources"
+#define LAUNCH_JOBKEY_MACHSERVICES		"MachServices"
 #define LAUNCH_JOBKEY_INETDCOMPATIBILITY	"inetdCompatibility"
 #define LAUNCH_JOBKEY_PROGRAMARGUMENTS		"ProgramArguments"
 #define LAUNCH_JOBKEY_PROGRAM			"Program"
 #define LAUNCH_JOBKEY_ONDEMAND			"OnDemand"
-#define LAUNCH_JOBKEY_LIMITLOADTOHOSTS          "LimitLoadToHosts"
-#define LAUNCH_JOBKEY_LIMITLOADFROMHOSTS        "LimitLoadFromHosts"
+#define LAUNCH_JOBKEY_LIMITLOADTOHOSTS		"LimitLoadToHosts"
+#define LAUNCH_JOBKEY_LIMITLOADFROMHOSTS	"LimitLoadFromHosts"
 #define LAUNCH_JOBKEY_RUNATLOAD			"RunAtLoad"
 #define LAUNCH_JOBKEY_ROOTDIRECTORY		"RootDirectory"
 #define LAUNCH_JOBKEY_WORKINGDIRECTORY		"WorkingDirectory"
@@ -78,20 +77,10 @@
 #define LAUNCH_JOBKEY_PID			"PID"
 #define LAUNCH_JOBKEY_UMASK			"Umask"
 #define LAUNCH_JOBKEY_NICE			"Nice"
-
-// FreeBSD's sysctl() interface doesn't allow per-process attributes :/
-#ifdef _BUILD_DARWIN_
 #define LAUNCH_JOBKEY_LOWPRIORITYIO		"LowPriorityIO"
-#endif
-
 #define LAUNCH_JOBKEY_SESSIONCREATE		"SessionCreate"
 #define LAUNCH_JOBKEY_SOFTRESOURCELIMITS	"SoftResourceLimits"
 #define LAUNCH_JOBKEY_HARDRESOURCELIMITS	"HardResourceLimits"
-/*
- * sipc = job_get_bool(j->ldj, LAUNCH_JOBKEY_SERVICEIPC);
- * job_get_bool (j=0x0, key=0x4f <Error reading address 0x4f: Bad address>)
-    at launchd.c:687
- */
 #define LAUNCH_JOBKEY_SERVICEIPC		"ServiceIPC"
 #define LAUNCH_JOBKEY_STANDARDOUTPATH		"StandardOutPath"
 #define LAUNCH_JOBKEY_STANDARDERRORPATH		"StandardErrorPath"
@@ -101,8 +90,8 @@
 #define LAUNCH_JOBKEY_STARTINTERVAL		"StartInterval"
 #define LAUNCH_JOBKEY_STARTCALENDARINTERVAL	"StartCalendarInterval"
 #define LAUNCH_JOBKEY_BONJOURFDS		"BonjourFDs"
-#define LAUNCH_JOBKEY_LASTEXITSTATUS            "LastExitStatus"
-#define LAUNCH_JOBKEY_PID                       "PID"
+#define LAUNCH_JOBKEY_LASTEXITSTATUS		"LastExitStatus"
+#define LAUNCH_JOBKEY_PID			"PID"
 
 #define LAUNCH_JOBINETDCOMPATIBILITY_WAIT	"Wait"
 
@@ -127,6 +116,7 @@
 #define LAUNCH_JOBSOCKETKEY_BONJOUR		"Bonjour"
 #define LAUNCH_JOBSOCKETKEY_SECUREWITHKEY	"SecureSocketWithKey"
 #define LAUNCH_JOBSOCKETKEY_PATHNAME		"SockPathName"
+#define LAUNCH_JOBSOCKETKEY_PATHMODE		"SockPathMode"
 #define LAUNCH_JOBSOCKETKEY_NODENAME		"SockNodeName"
 #define LAUNCH_JOBSOCKETKEY_SERVICENAME		"SockServiceName"
 #define LAUNCH_JOBSOCKETKEY_FAMILY		"SockFamily"
@@ -144,8 +134,8 @@
 	LAUNCH_DATA_BOOL,
 	LAUNCH_DATA_STRING,
 	LAUNCH_DATA_OPAQUE,
+	LAUNCH_DATA_ERRNO,
 	LAUNCH_DATA_PROPERTY,
-	LAUNCH_DATA_ERRNO,
 } launch_data_type_t;
 
 launch_data_t		launch_data_alloc(launch_data_type_t);

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


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


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


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


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


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

@@ -35,20 +35,6 @@
  * SUCH DAMAGE.
  */
 
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1991, 1993\n\
-	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)init.c	8.1 (Berkeley) 7/15/93";
-#endif
-static const char rcsid[] =
-  "$FreeBSD: src/sbin/init/init.c,v 1.60 2005/01/11 14:34:29 delphij Exp $";
-#endif /* not lint */
-
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>

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

@@ -151,6 +151,7 @@
 	{ "stdout",	stdio_cmd,		"Redirect launchd's standard out to the given path" },
 	{ "stderr",	stdio_cmd,		"Redirect launchd's standard error to the given path" },
 	{ "shutdown",	fyi_cmd,		"Prepare for system shutdown" },
+	{ "singleuser",	fyi_cmd,		"Switch to single-user mode" },
 	{ "reloadttys",	fyi_cmd,		"Reload /etc/ttys" },
 	{ "getrusage",	getrusage_cmd,		"Get resource usage statistics from launchd" },
 	{ "log",	logupdate_cmd,		"Adjust the logging level or mask of launchd" },
@@ -268,21 +269,29 @@
 	return 0;
 }
 
+static void print_launchd_env(launch_data_t obj, const char *key, void *context)
+{
+	bool *is_csh = context;
+
+	/* XXX escape the double quotes */
+	if (*is_csh)
+		fprintf(stdout, "setenv %s \"%s\";\n", key, launch_data_get_string(obj));
+	else
+		fprintf(stdout, "%s=\"%s\"; export %s;\n", key, launch_data_get_string(obj), key);
+}
+
+static void print_key_value(launch_data_t obj, const char *key, void *context)
+{
+	const char *k = context;
+
+	if (!strcmp(key, k))
+		fprintf(stdout, "%s\n", launch_data_get_string(obj));
+}
 static int getenv_and_export_cmd(int argc, char *const argv[] __attribute__((unused)))
 {
 	launch_data_t resp, msg;
 	bool is_csh = false;
-	const char *k;
-	void print_launchd_env(launch_data_t obj, const char *key, void *context __attribute__((unused))) {
-		if (is_csh)
-			fprintf(stdout, "setenv %s %s;\n", key, launch_data_get_string(obj));
-		else
-			fprintf(stdout, "%s=%s; export %s;\n", key, launch_data_get_string(obj), key);
-	}
-	void print_key_value(launch_data_t obj, const char *key, void *context __attribute__((unused))) {
-		if (!strcmp(key, k))
-			fprintf(stdout, "%s\n", launch_data_get_string(obj));
-	}
+	char *k;
 	
 	if (!strcmp(argv[0], "export")) {
 		char *s = getenv("SHELL");
@@ -301,7 +310,10 @@
 	launch_data_free(msg);
 
 	if (resp) {
-		launch_data_dict_iterate(resp, (!strcmp(argv[0], "export")) ? print_launchd_env : print_key_value, NULL);
+		if (!strcmp(argv[0], "export"))
+			launch_data_dict_iterate(resp, print_launchd_env, &is_csh);
+		else
+			launch_data_dict_iterate(resp, print_key_value, k);
 		launch_data_free(resp);
 	} else {
 		fprintf(stderr, "launch_msg(\"" LAUNCH_KEY_GETUSERENVIRONMENT "\"): %s\n", strerror(errno));
@@ -460,7 +472,8 @@
 	}
 }
 
-static bool delay_to_second_pass(launch_data_t o) {
+static bool delay_to_second_pass(launch_data_t o)
+{
 	bool res = false;
 
 	launch_data_t socks = launch_data_dict_lookup(o, LAUNCH_JOBKEY_SOCKETS);
@@ -495,50 +508,50 @@
 #endif
 
 	if (NULL == launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LABEL)) {
-                fprintf(stderr, "%s: missing the Label key: %s\n", getprogname(), what);
-                goto out_bad;
-        }
+		fprintf(stderr, "%s: missing the Label key: %s\n", getprogname(), what);
+		goto out_bad;
+	}
 
-        if (NULL != (tmpa = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS))) {
-                c = launch_data_array_get_count(tmpa);
+	if (NULL != (tmpa = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS))) {
+		c = launch_data_array_get_count(tmpa);
 
-                for (i = 0; i < c; i++) {
-                        launch_data_t oai = launch_data_array_get_index(tmpa, i);
-                        if (!strcasecmp(ourhostname, launch_data_get_string(oai)))
-                                goto out_bad;
-                }
-        }
+		for (i = 0; i < c; i++) {
+			launch_data_t oai = launch_data_array_get_index(tmpa, i);
+			if (!strcasecmp(ourhostname, launch_data_get_string(oai)))
+				goto out_bad;
+		}
+	}
 
-        if (NULL != (tmpa = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LIMITLOADTOHOSTS))) {
-                c = launch_data_array_get_count(tmpa);
+	if (NULL != (tmpa = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LIMITLOADTOHOSTS))) {
+		c = launch_data_array_get_count(tmpa);
 
-                for (i = 0; i < c; i++) {
-                        launch_data_t oai = launch_data_array_get_index(tmpa, i);
-                        if (!strcasecmp(ourhostname, launch_data_get_string(oai)))
-                                break;
-                }
+		for (i = 0; i < c; i++) {
+			launch_data_t oai = launch_data_array_get_index(tmpa, i);
+			if (!strcasecmp(ourhostname, launch_data_get_string(oai)))
+				break;
+		}
 
-                if (i == c)
-                        goto out_bad;
-        }
+		if (i == c)
+			goto out_bad;
+	}
 
-        if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED)))
-                job_disabled = launch_data_get_bool(tmpd);
+	if ((tmpd = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_DISABLED)))
+		job_disabled = launch_data_get_bool(tmpd);
 
-        if (forceload)
-                job_disabled = false;
+	if (forceload)
+		job_disabled = false;
 
-        if (job_disabled && load)
-                goto out_bad;
+	if (job_disabled && load)
+		goto out_bad;
 
-        if (delay_to_second_pass(thejob))
-                launch_data_array_append(pass2, thejob);
-        else
-                launch_data_array_append(pass1, thejob);
+	if (delay_to_second_pass(thejob))
+		launch_data_array_append(pass2, thejob);
+	else
+		launch_data_array_append(pass1, thejob);
 
-        return;
+	return;
 out_bad:
-        launch_data_free(thejob);
+	launch_data_free(thejob);
 }
 
 static void readpath(const char *what, launch_data_t pass1, launch_data_t pass2, bool editondisk, bool load, bool forceload)
@@ -578,9 +591,16 @@
 static void distill_config_file(launch_data_t id_plist)
 {
 	struct distill_context dc = { id_plist, NULL };
-	launch_data_t tmp;
+	launch_data_t tmp, sipco = launch_data_dict_lookup(dc.base, LAUNCH_JOBKEY_SERVICEIPC);
+	bool sipc = sipco ? launch_data_get_bool(sipco) : false;
 
-	if ((tmp = launch_data_dict_lookup(id_plist, LAUNCH_JOBKEY_SOCKETS))) {
+	if ((tmp = launch_data_dict_lookup(dc.base, LAUNCH_JOBKEY_SOCKETS))) {
+		if (!sipc && !launch_data_dict_lookup(dc.base, LAUNCH_JOBKEY_INETDCOMPATIBILITY)) {
+			fprintf(stderr, "%s specified without %s == true or %s will not work as expected.\n",
+					LAUNCH_JOBKEY_SOCKETS,
+					LAUNCH_JOBKEY_SERVICEIPC,
+					LAUNCH_JOBKEY_INETDCOMPATIBILITY);
+		}
 		dc.newsockdict = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
 		launch_data_dict_iterate(tmp, sock_dict_cb, &dc);
 		launch_data_dict_insert(dc.base, dc.newsockdict, LAUNCH_JOBKEY_SOCKETS);
@@ -647,6 +667,9 @@
 		
 	if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PATHNAME))) {
 		struct sockaddr_un sun;
+		mode_t sun_mode = 0;
+		mode_t oldmask;
+		bool setm = false;
 
 		memset(&sun, 0, sizeof(sun));
 
@@ -657,15 +680,26 @@
 		if ((sfd = _fd(socket(AF_UNIX, st, 0))) == -1)
 			return;
 
+		if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_PATHMODE))) {
+			sun_mode = (mode_t)launch_data_get_integer(val);
+			setm = true;
+		}
+
 		if (passive) {                  
 			if (unlink(sun.sun_path) == -1 && errno != ENOENT) {
 				close(sfd);     
 				return;
 			}
+			oldmask = umask(S_IRWXG|S_IRWXO);
 			if (bind(sfd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
 				close(sfd);
+				umask(oldmask);
 				return;
 			}
+			umask(oldmask);
+			if (setm) {
+				chmod(sun.sun_path, sun_mode);
+			}
 			if ((st == SOCK_STREAM || st == SOCK_SEQPACKET)
 					&& listen(sfd, SOMAXCONN) == -1) {
 				close(sfd);
@@ -695,7 +729,7 @@
 		if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_NODENAME)))
 			node = launch_data_get_string(val);
 		if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_MULTICASTGROUP)))
-                        mgroup = launch_data_get_string(val);
+			mgroup = launch_data_get_string(val);
 		if ((val = launch_data_dict_lookup(tmp, LAUNCH_JOBSOCKETKEY_SERVICENAME))) {
 			if (LAUNCH_DATA_INTEGER == launch_data_get_type(val)) {
 				sprintf(servnbuf, "%lld", launch_data_get_integer(val));
@@ -740,23 +774,24 @@
 					return;
 				}
 				if (mgroup) {
-                                        if (setsockopt(sfd, SOL_SOCKET, SO_REUSEPORT, (void *)&sock_opt, sizeof(sock_opt)) == -1) {
-                                                fprintf(stderr, "setsockopt(SO_REUSEPORT): %s\n", strerror(errno));
-                                                return;
-                                        }
-                                } else {
-                                        if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt, sizeof(sock_opt)) == -1) {
-                                                fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror(errno));
-                                                return;
-                                        }
-                                }
+					if (setsockopt(sfd, SOL_SOCKET, SO_REUSEPORT, (void *)&sock_opt, sizeof(sock_opt)) == -1) {
+						fprintf(stderr, "setsockopt(SO_REUSEPORT): %s\n", strerror(errno));
+						return;
+					}
+				} else {
+					if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt, sizeof(sock_opt)) == -1) {
+						fprintf(stderr, "setsockopt(SO_REUSEADDR): %s\n", strerror(errno));
+						return;
+					}
+				}
 				if (bind(sfd, res->ai_addr, res->ai_addrlen) == -1) {
 					fprintf(stderr, "bind(): %s\n", strerror(errno));
 					return;
 				}
+
 				if (mgroup) {
-                                        do_mgroup_join(sfd, res->ai_family, res->ai_socktype, res->ai_protocol, mgroup);
-                                }
+					do_mgroup_join(sfd, res->ai_family, res->ai_socktype, res->ai_protocol, mgroup);
+				}
 				if ((res->ai_socktype == SOCK_STREAM || res->ai_socktype == SOCK_SEQPACKET)
 						&& listen(sfd, SOMAXCONN) == -1) {
 					fprintf(stderr, "listen(): %s\n", strerror(errno));
@@ -770,15 +805,15 @@
 						launch_data_dict_insert(thejob, rvs_fds, LAUNCH_JOBKEY_BONJOURFDS);
 					}
 					if (NULL == rnames) {
-					/* XXX: let's NOT do any rendezvous magic :P
+#ifdef _BUILD_DARWIN_
 						rvs_fd = do_rendezvous_magic(res, serv);
-					*/
+#endif
 						if (rvs_fd)
 							launch_data_array_append(rvs_fds, rvs_fd);
 					} else if (LAUNCH_DATA_STRING == launch_data_get_type(rnames)) {
-						/* XXX: let's NOT do any rendezvous magic :P
+#ifdef _BUILD_DARWIN_
 						rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rnames));
-						*/
+#endif
 						if (rvs_fd)
 							launch_data_array_append(rvs_fds, rvs_fd);
 					} else if (LAUNCH_DATA_ARRAY == launch_data_get_type(rnames)) {
@@ -786,10 +821,9 @@
 
 						for (rn_i = 0; rn_i < rn_ac; rn_i++) {
 							launch_data_t rn_tmp = launch_data_array_get_index(rnames, rn_i);
-							
-							/* XXX: let's NOT do any rendezvous magic :P
+#ifdef _BUILD_DARWIN_
 							rvs_fd = do_rendezvous_magic(res, launch_data_get_string(rn_tmp));
-							*/
+#endif
 							if (rvs_fd)
 								launch_data_array_append(rvs_fds, rvs_fd);
 						}
@@ -812,45 +846,51 @@
 	}
 }
 
-static void do_mgroup_join(int fd, int family, int socktype, int protocol, const char *mgroup)           {
-        struct addrinfo hints, *res0, *res;
-        struct ip_mreq mreq;                    
-        struct ipv6_mreq m6req;                                                                                  int gerr;
-                                        
-        memset(&hints, 0, sizeof(hints));
-                                                
-        hints.ai_flags |= AI_PASSIVE;           
-        hints.ai_family = family;                       
-        hints.ai_socktype = socktype;   
-        hints.ai_protocol = protocol;                                                                    
-        if ((gerr = getaddrinfo(mgroup, NULL, &hints, &res0)) != 0) {
-                fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(gerr));
-                return;                 
-        }                                       
+static void do_mgroup_join(int fd, int family, int socktype, int protocol, const char *mgroup)
+{
+	struct addrinfo hints, *res0, *res;
+	struct ip_mreq mreq;
+	struct ipv6_mreq m6req;
+	int gerr;
+
+	memset(&hints, 0, sizeof(hints));
+
+	hints.ai_flags |= AI_PASSIVE;
+	hints.ai_family = family;
+	hints.ai_socktype = socktype;
+	hints.ai_protocol = protocol;
+
+	if ((gerr = getaddrinfo(mgroup, NULL, &hints, &res0)) != 0) {
+		fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(gerr));
+		return;
+	}
+
+	for (res = res0; res; res = res->ai_next) {
+		if (AF_INET == family) {
+			memset(&mreq, 0, sizeof(mreq));
+			mreq.imr_multiaddr = ((struct sockaddr_in *)res->ai_addr)->sin_addr;
+			if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) == -1) {
+				fprintf(stderr, "setsockopt(IP_ADD_MEMBERSHIP): %s\n", strerror(errno));
+				continue;
+			}
+			break;
+		} else if (AF_INET6 == family) {
+			memset(&m6req, 0, sizeof(m6req));
+			m6req.ipv6mr_multiaddr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
+			if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &m6req, sizeof(m6req)) == -1) {
+				fprintf(stderr, "setsockopt(IPV6_JOIN_GROUP): %s\n", strerror(errno));
+				continue;
+			}
+			break;
+		} else {
+			fprintf(stderr, "unknown family during multicast group bind!\n");
+			break;
+		}
+	}
 
-        for (res = res0; res; res = res->ai_next) { 
-                if (AF_INET == family) {                                                                                         memset(&mreq, 0, sizeof(mreq));
-                        mreq.imr_multiaddr = ((struct sockaddr_in *)res->ai_addr)->sin_addr;
-                        if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) == -1) {                                  fprintf(stderr, "setsockopt(IP_ADD_MEMBERSHIP): %s\n", strerror(errno));
-                                continue;               
-                        }                                                                                                        break;
-                } else if (AF_INET6 == family) {
-                        memset(&m6req, 0, sizeof(m6req));
-                        m6req.ipv6mr_multiaddr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
-                        if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &m6req, sizeof(m6req)) == -1) {
-                                fprintf(stderr, "setsockopt(IPV6_JOIN_GROUP): %s\n", strerror(errno));
-                                continue;
-                        }               
-                        break;  
-                } else {
-                        fprintf(stderr, "unknown family during multicast group bind!\n");
-                        break;
-                }                                                                                                }
-                                
-        freeaddrinfo(res0);
+	freeaddrinfo(res0);
 }
 
-
 #ifdef _BUILD_DARWIN_
 static launch_data_t do_rendezvous_magic(const struct addrinfo *res, const char *serv)
 {
@@ -964,6 +1004,7 @@
 		double d;
 		CFNumberType cfnt = CFNumberGetType(cfr);
 		switch (cfnt) {
+		case kCFNumberSInt8Type:
 		case kCFNumberSInt16Type:
 		case kCFNumberSInt32Type:
 		case kCFNumberSInt64Type:
@@ -1007,16 +1048,16 @@
 	fprintf(where, "usage: %s <subcommand>\n", getprogname());
 
 	for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) {
-                l = strlen(cmds[i].name);
-                if (l > cmdwidth)
-                        cmdwidth = l;
-        }
+		l = strlen(cmds[i].name);
+		if (l > cmdwidth)
+			cmdwidth = l;
+	}
 
-        for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) {
-                if (cmds[i].func == exit_cmd && istty == false)
-                        continue;
-                fprintf(where, "\t%-*s\t%s\n", cmdwidth, cmds[i].name, cmds[i].desc);
-        }
+	for (i = 0; i < (sizeof cmds / sizeof cmds[0]); i++) {
+		if (cmds[i].func == exit_cmd && istty == false)
+			continue;
+		fprintf(where, "\t%-*s\t%s\n", cmdwidth, cmds[i].name, cmds[i].desc);
+	}
 
 	return 0;
 }
@@ -1166,7 +1207,7 @@
 		lmsgcmd = LAUNCH_KEY_STARTJOB;
 
 	if (0 == strcmp(argv[0], "remove"))
-                lmsgcmd = LAUNCH_KEY_REMOVEJOB;
+		lmsgcmd = LAUNCH_KEY_REMOVEJOB;
 
 	if (argc != 2) {
 		fprintf(stderr, "usage: %s %s <job label>\n", getprogname(), argv[0]);
@@ -1199,22 +1240,22 @@
 static void print_jobs(launch_data_t j __attribute__((unused)), const char *label, void *context __attribute__((unused)))
 {
 	launch_data_t pido = launch_data_dict_lookup(j, LAUNCH_JOBKEY_PID);
-        launch_data_t stato = launch_data_dict_lookup(j, LAUNCH_JOBKEY_LASTEXITSTATUS);
+	launch_data_t stato = launch_data_dict_lookup(j, LAUNCH_JOBKEY_LASTEXITSTATUS);
 
-        if (pido) {
-                fprintf(stdout, "%lld\t-\t%s\n", launch_data_get_integer(pido), label);
-        } else if (stato) {
-                int wstatus = (int)launch_data_get_integer(stato);
-                if (WIFEXITED(wstatus)) {
-                        fprintf(stdout, "-\t%d\t%s\n", WEXITSTATUS(wstatus), label);
-                } else if (WIFSIGNALED(wstatus)) {
-                        fprintf(stdout, "-\t-%d\t%s\n", WTERMSIG(wstatus), label);
-                } else {
-                        fprintf(stdout, "-\t???\t%s\n", label);
-                }
-        } else {
-                fprintf(stdout, "-\t-\t%s\n", label);
-        }
+	if (pido) {
+		fprintf(stdout, "%lld\t-\t%s\n", launch_data_get_integer(pido), label);
+	} else if (stato) {
+		int wstatus = (int)launch_data_get_integer(stato);
+		if (WIFEXITED(wstatus)) {
+			fprintf(stdout, "-\t%d\t%s\n", WEXITSTATUS(wstatus), label);
+		} else if (WIFSIGNALED(wstatus)) {
+			fprintf(stdout, "-\t-%d\t%s\n", WTERMSIG(wstatus), label);
+		} else {
+			fprintf(stdout, "-\t???\t%s\n", label);
+		}
+	} else {
+		fprintf(stdout, "-\t-\t%s\n", label);
+	}
 }
 
 static int quickstart_cmd(int argc, char *const argv[]) {
@@ -1359,8 +1400,11 @@
 		return 1;
 	}
 
-	if (!strcmp(argv[0], "shutdown"))
+	if (!strcmp(argv[0], "shutdown")) {
 		lmsgk = LAUNCH_KEY_SHUTDOWN;
+	} else if (!strcmp(argv[0], "singleuser")) {
+		lmsgk = LAUNCH_KEY_SINGLEUSER;
+	}
 
 	msg = launch_data_new_string(lmsgk);
 	resp = launch_msg(msg);
@@ -1492,6 +1536,70 @@
 	return r;
 }
 
+static const struct {
+	const char *name;
+	int lim;
+} limlookup[] = {
+	{ "cpu",	RLIMIT_CPU },
+	{ "filesize",	RLIMIT_FSIZE },
+	{ "data",	RLIMIT_DATA },
+	{ "stack",	RLIMIT_STACK },
+	{ "core",	RLIMIT_CORE },
+	{ "rss", 	RLIMIT_RSS },
+	{ "memlock",	RLIMIT_MEMLOCK },
+	{ "maxproc",	RLIMIT_NPROC },
+	{ "maxfiles",	RLIMIT_NOFILE }
+};
+
+static const size_t limlookupcnt = sizeof limlookup / sizeof limlookup[0];
+
+static ssize_t name2num(const char *n)
+{
+	size_t i;
+
+	for (i = 0; i < limlookupcnt; i++) {
+		if (!strcmp(limlookup[i].name, n)) {
+			return limlookup[i].lim;
+		}
+	}
+	return -1;
+}
+
+static const char *num2name(int n)
+{
+	size_t i;
+
+	for (i = 0; i < limlookupcnt; i++) {
+		if (limlookup[i].lim == n)
+			return limlookup[i].name;
+	}
+	return NULL;
+}
+
+static const char *lim2str(rlim_t val, char *buf)
+{
+	if (val == RLIM_INFINITY)
+		strcpy(buf, "unlimited");
+	else
+		sprintf(buf, "%lld", val);
+	return buf;
+}
+
+static bool str2lim(const char *buf, rlim_t *res)
+{
+	char *endptr;
+	*res = strtoll(buf, &endptr, 10);
+	if (!strcmp(buf, "unlimited")) {
+		*res = RLIM_INFINITY;
+		return false;
+	} else if (*endptr == '\0') {
+		 return false;
+	}
+	return true;
+}
+
+
+
 static int limit_cmd(int argc __attribute__((unused)), char *const argv[])
 {
 	char slimstr[100];
@@ -1502,57 +1610,6 @@
 	size_t i, lsz = -1, which = 0;
 	rlim_t slim = -1, hlim = -1;
 	bool badargs = false;
-	static const struct {
-		const char *name;
-		int lim;
-	} limlookup[] = {
-		{ "cpu",	RLIMIT_CPU },
-		{ "filesize",	RLIMIT_FSIZE },
-		{ "data",	RLIMIT_DATA },
-		{ "stack",	RLIMIT_STACK },
-		{ "core",	RLIMIT_CORE },
-		{ "rss", 	RLIMIT_RSS },
-		{ "memlock",	RLIMIT_MEMLOCK },
-		{ "maxproc",	RLIMIT_NPROC },
-		{ "maxfiles",	RLIMIT_NOFILE }
-	};
-
-	size_t limlookupcnt = (sizeof(limlookup) / sizeof(limlookup[0]));
-
-	bool name2num(const char *n) {
-		for (i = 0; i < limlookupcnt; i++) {
-			if (!strcmp(limlookup[i].name, n)) {
-				which = limlookup[i].lim;
-				return false;
-			}
-		}
-		return true;
-	};
-	const char *num2name(int n) {
-		for (i = 0; i < limlookupcnt; i++) {
-			if (limlookup[i].lim == n)
-				return limlookup[i].name;
-		}
-		return NULL;
-	};
-	const char *lim2str(rlim_t val, char *buf) {
-		if (val == RLIM_INFINITY)
-			strcpy(buf, "unlimited");
-		else
-			sprintf(buf, "%lld", val);
-		return buf;
-	};
-	bool str2lim(const char *buf, rlim_t *res) {
-		char *endptr;
-		*res = strtoll(buf, &endptr, 10);
-		if (!strcmp(buf, "unlimited")) {
-			*res = RLIM_INFINITY;
-			return false;
-		} else if (*endptr == '\0') {
-			 return false;
-		}
-		return true;
-	};
 
 	if (argc > 4)
 		badargs = true;
@@ -1565,7 +1622,7 @@
 	if (argc == 4 && str2lim(argv[3], &hlim))
 		badargs = true;
 
-	if (argc >= 2 && name2num(argv[1]))
+	if (argc >= 2 && -1 == (which = name2num(argv[1])))
 		badargs = true;
 
 	if (badargs) {
@@ -1588,7 +1645,7 @@
 		lsz = launch_data_get_opaque_size(resp);
 		if (argc <= 2) {
 			for (i = 0; i < (lsz / sizeof(struct rlimit)); i++) {
-				if (argc == 2 && which != i)
+				if (argc == 2 && (size_t)which != i)
 					continue;
 				fprintf(stdout, "\t%-12s%-15s%-15s\n", num2name(i),
 						lim2str(lmts[i].rlim_cur, slimstr),
@@ -1639,48 +1696,48 @@
 static int umask_cmd(int argc, char *const argv[])
 {
 	launch_data_t resp, msg;
-        bool badargs = false;
-        char *endptr;
-        long m = 0;
-        int r = 0;
+	bool badargs = false;
+	char *endptr;
+	long m = 0;
+	int r = 0;
 
-        if (argc == 2) {
-                m = strtol(argv[1], &endptr, 8);
-                if (*endptr != '\0' || m > 0777)
-                        badargs = true;
-        }
+	if (argc == 2) {
+		m = strtol(argv[1], &endptr, 8);
+		if (*endptr != '\0' || m > 0777)
+			badargs = true;
+	}
 
-        if (argc > 2 || badargs) {
-                fprintf(stderr, "usage: %s %s <mask>\n", getprogname(), argv[0]);
-                return 1;
-        }
+	if (argc > 2 || badargs) {
+		fprintf(stderr, "usage: %s %s <mask>\n", getprogname(), argv[0]);
+		return 1;
+	}
 
 
-        if (argc == 1) {
-                msg = launch_data_new_string(LAUNCH_KEY_GETUMASK);
-        } else {
-                msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
-                launch_data_dict_insert(msg, launch_data_new_integer(m), LAUNCH_KEY_SETUMASK);
-        }
-        resp = launch_msg(msg);
-        launch_data_free(msg);
+	if (argc == 1) {
+		msg = launch_data_new_string(LAUNCH_KEY_GETUMASK);
+	} else {
+		msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
+		launch_data_dict_insert(msg, launch_data_new_integer(m), LAUNCH_KEY_SETUMASK);
+	}
+	resp = launch_msg(msg);
+	launch_data_free(msg);
 
-        if (resp == NULL) {
-                fprintf(stderr, "launch_msg(): %s\n", strerror(errno));
-                return 1;
-        } else if (launch_data_get_type(resp) == LAUNCH_DATA_STRING) {
-                fprintf(stderr, "%s %s error: %s\n", getprogname(), argv[0], launch_data_get_string(resp));
-                r = 1;
-        } else if (launch_data_get_type(resp) != LAUNCH_DATA_INTEGER) {
-                fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]);
-                r = 1;
-        } else if (argc == 1) {
-                fprintf(stdout, "%o\n", (unsigned int)launch_data_get_integer(resp));
-        }
+	if (resp == NULL) {
+		fprintf(stderr, "launch_msg(): %s\n", strerror(errno));
+		return 1;
+	} else if (launch_data_get_type(resp) == LAUNCH_DATA_STRING) {
+		fprintf(stderr, "%s %s error: %s\n", getprogname(), argv[0], launch_data_get_string(resp));
+		r = 1;
+	} else if (launch_data_get_type(resp) != LAUNCH_DATA_INTEGER) {
+		fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]);
+		r = 1;
+	} else if (argc == 1) {
+		fprintf(stdout, "%o\n", (unsigned int)launch_data_get_integer(resp));
+	}
 
-        launch_data_free(resp);
+	launch_data_free(resp);
 
-        return r;
+	return r;
 }
 
 static int submit_cmd(int argc, char *const argv[])

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

@@ -302,7 +302,7 @@
 				exit(EXIT_SUCCESS);
 			} else if (re_exec_in_single_user_mode) {
 				re_exec_in_single_user_mode = false;
-				launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1);
+				launchd_assumes(execl(LAUNCHD_PATH, LAUNCHD_PATH, "-s", NULL) != -1);
 			}
 		}
 

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


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


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

@@ -106,6 +106,8 @@
 	int dfd, lfd = -1;
 	
 	_lc = calloc(1, sizeof(struct _launch_client));
+	
+	fprintf(stderr, "Entering into launch_client_init()\n");
 
 	if (!_lc)
 		return;
@@ -146,6 +148,8 @@
 
 	return;
 out_bad:
+	fprintf(stderr, "Entered out_bad withing launch_client_init()\n");
+
 	if (_lc->l)
 		launchd_close(_lc->l);
 	else if (lfd != -1)


More information about the p4-projects mailing list