diff options
-rw-r--r-- | osdep-darwin.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/osdep-darwin.c b/osdep-darwin.c index b112fa7c..23de9d52 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -17,7 +17,6 @@ */ #include <sys/types.h> -#include <sys/sysctl.h> #include <event.h> #include <libproc.h> @@ -34,26 +33,24 @@ struct event_base *osdep_event_init(void); char * osdep_get_name(int fd, unused char *tty) { - 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); + struct proc_bsdshortinfo bsdinfo; + pid_t pgrp; + int ret; - size = sizeof kp; - if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1) - return (NULL); - if (*kp.kp_proc.p_comm == '\0') + if ((pgrp = tcgetpgrp(fd)) == -1) return (NULL); - return (strdup(kp.kp_proc.p_comm)); + ret = proc_pidinfo(pgrp, PROC_PIDT_SHORTBSDINFO, 0, + &bsdinfo, sizeof bsdinfo); + if (ret == sizeof bsdinfo && *bsdinfo.pbsi_comm != '\0') + return (strdup(bsdinfo.pbsi_comm)); + return (NULL); } char * osdep_get_cwd(int fd) { - static char wd[PATH_MAX]; + static char wd[PATH_MAX]; struct proc_vnodepathinfo pathinfo; pid_t pgrp; int ret; @@ -61,8 +58,8 @@ osdep_get_cwd(int fd) if ((pgrp = tcgetpgrp(fd)) == -1) return (NULL); - ret = proc_pidinfo( - pgrp, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); + ret = proc_pidinfo(pgrp, PROC_PIDVNODEPATHINFO, 0, + &pathinfo, sizeof pathinfo); if (ret == sizeof pathinfo) { strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); return (wd); |