Revision
23225
Author
zarzycki@apple.com
Date
2007-04-17 13:40:43 -0700 (Tue, 17 Apr 2007)

Log Message

Loginwindow is always the exception to every rule. They're playing both in the 'Aqua' and 'Background' bootstraps and confusing launchd.

Modified Paths

Diff

Modified: trunk/launchd/src/launchd_core_logic.c (23224 => 23225)


--- trunk/launchd/src/launchd_core_logic.c	2007-04-17 15:56:02 UTC (rev 23224)
+++ trunk/launchd/src/launchd_core_logic.c	2007-04-17 20:40:43 UTC (rev 23225)
@@ -263,7 +263,7 @@
 
 #define DO_RUSAGE_SUMMATION 0
 
-#define AUTO_PICK_LEGACY_MACH_LABEL (const char *)(~0)
+#define AUTO_PICK_LEGACY_LABEL (const char *)(~0)
 
 struct job_s {
 	kq_callback kqjob_callback;
@@ -863,7 +863,7 @@
 		goto out_bad;
 	}
 
-	jr = job_new(j->mgr, AUTO_PICK_LEGACY_MACH_LABEL, NULL, argv);
+	jr = job_new(j->mgr, AUTO_PICK_LEGACY_LABEL, NULL, argv);
 
 	free(argv);
 
@@ -967,7 +967,6 @@
 job_new_anonymous(jobmgr_t jm, pid_t anonpid)
 {
 	int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, anonpid };
-	char newlabel[1000];
 	struct kinfo_proc kp, ppid_kp;
 	size_t len = sizeof(kp);
 	bool shutdown_state;
@@ -983,14 +982,12 @@
 		return NULL;
 	}
 
-	snprintf(newlabel, sizeof(newlabel), "anonymous-%u.%s", anonpid, kp.kp_proc.p_comm);
-
 	/* A total hack: Normally, job_new() returns an error during shutdown, but anonymous jobs are special. */
 	if ((shutdown_state = jm->shutting_down)) {
 		jm->shutting_down = false;
 	}
 
-	if (jobmgr_assumes(jm, (jr = job_new(jm, newlabel, kp.kp_proc.p_comm, NULL)) != NULL)) {
+	if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, kp.kp_proc.p_comm, NULL)) != NULL)) {
 		total_children++;
 		jr->anonymous = true;
 		jr->p = anonpid;
@@ -1016,7 +1013,7 @@
 {
 	const char *const *argv_tmp = argv;
 	char auto_label[1000];
-	char *bn = NULL;
+	const char *bn = NULL;
 	char *co;
 	size_t minlabel_len;
 	int i, cc = 0;
@@ -1034,19 +1031,16 @@
 		return NULL;
 	}
 
-	if (label == AUTO_PICK_LEGACY_MACH_LABEL) {
-		bn = basename((char *)argv[0]);
+	if (label == AUTO_PICK_LEGACY_LABEL) {
+		bn = prog ? prog : basename((char *)argv[0]); /* prog for auto labels is kp.kp_kproc.p_comm */
 		snprintf(auto_label, sizeof(auto_label), "%s.%s", sizeof(void *) == 8 ? "0xdeadbeeffeedface" : "0xbabecafe", bn);
 		label = auto_label;
+		/* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */
+		minlabel_len = strlen(label) + MAXCOMLEN;
+	} else {
+		minlabel_len = strlen(label);
 	}
 
-	/* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */
-#define MAX_ANONYMOUS_LABEL_LEN (sizeof("anonymous-100000.") + MAXCOMLEN)
-	minlabel_len = strlen(label);
-	if (minlabel_len < MAX_ANONYMOUS_LABEL_LEN) {
-		minlabel_len = MAX_ANONYMOUS_LABEL_LEN;
-	}
-
 	j = calloc(1, sizeof(struct job_s) + minlabel_len + 1);
 
 	if (!jobmgr_assumes(jm, j != NULL)) {
@@ -1954,7 +1948,7 @@
 		if (job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1)) {
 			char newlabel[1000];
 
-			snprintf(newlabel, sizeof(newlabel), "anonymous-%u.%s", j->p, kp.kp_proc.p_comm);
+			snprintf(newlabel, sizeof(newlabel), "%p.%s", j, kp.kp_proc.p_comm);
 
 			job_log(j, LOG_DEBUG, "Program changed. Updating the label to: %s", newlabel);