mirror of
https://github.com/tmate-io/tmate.git
synced 2025-02-17 02:41:07 +01:00
Use proc_pidinfo on Darwin for process name too, from OZAKI Kiichi.
This commit is contained in:
parent
a6fd92bd8d
commit
7360ff4496
@ -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;
|
||||
struct proc_bsdshortinfo bsdinfo;
|
||||
pid_t pgrp;
|
||||
int ret;
|
||||
|
||||
if ((mib[3] = tcgetpgrp(fd)) == -1)
|
||||
if ((pgrp = 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));
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user