4 * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/param.h>
20 #include <sys/procfs.h>
29 osdep_get_name(__unused
int fd
, char *tty
)
37 if ((ttyfd
= open(tty
, O_RDONLY
|O_NOCTTY
)) == -1)
40 retval
= ioctl(ttyfd
, TIOCGPGRP
, &pgrp
);
45 xasprintf(&path
, "/proc/%u/psinfo", (u_int
) pgrp
);
46 f
= open(path
, O_RDONLY
);
51 bytes
= read(f
, &p
, sizeof(p
));
53 if (bytes
!= sizeof(p
))
56 return (xstrdup(p
.pr_fname
));
62 static char target
[MAXPATHLEN
+ 1];
67 int len
, retval
, ttyfd
;
69 if ((ttypath
= ptsname(fd
)) == NULL
)
71 if ((ttyfd
= open(ttypath
, O_RDONLY
|O_NOCTTY
)) == -1)
74 retval
= ioctl(ttyfd
, TIOCGPGRP
, &pgrp
);
79 xasprintf(&path
, "/proc/%u/cwd", (u_int
) pgrp
);
80 n
= readlink(path
, target
, MAXPATHLEN
);
84 if ((len
= strlen(target
)) > 1 && target
[len
- 1] == '/')
85 target
[len
- 1] = '\0';
92 osdep_event_init(void)
94 return (event_init());