diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2011-12-09 16:37:29 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2011-12-09 16:37:29 +0000 |
commit | c1b994852594b23b7443e01e05257c991684ba4e (patch) | |
tree | 7cbfc1dbdeff8197e63167dee96200d122a1be72 /osdep-freebsd.c | |
parent | 76862acf3e8ebd3573c1b9415b32731891e5545a (diff) |
Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:
1) If tmux neww is run from the command line, the working directory of the
client is used.
2) Otherwise use some platform specific code to retrieve the current working
directory of the process in the active pane.
3) If that fails, the directory where the session was created is used.
Idea and support code, Linux, Solaris, FreeBSD bits by Romain Francoise,
OpenBSD bits by me.
Diffstat (limited to 'osdep-freebsd.c')
-rw-r--r-- | osdep-freebsd.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/osdep-freebsd.c b/osdep-freebsd.c index 6b0c8886..1027a648 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -29,9 +29,11 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <libutil.h> struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); +char *osdep_get_cwd(pid_t); struct event_base *osdep_event_init(void); #ifndef nitems @@ -130,6 +132,28 @@ error: return (NULL); } +char * +osdep_get_cwd(pid_t pid) +{ + static char wd[PATH_MAX]; + struct kinfo_file *info = NULL; + int nrecords, i; + + if ((info = kinfo_getfile(pid, &nrecords)) == NULL) + return (NULL); + + for (i = 0; i < nrecords; i++) { + if (info[i].kf_fd == KF_FD_TYPE_CWD) { + strlcpy(wd, info[i].kf_path, sizeof wd); + free(info); + return (wd); + } + } + + free(info); + return (NULL); +} + struct event_base * osdep_event_init(void) { |