summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2016-08-23 21:45:05 +0200
committerGuillem Jover <guillem@debian.org>2016-10-30 04:45:33 +0100
commit47f9afbd7b1351f5673bf32b6f1da484c3b8563c (patch)
treee36cc013bd0680c1804760d01265bc0d0a728c23 /utils
parent97af191aa67e3b6c03ba7d7fa22a88a0ec6591df (diff)
downloaddpkg-47f9afbd7b1351f5673bf32b6f1da484c3b8563c.tar.gz
s-s-d: Port process handling to Mac OS X
Based-on-a-patch-by: Mo McRoberts <mo@nevali.net> Signed-off-by: Guillem Jover <guillem@debian.org>
Diffstat (limited to 'utils')
-rw-r--r--utils/start-stop-daemon.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 440d17f0f..ed4a50245 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)