Use proc_pidinfo on Darwin for process name too, from OZAKI Kiichi.

pull/1/head
Nicholas Marriott 2013-02-12 09:40:22 +00:00
parent a6fd92bd8d
commit 7360ff4496
1 changed files with 12 additions and 15 deletions

View File

@ -17,7 +17,6 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h>
#include <event.h> #include <event.h>
#include <libproc.h> #include <libproc.h>
@ -34,26 +33,24 @@ struct event_base *osdep_event_init(void);
char * char *
osdep_get_name(int fd, unused char *tty) osdep_get_name(int fd, unused char *tty)
{ {
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; struct proc_bsdshortinfo bsdinfo;
size_t size; pid_t pgrp;
struct kinfo_proc kp; int ret;
if ((mib[3] = tcgetpgrp(fd)) == -1) if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL); return (NULL);
size = sizeof kp; ret = proc_pidinfo(pgrp, PROC_PIDT_SHORTBSDINFO, 0,
if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1) &bsdinfo, sizeof bsdinfo);
return (NULL); if (ret == sizeof bsdinfo && *bsdinfo.pbsi_comm != '\0')
if (*kp.kp_proc.p_comm == '\0') return (strdup(bsdinfo.pbsi_comm));
return (NULL); return (NULL);
return (strdup(kp.kp_proc.p_comm));
} }
char * char *
osdep_get_cwd(int fd) osdep_get_cwd(int fd)
{ {
static char wd[PATH_MAX]; static char wd[PATH_MAX];
struct proc_vnodepathinfo pathinfo; struct proc_vnodepathinfo pathinfo;
pid_t pgrp; pid_t pgrp;
int ret; int ret;
@ -61,8 +58,8 @@ osdep_get_cwd(int fd)
if ((pgrp = tcgetpgrp(fd)) == -1) if ((pgrp = tcgetpgrp(fd)) == -1)
return (NULL); return (NULL);
ret = proc_pidinfo( ret = proc_pidinfo(pgrp, PROC_PIDVNODEPATHINFO, 0,
pgrp, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); &pathinfo, sizeof pathinfo);
if (ret == sizeof pathinfo) { if (ret == sizeof pathinfo) {
strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd);
return (wd); return (wd);