2011-07-09 09:42:33 +00:00
|
|
|
/* $Id$ */
|
2009-01-20 22:17:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2010-12-30 20:41:08 +00:00
|
|
|
#include <event.h>
|
2012-01-27 09:01:06 +00:00
|
|
|
#include <libproc.h>
|
2009-01-20 22:17:53 +00:00
|
|
|
#include <stdlib.h>
|
2009-02-07 19:41:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-01-20 22:17:53 +00:00
|
|
|
|
2010-12-30 20:41:08 +00:00
|
|
|
char *osdep_get_name(int, char *);
|
2012-09-24 13:05:38 +00:00
|
|
|
char *osdep_get_cwd(int);
|
2010-12-30 20:41:08 +00:00
|
|
|
struct event_base *osdep_event_init(void);
|
2009-02-09 18:08:01 +00:00
|
|
|
|
|
|
|
#define unused __attribute__ ((unused))
|
2009-01-20 22:17:53 +00:00
|
|
|
|
2009-02-13 00:43:04 +00:00
|
|
|
char *
|
|
|
|
osdep_get_name(int fd, unused char *tty)
|
2009-01-20 22:17:53 +00:00
|
|
|
{
|
2013-04-10 11:46:29 +00:00
|
|
|
struct proc_bsdinfo bsdinfo;
|
2013-02-12 09:40:22 +00:00
|
|
|
pid_t pgrp;
|
|
|
|
int ret;
|
2009-01-26 22:57:20 +00:00
|
|
|
|
2013-02-12 09:40:22 +00:00
|
|
|
if ((pgrp = tcgetpgrp(fd)) == -1)
|
2009-02-13 00:43:04 +00:00
|
|
|
return (NULL);
|
2009-01-20 22:17:53 +00:00
|
|
|
|
2013-04-10 11:46:29 +00:00
|
|
|
ret = proc_pidinfo(pgrp, PROC_PIDTBSDINFO, 0,
|
2013-02-12 09:40:22 +00:00
|
|
|
&bsdinfo, sizeof bsdinfo);
|
2013-04-10 11:46:29 +00:00
|
|
|
if (ret == sizeof bsdinfo && *bsdinfo.pbi_comm != '\0')
|
|
|
|
return (strdup(bsdinfo.pbi_comm));
|
2013-02-12 09:40:22 +00:00
|
|
|
return (NULL);
|
2009-01-20 22:17:53 +00:00
|
|
|
}
|
2010-12-30 20:41:08 +00:00
|
|
|
|
2011-12-09 16:37:29 +00:00
|
|
|
char *
|
2012-09-24 13:05:38 +00:00
|
|
|
osdep_get_cwd(int fd)
|
2011-12-09 16:37:29 +00:00
|
|
|
{
|
2013-02-12 09:40:22 +00:00
|
|
|
static char wd[PATH_MAX];
|
2012-01-27 09:01:06 +00:00
|
|
|
struct proc_vnodepathinfo pathinfo;
|
2012-09-24 13:05:38 +00:00
|
|
|
pid_t pgrp;
|
2012-01-27 09:01:06 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-09-24 13:05:38 +00:00
|
|
|
if ((pgrp = tcgetpgrp(fd)) == -1)
|
|
|
|
return (NULL);
|
|
|
|
|
2013-02-12 09:40:22 +00:00
|
|
|
ret = proc_pidinfo(pgrp, PROC_PIDVNODEPATHINFO, 0,
|
|
|
|
&pathinfo, sizeof pathinfo);
|
2012-01-27 09:01:06 +00:00
|
|
|
if (ret == sizeof pathinfo) {
|
|
|
|
strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd);
|
|
|
|
return (wd);
|
|
|
|
}
|
2011-12-09 16:37:29 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2010-12-30 20:41:08 +00:00
|
|
|
struct event_base *
|
|
|
|
osdep_event_init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* On OS X, kqueue and poll are both completely broken and don't
|
|
|
|
* work on anything except socket file descriptors (yes, really).
|
|
|
|
*/
|
|
|
|
setenv("EVENT_NOKQUEUE", "1", 1);
|
|
|
|
setenv("EVENT_NOPOLL", "1", 1);
|
|
|
|
return (event_init());
|
|
|
|
}
|