aboutsummaryrefslogtreecommitdiff
path: root/osdep-sunos.c
diff options
context:
space:
mode:
Diffstat (limited to 'osdep-sunos.c')
-rw-r--r--osdep-sunos.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/osdep-sunos.c b/osdep-sunos.c
index fd644f5d..855cac9d 100644
--- a/osdep-sunos.c
+++ b/osdep-sunos.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $OpenBSD$ */
/*
* Copyright (c) 2009 Todd Carson <toc@daybefore.net>
@@ -69,10 +69,19 @@ osdep_get_cwd(int fd)
{
static char target[MAXPATHLEN + 1];
char *path;
+ const char *ttypath;
ssize_t n;
pid_t pgrp;
+ int retval, ttyfd;
- if ((pgrp = tcgetpgrp(fd)) == -1)
+ if ((ttypath = ptsname(fd)) == NULL)
+ return (NULL);
+ if ((ttyfd = open(ttypath, O_RDONLY|O_NOCTTY)) == -1)
+ return (NULL);
+
+ retval = ioctl(ttyfd, TIOCGPGRP, &pgrp);
+ close(ttyfd);
+ if (retval == -1)
return (NULL);
xasprintf(&path, "/proc/%u/path/cwd", (u_int) pgrp);