1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <sys/types.h>
- #include <event.h>
- #include <libproc.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- char *osdep_get_name(int, char *);
- char *osdep_get_cwd(int);
- struct event_base *osdep_event_init(void);
- #define __unused __attribute__ ((__unused__))
- char *
- osdep_get_name(int fd, __unused char *tty)
- {
- struct proc_bsdinfo 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);
- }
- char *
- osdep_get_cwd(int fd)
- {
- static char wd[PATH_MAX];
- struct proc_vnodepathinfo pathinfo;
- pid_t pgrp;
- int ret;
- if ((pgrp = tcgetpgrp(fd)) == -1)
- return (NULL);
- 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);
- }
- return (NULL);
- }
- struct event_base *
- osdep_event_init(void)
- {
-
- setenv("EVENT_NOKQUEUE", "1", 1);
- setenv("EVENT_NOPOLL", "1", 1);
- return (event_init());
- }
|