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

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 26 16:28:44 PDT 2007


Revision: 23235
          http://trac.macosforge.org/projects/launchd/changeset/23235
Author:   zarzycki at apple.com
Date:     2007-04-26 16:28:44 -0700 (Thu, 26 Apr 2007)

Log Message:
-----------
<rdar://problem/5044467> launchctl export does not print all variables

There are other changes included in this diff. Please note that more IPC is migrating to MIG.

Modified Paths:
--------------
    trunk/launchd/src/launchctl.c
    trunk/launchd/src/launchd_core_logic.c
    trunk/launchd/src/launchd_unix_ipc.c
    trunk/launchd/src/liblaunch.c
    trunk/launchd/src/liblaunch_private.h
    trunk/launchd/src/liblaunch_public.h
    trunk/launchd/src/libvproc_private.h

Modified: trunk/launchd/src/launchctl.c
===================================================================
--- trunk/launchd/src/launchctl.c	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/launchctl.c	2007-04-26 23:28:44 UTC (rev 23235)
@@ -402,9 +402,9 @@
 }
 
 int
-getenv_and_export_cmd(int argc, char *const argv[] __attribute__((unused)))
+getenv_and_export_cmd(int argc, char *const argv[])
 {
-	launch_data_t resp, msg;
+	launch_data_t resp;
 	bool is_csh = false;
 	char *k;
 	
@@ -420,21 +420,18 @@
 
 	k = argv[1];
 
-	msg = launch_data_new_string(LAUNCH_KEY_GETUSERENVIRONMENT);
-
-	resp = launch_msg(msg);
-	launch_data_free(msg);
-
-	if (resp) {
+	if (vproc_swap_complex(NULL, VPROC_GSK_ENVIRONMENT, NULL, &resp) == 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);
+		return 0;
 	} else {
-		fprintf(stderr, "launch_msg(\"" LAUNCH_KEY_GETUSERENVIRONMENT "\"): %s\n", strerror(errno));
+		return 1;
 	}
+
 	return 0;
 }
 
@@ -1932,7 +1929,7 @@
 }
 
 int
-list_cmd(int argc, char *const argv[])
+list_cmd(int argc, char *const argv[] __attribute__((unused)))
 {
 	launch_data_t resp, msg;
 	int r = 0;
@@ -1943,8 +1940,13 @@
 	} else if (argc == 2) {
 		msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
 		launch_data_dict_insert(msg, launch_data_new_string(argv[1]), LAUNCH_KEY_GETJOB);
+	} else if (vproc_swap_complex(NULL, VPROC_GSK_ALLJOBS, NULL, &resp) == NULL) {
+		fprintf(stdout, "PID\tStatus\tLabel\n");
+		launch_data_dict_iterate(resp, print_jobs, NULL);
+		launch_data_free(resp);
+		return 0;
 	} else {
-		msg = launch_data_new_string(LAUNCH_KEY_GETJOBS);
+		return 1;
 	}
 
 	resp = launch_msg(msg);
@@ -1954,12 +1956,7 @@
 		fprintf(stderr, "launch_msg(): %s\n", strerror(errno));
 		return 1;
 	} else if (launch_data_get_type(resp) == LAUNCH_DATA_DICTIONARY) {
-		if (argc == 1) {
-			fprintf(stdout, "PID\tStatus\tLabel\n");
-			launch_data_dict_iterate(resp, print_jobs, NULL);
-		} else {
-			print_obj(resp, NULL, NULL);
-		}
+		print_obj(resp, NULL, NULL);
 	} else {
 		fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]);
 		r = 1;
@@ -2022,10 +2019,9 @@
 int
 logupdate_cmd(int argc, char *const argv[])
 {
-	launch_data_t resp, msg;
-	int e, i, j, r = 0, m = 0;
+	int64_t inval, outval;
+	int i, j, m = 0;
 	bool badargs = false, maskmode = false, onlymode = false, levelmode = false;
-	const char *whichcmd = LAUNCH_KEY_SETLOGMASK;
 	static const struct {
 		const char *name;
 		int level;
@@ -2080,9 +2076,7 @@
 		}
 		if (j == logtblsz)
 			badargs = true;
-	} else if (argc == 1) {
-		whichcmd = LAUNCH_KEY_GETLOGMASK;
-	} else {
+	} else if (argc != 1) {
 		badargs = true;
 	}
 
@@ -2091,41 +2085,21 @@
 		return 1;
 	}
 
