[dpkg] 95/187: s-s-d: Port process handling to Mac OS X

Reiner Herrmann reiner at reiner-h.de
Sun Nov 6 12:46:29 UTC 2016


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository dpkg.

commit 47f9afbd7b1351f5673bf32b6f1da484c3b8563c
Author: Guillem Jover <guillem at debian.org>
Date:   Tue Aug 23 21:45:05 2016 +0200

    s-s-d: Port process handling to Mac OS X
    
    Based-on-a-patch-by: Mo McRoberts <mo at nevali.net>
    Signed-off-by: Guillem Jover <guillem at debian.org>
---
 debian/changelog          |  2 ++
 utils/start-stop-daemon.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 82eff79..27d223c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -40,6 +40,8 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       start-stop-daemon. This affects Mac OS X.
     - On FreeBSD return STATUS_UNKNOWN instead of false in start-stop-daemon
       do_procinit().
+    - Port start-stop-daemon process handling to Mac OS X.
+      Based on a patch by Mo McRoberts <mo at nevali.net>.
   * Perl modules:
     - Obsolete Source-Version substvar in Dpkg::Substvars by emitting errors.
     - Rework keyring hooks in Dpkg::Vendor. Deprecate the keyrings hook, and
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 440d17f..ed4a502 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -41,6 +41,8 @@
 #  define OSNetBSD
 #elif defined(__DragonFly__)
 #  define OSDragonFlyBSD
+#elif defined(__APPLE__) && defined(__MACH__)
+#  define OSDarwin
 #else
 #  error Unknown architecture - cannot build start-stop-daemon
 #endif
@@ -103,6 +105,10 @@
 #include <ps.h>
 #endif
 
+#if defined(OSDarwin)
+#include <libproc.h>
+#endif
+
 #ifdef HAVE_KVM_H
 #include <kvm.h>
 #if defined(OSFreeBSD)
@@ -1385,6 +1391,21 @@ pid_is_exec(pid_t pid, const struct stat *esb)
 
 	return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
 }
+#elif defined(OSDarwin)
+static bool
+pid_is_exec(pid_t pid, const struct stat *esb)
+{
+	struct stat sb;
+	char pathname[_POSIX_PATH_MAX];
+
+	if (proc_pidpath(pid, pathname, sizeof(pathname)) < 0)
+		return false;
+
+	if (stat(pathname, &sb) != 0)
+		return false;
+
+	return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
+}
 #elif defined(OShpux)
 static bool
 pid_is_exec(pid_t pid, const struct stat *esb)
@@ -1507,6 +1528,17 @@ pid_is_child(pid_t pid, pid_t ppid)
 
 	return pi->ppid == ppid;
 }
+#elif defined(OSDarwin)
+static bool
+pid_is_child(pid_t pid, pid_t ppid)
+{
+	struct proc_bsdinfo info;
+
+	if (proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, sizeof(info)) < 0)
+		return false;
+
+	return (pid_t)info.pbi_ppid == ppid;
+}
 #elif defined(OShpux)
 static bool
 pid_is_child(pid_t pid, pid_t ppid)
@@ -1594,6 +1626,17 @@ pid_is_user(pid_t pid, uid_t uid)
 	ps = get_proc_stat(pid, PSTAT_OWNER_UID);
 	return ps && (uid_t)proc_stat_owner_uid(ps) == uid;
 }
+#elif defined(OSDarwin)
+static bool
+pid_is_user(pid_t pid, uid_t uid)
+{
+	struct proc_bsdinfo info;
+
+	if (proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, sizeof(info)) < 0)
+		return false;
+
+	return info.pbi_ruid == uid;
+}
 #elif defined(OShpux)
 static bool
 pid_is_user(pid_t pid, uid_t uid)
@@ -1716,6 +1759,17 @@ pid_is_cmd(pid_t pid, const char *name)
 		return false;
 	return (strcmp(pst.pst_ucomm, name) == 0);
 }
+#elif defined(OSDarwin)
+static bool
+pid_is_cmd(pid_t pid, const char *name)
+{
+	char pathname[_POSIX_PATH_MAX];
+
+	if (proc_pidpath(pid, pathname, sizeof(pathname)) < 0)
+		return false;
+
+	return strcmp(pathname, name) == 0;
+}
 #elif defined(OSFreeBSD)
 static bool
 pid_is_cmd(pid_t pid, const char *name)
@@ -1891,6 +1945,39 @@ do_procinit(void)
 	else
 		return STATUS_DEAD;
 }
+#elif defined(OSDarwin)
+static enum status_code
+do_procinit(void)
+{
+	pid_t *pid_buf;
+	int i, npids, pid_bufsize;
+	enum status_code prog_status = STATUS_DEAD;
+
+	npids = proc_listallpids(NULL, 0);
+	if (npids == 0)
+		return STATUS_UNKNOWN;
+
+	/* Try to avoid sudden changes in number of PIDs. */
+	npids += 4096;
+	pid_bufsize = sizeof(pid_t) * npids;
+	pid_buf = xmalloc(pid_bufsize);
+
+	npids = proc_listallpids(pid_buf, pid_bufsize);
+	if (npids == 0)
+		return STATUS_UNKNOWN;
+
+	for (i = 0; i < npids; i++) {
+		enum status_code pid_status;
+
+		pid_status = pid_check(pid_buf[i]);
+		if (pid_status < prog_status)
+			prog_status = pid_status;
+	}
+
+	free(pid_buf);
+
+	return prog_status;
+}
 #elif defined(OShpux)
 static enum status_code
 do_procinit(void)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list