2014-11-08 13:27:43 +01:00
|
|
|
/* $OpenBSD$ */
|
2009-01-20 23:17:53 +01: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 21:41:08 +01:00
|
|
|
#include <event.h>
|
2012-01-27 10:01:06 +01:00
|
|
|
#include <libproc.h>
|
2009-01-20 23:17:53 +01:00
|
|
|
#include <stdlib.h>
|
2009-02-07 20:41:35 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-01-20 23:17:53 +01:00
|
|
|
|
2010-12-30 21:41:08 +01:00
|
|
|
char *osdep_get_name(int, char *);
|
2012-09-24 15:05:38 +02:00
|
|
|
char *osdep_get_cwd(int);
|
2010-12-30 21:41:08 +01:00
|
|
|
struct event_base *osdep_event_init(void);
|
2009-02-09 19:08:01 +01:00
|
|
|
|
2019-11-07 15:08:17 +01:00
|
|
|
#ifndef __unused
|
2015-11-18 17:45:44 +01:00
|
|
|
#define __unused __attribute__ ((__unused__))
|
2019-11-07 15:08:17 +01:00
|
|
|
#endif
|
2009-01-20 23:17:53 +01:00
|
|
|
|
2009-02-13 01:43:04 +01:00
|
|
|
char *
|
2015-11-18 17:45:44 +01:00
|
|
|
osdep_get_name(int fd, __unused char *tty)
|
2009-01-20 23:17:53 +01:00
|
|
|
{
|
2013-04-10 13:46:29 +02:00
|
|
|
struct proc_bsdinfo bsdinfo;
|
2013-02-12 10:40:22 +01:00
|
|
|
pid_t pgrp;
|
|
|
|
int ret;
|
2009-01-26 23:57:20 +01:00
|
|
|
|
2013-02-12 10:40:22 +01:00
|
|
|
if ((pgrp = tcgetpgrp(fd)) == -1)
|
2009-02-13 01:43:04 +01:00
|
|
|
return (NULL);
|
2009-01-20 23:17:53 +01:00
|
|
|
|
2013-04-10 13:46:29 +02:00
|
|
|
ret = proc_pidinfo(pgrp, PROC_PIDTBSDINFO, 0,
|
2013-02-12 10:40:22 +01:00
|
|
|
&bsdinfo, sizeof bsdinfo);
|
2013-04-10 13:46:29 +02:00
|
|
|
if (ret == sizeof bsdinfo && *bsdinfo.pbi_comm != '\0')
|
|
|
|
return (strdup(bsdinfo.pbi_comm));
|
2013-02-12 10:40:22 +01:00
|
|
|
return (NULL);
|
2009-01-20 23:17:53 +01:00
|
|
|
}
|
2010-12-30 21:41:08 +01:00
|
|
|
|
2011-12-09 17:37:29 +01:00
|
|
|
char *
|
2012-09-24 15:05:38 +02:00
|
|
|
osdep_get_cwd(int fd)
|
2011-12-09 17:37:29 +01:00
|
|
|
{
|
2013-02-12 10:40:22 +01:00
|
|
|
static char wd[PATH_MAX];
|
2012-01-27 10:01:06 +01:00
|
|
|
struct proc_vnodepathinfo pathinfo;
|
2012-09-24 15:05:38 +02:00
|
|
|
pid_t pgrp;
|
2012-01-27 10:01:06 +01:00
|
|
|
int ret;
|
|
|
|
|
2012-09-24 15:05:38 +02:00
|
|
|
if ((pgrp = tcgetpgrp(fd)) == -1)
|
|
|
|
return (NULL);
|
|
|
|
|
2013-02-12 10:40:22 +01:00
|
|
|
ret = proc_pidinfo(pgrp, PROC_PIDVNODEPATHINFO, 0,
|
|
|
|
&pathinfo, sizeof pathinfo);
|
2012-01-27 10:01:06 +01:00
|
|
|
if (ret == sizeof pathinfo) {
|
|
|
|
strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd);
|
|
|
|
return (wd);
|
|
|
|
}
|
2011-12-09 17:37:29 +01:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2010-12-30 21:41:08 +01: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());
|
|
|
|
}
|