Bläddra i källkod

s-s-d: Add a generic KVM implementation for do_procinit()

This uses the traditional BSD kinfo_proc layout.
Guillem Jover 12 år sedan
förälder
incheckning
02901d4027
2 ändrade filer med 29 tillägg och 2 borttagningar
  1. 2 0
      debian/changelog
  2. 27 2
      utils/start-stop-daemon.c

+ 2 - 0
debian/changelog

@@ -54,6 +54,8 @@ dpkg (1.17.7) UNRELEASED; urgency=low
   * Improvements and portability fixes to start-stop-daemon:
     - When using the Linux procfs switch to use /proc/PID/status instead of
       /proc/PID/stat to read the process name.
+    - Add a generic KVM-based implementation to initialize the entire
+      process list.
 
   [ Updated dpkg translations ]
   * German (Sven Joachim).

+ 27 - 2
utils/start-stop-daemon.c

@@ -1521,8 +1521,33 @@ do_procinit(void)
 static enum status_code
 do_procinit(void)
 {
-	/* Nothing to do. */
-	return status_unknown;
+	kvm_t *kd;
+	int nentries, i;
+	struct kinfo_proc *kp;
+	char errbuf[_POSIX2_LINE_MAX];
+	enum status_code prog_status = status_dead;
+
+	kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
+	if (kd == NULL)
+		errx(1, "%s", errbuf);
+	kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries);
+	if (kp == NULL)
+		errx(1, "%s", kvm_geterr(kd));
+
+	for (i = 0; i < nentries; i++) {
+		enum status_code pid_status;
+		pid_t pid;
+
+		pid = kp[i].kp_proc.p_pid;
+
+		pid_status = pid_check(pid);
+		if (pid_status < prog_status)
+			prog_status = pid_status;
+	}
+
+	kvm_close(kd);
+
+	return prog_status;
 }
 #endif