From c1b994852594b23b7443e01e05257c991684ba4e Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 9 Dec 2011 16:37:29 +0000 Subject: 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. --- osdep-freebsd.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'osdep-freebsd.c') 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 #include #include +#include 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) { -- cgit v1.2.3