-	if (whichcmd == LAUNCH_KEY_SETLOGMASK) {
-		msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
-		launch_data_dict_insert(msg, launch_data_new_integer(m), whichcmd);
-	} else {
-		msg = launch_data_new_string(whichcmd);
-	}
+	inval = m;
 
-	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_ERRNO) {
-		if ((e = launch_data_get_errno(resp))) {
-			fprintf(stderr, "%s %s error: %s\n", getprogname(), argv[0], strerror(e));
-			r = 1;
-		}
-	} else if (launch_data_get_type(resp) == LAUNCH_DATA_INTEGER) {
-		if (whichcmd == LAUNCH_KEY_GETLOGMASK) {
-			m = launch_data_get_integer(resp);
+	if (vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_LOG_MASK, argc != 1 ? &inval : NULL, &outval) == NULL) {
+		if (argc == 1) {
 			for (j = 0; j < logtblsz; j++) {
-				if (m & LOG_MASK(logtbl[j].level))
+				if (outval & LOG_MASK(logtbl[j].level)) {
 					fprintf(stdout, "%s ", logtbl[j].name);
+				}
 			}
 			fprintf(stdout, "\n");
 		}
+		return 0;
 	} else {
-		fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]);
-		r = 1;
+		return 1;
 	}
-
-	launch_data_free(resp);
-
-	return r;
 }
 
 static const struct {
@@ -2292,11 +2266,10 @@
 int
 umask_cmd(int argc, char *const argv[])
 {
-	launch_data_t resp, msg;
 	bool badargs = false;
 	char *endptr;
 	long m = 0;
-	int r = 0;
+	int64_t inval, outval;
 
 	if (argc == 2) {
 		m = strtol(argv[1], &endptr, 8);
@@ -2309,32 +2282,16 @@
 		return 1;
 	}
 
+	inval = m;
 
-	if (argc == 1) {
-		msg = launch_data_new_string(LAUNCH_KEY_GETUMASK);
+	if (vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_UMASK, argc == 2 ? &inval : NULL, &outval) == NULL) {
+		if (argc == 1) {
+			fprintf(stdout, "%o\n", (unsigned int)outval);
+		}
+		return 0;
 	} 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));
 	}
-
-	launch_data_free(resp);
-
-	return r;
 }
 
 int

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/launchd_core_logic.c	2007-04-26 23:28:44 UTC (rev 23235)
@@ -4540,9 +4540,8 @@
 	const char *action;
 	launch_data_t input_obj, output_obj;
 	size_t data_offset = 0;
+	size_t packed_size;
 
-	*outvalCnt = 10 * 1024 * 1024;
-
 	if (!launchd_assumes(j != NULL)) {
 		return BOOTSTRAP_NO_MEMORY;
 	}
@@ -4561,30 +4560,45 @@
 
 	job_log(j, LOG_DEBUG, "%s key: %u", action, inkey ? inkey : outkey);
 
