From 060515684dd2f3d471cc801920495426368b6ecf Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 12 Sep 2016 11:06:35 +0100 Subject: [PATCH] Apple have changed their API again, from Gregory Pakosz. --- osdep-darwin.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/osdep-darwin.c b/osdep-darwin.c index 40b18951..9956ab45 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -17,7 +17,9 @@ */ #include +#include +#include #include #include #include @@ -33,18 +35,34 @@ struct event_base *osdep_event_init(void); char * osdep_get_name(int fd, __unused char *tty) { - struct proc_bsdinfo bsdinfo; +#ifdef __MAC_10_7 + struct proc_bsdshortinfo bsdinfo; pid_t pgrp; int ret; if ((pgrp = tcgetpgrp(fd)) == -1) return (NULL); - ret = proc_pidinfo(pgrp, PROC_PIDTBSDINFO, 0, - &bsdinfo, sizeof bsdinfo); - if (ret == sizeof bsdinfo && *bsdinfo.pbi_comm != '\0') - return (strdup(bsdinfo.pbi_comm)); - return (NULL); + ret = proc_pidinfo(pgrp, PROC_PIDT_SHORTBSDINFO, 0, + &bsdinfo, sizeof bsdinfo); + if (ret == sizeof bsdinfo && *bsdinfo.pbsi_comm != '\0') + return (strdup(bsdinfo.pbsi_comm)); +#else + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; + size_t size; + struct kinfo_proc kp; + + if ((mib[3] = tcgetpgrp(fd)) == -1) + return (NULL); + + size = sizeof kp; + if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1) + return (NULL); + if (*kp.kp_proc.p_comm == '\0') + return (NULL); + + return (strdup(kp.kp_proc.p_comm)); +#endif } char *