diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2016-09-12 11:06:35 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2016-09-12 11:06:35 +0100 |
commit | 060515684dd2f3d471cc801920495426368b6ecf (patch) | |
tree | c9ccfdb89bfe57b8e82cb25d3acf3af0b910e3a6 /osdep-darwin.c | |
parent | c6cdab1f7946dd0d7aa3caf2befa60afb11ade25 (diff) | |
download | rtmux-060515684dd2f3d471cc801920495426368b6ecf.tar.gz rtmux-060515684dd2f3d471cc801920495426368b6ecf.tar.bz2 rtmux-060515684dd2f3d471cc801920495426368b6ecf.zip |
Apple have changed their API again, from Gregory Pakosz.
Diffstat (limited to 'osdep-darwin.c')
-rw-r--r-- | osdep-darwin.c | 30 |
1 files 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 <sys/types.h> +#include <sys/sysctl.h> +#include <Availability.h> #include <event.h> #include <libproc.h> #include <stdlib.h> @@ -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 * |