-	if (invalCnt && !job_assumes(j, (input_obj = launch_data_unpack((void *)inval, invalCnt, NULL, 0, &data_offset, NULL)) != NULL)) {
+	*outvalCnt = 20 * 1024 * 1024;
+	mig_allocate(outval, *outvalCnt);
+	if (!job_assumes(j, *outval != 0)) {
 		return 1;
 	}
 
+	if (invalCnt && !job_assumes(j, (input_obj = launch_data_unpack((void *)inval, invalCnt, NULL, 0, &data_offset, NULL)) != NULL)) {
+		goto out_bad;
+	}
+
 	switch (outkey) {
 	case VPROC_GSK_ENVIRONMENT:
-		mig_allocate(outval, *outvalCnt);
-		if (!job_assumes(j, *outval != 0)) {
-			return 1;
+		if (!job_assumes(j, (output_obj = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) {
+			goto out_bad;
 		}
-		if (job_assumes(j, (output_obj = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) {
-			jobmgr_export_env_from_other_jobs(j->mgr, output_obj);
-		}
+		jobmgr_export_env_from_other_jobs(j->mgr, output_obj);
 		if (!job_assumes(j, launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL) != 0)) {
-			mig_deallocate(*outval, *outvalCnt);
-			return 1;
+			goto out_bad;
 		}
+		launch_data_free(output_obj);
 		break;
+	case VPROC_GSK_ALLJOBS:
+		if (!job_assumes(j, (output_obj = job_export_all()) != NULL)) {
+			goto out_bad;
+		}
+		ipc_revoke_fds(output_obj);
+		packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL);
+		if (!job_assumes(j, packed_size != 0)) {
+			goto out_bad;
+		}
+		launch_data_free(output_obj);
+		break;
 	case 0:
+		mig_deallocate(*outval, *outvalCnt);
 		*outval = 0;
 		*outvalCnt = 0;
 		break;
 	default:
-		return 1;
+		goto out_bad;
 	}
 
 	if (invalCnt) switch (inkey) {
@@ -4594,12 +4608,18 @@
 	case 0:
 		break;
 	default:
-		return 1;
+		goto out_bad;
 	}
 
 	mig_deallocate(inval, invalCnt);
 
 	return 0;
+
+out_bad:
+	if (*outval) {
+		mig_deallocate(*outval, *outvalCnt);
+	}
+	return 1;
 }
 
 kern_return_t
@@ -4607,6 +4627,7 @@
 {
 	const char *action;
 	kern_return_t kr = 0;
+	int oldmask;
 
 	if (!launchd_assumes(j != NULL)) {
 		return BOOTSTRAP_NO_MEMORY;
@@ -4651,6 +4672,16 @@
 	case VPROC_GSK_EXIT_TIMEOUT:
 		*outval = j->exit_timeout;
 		break;
+	case VPROC_GSK_GLOBAL_LOG_MASK:
+		oldmask = runtime_setlogmask(LOG_UPTO(LOG_DEBUG));
+		*outval = oldmask;
+		runtime_setlogmask(oldmask);
+		break;
+	case VPROC_GSK_GLOBAL_UMASK:
+		oldmask = umask(0);
+		*outval = oldmask;
+		umask(oldmask);
+		break;
 	case 0:
 		*outval = 0;
 		break;
@@ -4685,6 +4716,12 @@
 			j->exit_timeout = inval;
 		}
 		break;
+	case VPROC_GSK_GLOBAL_LOG_MASK:
+		runtime_setlogmask(inval);
+		break;
+	case VPROC_GSK_GLOBAL_UMASK:
+		umask(inval);
+		break;
 	case 0:
 		break;
 	default:

Modified: trunk/launchd/src/launchd_unix_ipc.c
===================================================================
--- trunk/launchd/src/launchd_unix_ipc.c	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/launchd_unix_ipc.c	2007-04-26 23:28:44 UTC (rev 23235)
@@ -361,25 +361,6 @@
 			ipc_revoke_fds(resp);
 		} else if (!strcmp(cmd, LAUNCH_KEY_GETRESOURCELIMITS)) {
 			resp = adjust_rlimits(NULL);
-		} else if (!strcmp(cmd, LAUNCH_KEY_GETUSERENVIRONMENT)) {
-			char **tmpenviron = environ;
-			resp = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
-			for (; *tmpenviron; tmpenviron++) {
-				char envkey[1024];
-				launch_data_t s = launch_data_alloc(LAUNCH_DATA_STRING);
-				launch_data_set_string(s, strchr(*tmpenviron, '=') + 1);
-				strncpy(envkey, *tmpenviron, sizeof(envkey));
-				*(strchr(envkey, '=')) = '\0';
-				launch_data_dict_insert(resp, s, envkey);
-			}
-		} else if (!strcmp(cmd, LAUNCH_KEY_GETLOGMASK)) {
-			int oldmask = setlogmask(LOG_UPTO(LOG_DEBUG));
-			resp = launch_data_new_integer(oldmask);
-			setlogmask(oldmask);
-		} else if (!strcmp(cmd, LAUNCH_KEY_GETUMASK)) {
-			mode_t oldmask = umask(0);
-			resp = launch_data_new_integer(oldmask);
-			umask(oldmask);
 		} else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGESELF)) {
 			struct rusage rusage;
 			getrusage(RUSAGE_SELF, &rusage);
@@ -434,16 +415,6 @@
 			resp = job_export(j);
 			ipc_revoke_fds(resp);
 		}
-	} else if (!strcmp(cmd, LAUNCH_KEY_GETJOBWITHHANDLES)) {
-		if ((j = job_find(launch_data_get_string(data))) == NULL) {
-			resp = launch_data_new_errno(errno);
-		} else {
-			resp = job_export(j);
-		}
-	} else if (!strcmp(cmd, LAUNCH_KEY_SETLOGMASK)) {
-		resp = launch_data_new_integer(setlogmask(launch_data_get_integer(data)));
-	} else if (!strcmp(cmd, LAUNCH_KEY_SETUMASK)) {
-		resp = launch_data_new_integer(umask(launch_data_get_integer(data)));
 	} else if (!strcmp(cmd, LAUNCH_KEY_BATCHCONTROL)) {
 		batch_job_enable(launch_data_get_bool(data), rmc->c);
 		resp = launch_data_new_errno(0);

Modified: trunk/launchd/src/liblaunch.c
===================================================================
--- trunk/launchd/src/liblaunch.c	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/liblaunch.c	2007-04-26 23:28:44 UTC (rev 23235)
@@ -605,9 +605,7 @@
 		break;
 	case LAUNCH_DATA_FD:
 		o_in_w->fd = host2big(d->fd);
-		if (!fd_where) {
-			return 0;
-		} else if (d->fd != -1) {
+		if (fd_where && d->fd != -1) {
 			fd_where[*fd_cnt] = d->fd;
 			(*fd_cnt)++;
 		}
@@ -897,6 +895,12 @@
 {
 	launch_data_t resp = NULL;
 
+	if (d && (launch_data_get_type(d) == LAUNCH_DATA_STRING)
+			&& (strcmp(launch_data_get_string(d), LAUNCH_KEY_GETJOBS) == 0)
+			&& vproc_swap_complex(NULL, VPROC_GSK_ALLJOBS, NULL, &resp) == NULL) {
+		return resp;
+	}
+
 	pthread_once(&_lc_once, launch_client_init);
 
 	if (!_lc) {

Modified: trunk/launchd/src/liblaunch_private.h
===================================================================
--- trunk/launchd/src/liblaunch_private.h	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/liblaunch_private.h	2007-04-26 23:28:44 UTC (rev 23235)
@@ -29,17 +29,12 @@
 
 __BEGIN_DECLS
 
-#define LAUNCH_KEY_GETUSERENVIRONMENT	"GetUserEnvironment"
 #define LAUNCH_KEY_SETUSERENVIRONMENT	"SetUserEnvironment"
 #define LAUNCH_KEY_UNSETUSERENVIRONMENT	"UnsetUserEnvironment"
 #define LAUNCH_KEY_SHUTDOWN		"Shutdown"
 #define LAUNCH_KEY_SINGLEUSER		"SingleUser"
 #define LAUNCH_KEY_GETRESOURCELIMITS	"GetResourceLimits"
 #define LAUNCH_KEY_SETRESOURCELIMITS	"SetResourceLimits"
-#define LAUNCH_KEY_SETLOGMASK		"SetLogMask"
-#define LAUNCH_KEY_GETLOGMASK		"GetLogMask"
-#define LAUNCH_KEY_SETUMASK		"SetUmask"
-#define LAUNCH_KEY_GETUMASK		"GetUmask"
 #define LAUNCH_KEY_GETRUSAGESELF	"GetResourceUsageSelf"
 #define LAUNCH_KEY_GETRUSAGECHILDREN	"GetResourceUsageChildren"
 

Modified: trunk/launchd/src/liblaunch_public.h
===================================================================
--- trunk/launchd/src/liblaunch_public.h	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/liblaunch_public.h	2007-04-26 23:28:44 UTC (rev 23235)
@@ -49,7 +49,6 @@
 #define LAUNCH_KEY_STARTJOB			"StartJob"
 #define LAUNCH_KEY_STOPJOB			"StopJob"
 #define LAUNCH_KEY_GETJOB			"GetJob"
-#define LAUNCH_KEY_GETJOBWITHHANDLES		"GetJobWithHandles"
 #define LAUNCH_KEY_GETJOBS			"GetJobs"
 #define LAUNCH_KEY_CHECKIN			"CheckIn"
 

Modified: trunk/launchd/src/libvproc_private.h
===================================================================
--- trunk/launchd/src/libvproc_private.h	2007-04-25 23:40:49 UTC (rev 23234)
+++ trunk/launchd/src/libvproc_private.h	2007-04-26 23:28:44 UTC (rev 23235)
@@ -41,6 +41,9 @@
 	VPROC_GSK_IDLE_TIMEOUT,
 	VPROC_GSK_EXIT_TIMEOUT,
 	VPROC_GSK_ENVIRONMENT,
+	VPROC_GSK_ALLJOBS,
+	VPROC_GSK_GLOBAL_LOG_MASK,
+	VPROC_GSK_GLOBAL_UMASK,
 } vproc_gsk_t;
 
 vproc_err_t vproc_swap_integer(vproc_t vp, vproc_gsk_t key, int64_t *inval, int64_t *outval);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070426/1e360942/attachment.html


More information about the launchd-changes mailing list