summaryrefslogtreecommitdiffstats
path: root/osdep-darwin.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2016-09-12 11:06:35 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2016-09-12 11:06:35 +0100
commit060515684dd2f3d471cc801920495426368b6ecf (patch)
treec9ccfdb89bfe57b8e82cb25d3acf3af0b910e3a6 /osdep-darwin.c
parentc6cdab1f7946dd0d7aa3caf2befa60afb11ade25 (diff)
Apple have changed their API again, from Gregory Pakosz.
Diffstat (limited to 'osdep-darwin.c')
-rw-r--r--osdep-darwin.c30
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 *