diff options
Diffstat (limited to 'osdep-linux.c')
-rw-r--r-- | osdep-linux.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/osdep-linux.c b/osdep-linux.c index ccac2670..ad4c11cd 100644 --- a/osdep-linux.c +++ b/osdep-linux.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $OpenBSD$ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -18,6 +18,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/param.h> #include <event.h> #include <stdio.h> @@ -50,7 +51,7 @@ osdep_get_name(int fd, unused char *tty) while ((ch = fgetc(f)) != EOF) { if (ch == '\0') break; - buf = xrealloc(buf, 1, len + 2); + buf = xrealloc(buf, len + 2); buf[len++] = ch; } if (buf != NULL) @@ -65,7 +66,7 @@ osdep_get_cwd(int fd) { static char target[MAXPATHLEN + 1]; char *path; - pid_t pgrp; + pid_t pgrp, sid; ssize_t n; if ((pgrp = tcgetpgrp(fd)) == -1) @@ -74,6 +75,13 @@ osdep_get_cwd(int fd) xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp); n = readlink(path, target, MAXPATHLEN); free(path); + + if (n == -1 && ioctl(fd, TIOCGSID, &sid) != -1) { + xasprintf(&path, "/proc/%lld/cwd", (long long) sid); + n = readlink(path, target, MAXPATHLEN); + free(path); + } + if (n > 0) { target[n] = '\0'; return (target); |