[launchd-changes] [23512] branches/SULeopard/launchd/src/launchd_core_logic.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 6 18:15:20 PST 2008


Revision: 23512
          http://trac.macosforge.org/projects/launchd/changeset/23512
Author:   zarzycki at apple.com
Date:     2008-02-06 18:15:19 -0800 (Wed, 06 Feb 2008)

Log Message:
-----------
<rdar://problem/5725563> Device hung on "slide to unlock" screen

Modified Paths:
--------------
    branches/SULeopard/launchd/src/launchd_core_logic.c

Modified: branches/SULeopard/launchd/src/launchd_core_logic.c
===================================================================
--- branches/SULeopard/launchd/src/launchd_core_logic.c	2008-02-06 17:34:55 UTC (rev 23511)
+++ branches/SULeopard/launchd/src/launchd_core_logic.c	2008-02-07 02:15:19 UTC (rev 23512)
@@ -462,9 +462,11 @@
 static size_t our_strhash(const char *s) __attribute__((pure));
 static void extract_rcsid_substr(const char *i, char *o, size_t osz);
 static void do_first_per_user_launchd_hack(void);
+static size_t get_kern_max_proc(void);
 static void do_file_init(void) __attribute__((constructor));
 
 /* file local globals */
+static bool do_apple_internal_magic;
 static size_t total_children;
 static size_t total_anon_children;
 static mach_port_t the_exception_server;
@@ -2046,9 +2048,15 @@
 job_log_stray_pg(job_t j)
 {
 	int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, j->p };
-	size_t i, kp_cnt, len = 10*1024*1024;
+	size_t i, kp_cnt, len = sizeof(struct kinfo_proc) * get_kern_max_proc();
 	struct kinfo_proc *kp;
 
+#if TARGET_OS_EMBEDDED
+	if (!do_apple_internal_magic) {
+		return;
+	}
+#endif
+
 	if (!job_assumes(j, (kp = malloc(len)) != NULL)) {
 		return;
 	}
@@ -2821,10 +2829,17 @@
 job_find_and_blame_pids_with_weird_uids(job_t j)
 {
 	int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
-	size_t i, kp_cnt, len = 10*1024*1024;
-	struct kinfo_proc *kp = malloc(len);
+	size_t i, kp_cnt, len = sizeof(struct kinfo_proc) * get_kern_max_proc();
+	struct kinfo_proc *kp;
 	uid_t u = j->mach_uid;
 
+#if TARGET_OS_EMBEDDED
+	if (!do_apple_internal_magic) {
+		return;
+	}
+#endif
+	kp = malloc(len);
+
 	if (!job_assumes(j, kp != NULL)) {
 		return;
 	}
@@ -4302,9 +4317,14 @@
 jobmgr_log_stray_children(jobmgr_t jm)
 {
 	int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
-	size_t i, kp_cnt, len = 10*1024*1024;
+	size_t i, kp_cnt, len = sizeof(struct kinfo_proc) * get_kern_max_proc();
 	struct kinfo_proc *kp;
 
+#if TARGET_OS_EMBEDDED
+	if (!do_apple_internal_magic) {
+		return;
+	}
+#endif
 	if (jm->parentmgr || getpid() != 1) {
 		return;
 	}
@@ -6778,9 +6798,26 @@
 	free(w4r);
 }
 
+size_t
+get_kern_max_proc(void)
+{
+	int mib[] = { CTL_KERN, KERN_MAXPROC };
+	int max = 100;
+	size_t max_sz = sizeof(max);
+
+	launchd_assumes(sysctl(mib, 2, &max, &max_sz, NULL, 0) != -1);
+
+	return max;
+}
+
 void
 do_file_init(void)
 {
+	struct stat sb;
+
 	launchd_assert(mach_timebase_info(&tbi) == 0);
 
+	if (stat("/AppleInternal", &sb) == 0) {
+		do_apple_internal_magic = true;
+	}
 }

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


More information about the launchd-changes mailing list