mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Use pgrp of pty fd not pid of immediate child when recovering current working
directory (like current process). From Marcel Partap.
This commit is contained in:
		
							
								
								
									
										2
									
								
								cmd.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								cmd.c
									
									
									
									
									
								
							| @@ -1297,7 +1297,7 @@ cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd) | ||||
| 		if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) | ||||
| 			root = ctx->cmdclient->cwd; | ||||
| 		else if (ctx->curclient != NULL && s->curw != NULL) | ||||
| 			root = osdep_get_cwd(s->curw->window->active->pid); | ||||
| 			root = osdep_get_cwd(s->curw->window->active->fd); | ||||
| 		else | ||||
| 			return (s->cwd); | ||||
| 		skip = 0; | ||||
|   | ||||
							
								
								
									
										2
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								format.c
									
									
									
									
									
								
							| @@ -391,7 +391,7 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) | ||||
| 		format_add(ft, "pane_start_command", "%s", wp->cmd); | ||||
| 	if (wp->cwd != NULL) | ||||
| 		format_add(ft, "pane_start_path", "%s", wp->cwd); | ||||
| 	format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->pid)); | ||||
| 	format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->fd)); | ||||
| 	format_add(ft, "pane_pid", "%ld", (long) wp->pid); | ||||
| 	format_add(ft, "pane_tty", "%s", wp->tty); | ||||
| } | ||||
|   | ||||
| @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(unused int fd) | ||||
| { | ||||
| 	return (NULL); | ||||
| } | ||||
|   | ||||
| @@ -26,7 +26,7 @@ | ||||
| #include <unistd.h> | ||||
|  | ||||
| char			*osdep_get_name(int, char *); | ||||
| char			*osdep_get_cwd(pid_t); | ||||
| char			*osdep_get_cwd(int); | ||||
| struct event_base	*osdep_event_init(void); | ||||
|  | ||||
| #define unused __attribute__ ((unused)) | ||||
| @@ -51,14 +51,18 @@ osdep_get_name(int fd, unused char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	static char 			wd[PATH_MAX]; | ||||
| 	struct proc_vnodepathinfo	pathinfo; | ||||
| 	pid_t				pgrp; | ||||
| 	int				ret; | ||||
|  | ||||
| 	if ((pgrp = tcgetpgrp(fd)) == -1) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	ret = proc_pidinfo( | ||||
| 	    pid, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); | ||||
| 	    pgrp, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); | ||||
| 	if (ret == sizeof pathinfo) { | ||||
| 		strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); | ||||
| 		return (wd); | ||||
|   | ||||
| @@ -31,7 +31,7 @@ | ||||
|  | ||||
| struct kinfo_proc	*cmp_procs(struct kinfo_proc *, struct kinfo_proc *); | ||||
| char			*osdep_get_name(int, char *); | ||||
| char			*osdep_get_cwd(pid_t); | ||||
| char			*osdep_get_cwd(int); | ||||
| struct event_base	*osdep_event_init(void); | ||||
|  | ||||
| #ifndef nitems | ||||
| @@ -121,7 +121,7 @@ error: | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	return (NULL); | ||||
| } | ||||
|   | ||||
| @@ -33,7 +33,7 @@ | ||||
|  | ||||
| struct kinfo_proc	*cmp_procs(struct kinfo_proc *, struct kinfo_proc *); | ||||
| char			*osdep_get_name(int, char *); | ||||
| char			*osdep_get_cwd(pid_t); | ||||
| char			*osdep_get_cwd(int); | ||||
| struct event_base	*osdep_event_init(void); | ||||
|  | ||||
| #ifndef nitems | ||||
| @@ -133,13 +133,17 @@ error: | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	static char		 wd[PATH_MAX]; | ||||
| 	struct kinfo_file	*info = NULL; | ||||
| 	pid_t			 pgrp; | ||||
| 	int			 nrecords, i; | ||||
|  | ||||
| 	if ((info = kinfo_getfile(pid, &nrecords)) == NULL) | ||||
| 	if ((pgrp = tcgetpgrp(fd)) == -1) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	if ((info = kinfo_getfile(pgrp, &nrecords)) == NULL) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	for (i = 0; i < nrecords; i++) { | ||||
|   | ||||
| @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(unused int fd) | ||||
| { | ||||
| 	return (NULL); | ||||
| } | ||||
|   | ||||
| @@ -61,13 +61,17 @@ osdep_get_name(int fd, unused char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	static char	 target[MAXPATHLEN + 1]; | ||||
| 	char		*path; | ||||
| 	pid_t		 pgrp; | ||||
| 	ssize_t		 n; | ||||
|  | ||||
| 	xasprintf(&path, "/proc/%d/cwd", pid); | ||||
| 	if ((pgrp = tcgetpgrp(fd)) == -1) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp); | ||||
| 	n = readlink(path, target, MAXPATHLEN); | ||||
| 	free(path); | ||||
| 	if (n > 0) { | ||||
|   | ||||
| @@ -34,7 +34,7 @@ | ||||
|  | ||||
| struct kinfo_proc2	*cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *); | ||||
| char			*osdep_get_name(int, char *); | ||||
| char			*osdep_get_cwd(pid_t); | ||||
| char			*osdep_get_cwd(int); | ||||
| struct event_base	*osdep_event_init(void); | ||||
|  | ||||
| struct kinfo_proc2 * | ||||
| @@ -125,7 +125,7 @@ error: | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	return (NULL); | ||||
| } | ||||
|   | ||||
| @@ -37,7 +37,7 @@ | ||||
|  | ||||
| struct kinfo_proc	*cmp_procs(struct kinfo_proc *, struct kinfo_proc *); | ||||
| char			*osdep_get_name(int, char *); | ||||
| char			*osdep_get_cwd(pid_t); | ||||
| char			*osdep_get_cwd(int); | ||||
| struct event_base	*osdep_event_init(void); | ||||
|  | ||||
| struct kinfo_proc * | ||||
| @@ -135,12 +135,14 @@ error: | ||||
| } | ||||
|  | ||||
| char* | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	int		name[] = { CTL_KERN, KERN_PROC_CWD, (int)pid }; | ||||
| 	int		name[] = { CTL_KERN, KERN_PROC_CWD, 0 }; | ||||
| 	static char	path[MAXPATHLEN]; | ||||
| 	size_t		pathlen = sizeof path; | ||||
|  | ||||
| 	if ((name[2] = tcgetpgrp(fd)) == -1) | ||||
| 		return (NULL); | ||||
| 	if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) | ||||
| 		return (NULL); | ||||
| 	return (path); | ||||
|   | ||||
| @@ -65,13 +65,17 @@ osdep_get_name(int fd, char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	static char	 target[MAXPATHLEN + 1]; | ||||
| 	char		*path; | ||||
| 	ssize_t		 n; | ||||
| 	pid_t		 pgrp; | ||||
|  | ||||
| 	xasprintf(&path, "/proc/%u/path/cwd", (u_int) pid); | ||||
| 	if ((pgrp = tcgetpgrp(fd)) == -1) | ||||
| 		return (NULL); | ||||
|  | ||||
| 	xasprintf(&path, "/proc/%u/path/cwd", (u_int) pgrp); | ||||
| 	n = readlink(path, target, MAXPATHLEN); | ||||
| 	free(path); | ||||
| 	if (n > 0) { | ||||
|   | ||||
| @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) | ||||
| } | ||||
|  | ||||
| char * | ||||
| osdep_get_cwd(pid_t pid) | ||||
| osdep_get_cwd(int fd) | ||||
| { | ||||
| 	return (NULL); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Nicholas Marriott
					Nicholas Marriott