From 32816eaebd4ccd712cc7f7291a587146d122a9ff Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 28 Jan 2020 10:21:21 +0000 Subject: [PATCH 1/2] Set up working directory before killing the existing pane on respawn. --- spawn.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/spawn.c b/spawn.c index 75995221..933f0c6a 100644 --- a/spawn.c +++ b/spawn.c @@ -225,6 +225,17 @@ spawn_pane(struct spawn_context *sc, char **cause) spawn_log(__func__, sc); + /* + * Work out the current working directory. If respawning, use + * the pane's stored one unless specified. + */ + if (sc->cwd != NULL) + cwd = format_single(item, sc->cwd, c, s, NULL, NULL); + else if (~sc->flags & SPAWN_RESPAWN) + cwd = xstrdup(server_client_get_cwd(c, s)); + else + cwd = NULL; + /* * If we are respawning then get rid of the old process. Otherwise * either create a new cell or assign to the one we are given. @@ -235,6 +246,7 @@ spawn_pane(struct spawn_context *sc, char **cause) window_pane_index(sc->wp0, &idx); xasprintf(cause, "pane %s:%d.%u still active", s->name, sc->wl->idx, idx); + free(cwd); return (NULL); } if (sc->wp0->fd != -1) { @@ -255,8 +267,8 @@ spawn_pane(struct spawn_context *sc, char **cause) } /* - * Now we have a pane with nothing running in it ready for the new - * process. Work out the command and arguments. + * Now we have a pane with nothing running in it ready for the new process. + * Work out the command and arguments and store the working directory. */ if (sc->argc == 0 && (~sc->flags & SPAWN_RESPAWN)) { cmd = options_get_string(s->options, "default-command"); @@ -271,6 +283,10 @@ spawn_pane(struct spawn_context *sc, char **cause) argc = sc->argc; argv = sc->argv; } + if (cwd != NULL) { + free(new_wp->cwd); + new_wp->cwd = cwd; + } /* * Replace the stored arguments if there are new ones. If not, the @@ -282,21 +298,6 @@ spawn_pane(struct spawn_context *sc, char **cause) new_wp->argv = cmd_copy_argv(argc, argv); } - /* - * Work out the current working directory. If respawning, use - * the pane's stored one unless specified. - */ - if (sc->cwd != NULL) - cwd = format_single(item, sc->cwd, c, s, NULL, NULL); - else if (~sc->flags & SPAWN_RESPAWN) - cwd = xstrdup(server_client_get_cwd(c, s)); - else - cwd = NULL; - if (cwd != NULL) { - free(new_wp->cwd); - new_wp->cwd = cwd; - } - /* Create an environment for this pane. */ child = environ_for_session(s, 0); if (sc->environ != NULL) From f165221dc4641837ee9f589bb666d310a495904c Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 28 Jan 2020 10:44:30 +0000 Subject: [PATCH 2/2] Reduce a difference with portable tmux by adding the -V flag and #{version} format; on OpenBSD these just report the OpenBSD version. --- format.c | 1 + proc.c | 4 ++-- tmux.1 | 8 +++++++- tmux.c | 20 +++++++++++++++++++- tmux.h | 1 + 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/format.c b/format.c index f5e7b2ce..ff8e3c62 100644 --- a/format.c +++ b/format.c @@ -1106,6 +1106,7 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags) ft->flags = flags; ft->time = time(NULL); + format_add(ft, "version", "%s", getversion()); format_add_cb(ft, "host", format_cb_host); format_add_cb(ft, "host_short", format_cb_host_short); format_add_cb(ft, "pid", format_cb_pid); diff --git a/proc.c b/proc.c index 48e0d90c..3fc190a2 100644 --- a/proc.c +++ b/proc.c @@ -182,8 +182,8 @@ proc_start(const char *name) if (uname(&u) < 0) memset(&u, 0, sizeof u); - log_debug("%s started (%ld): socket %s, protocol %d", name, - (long)getpid(), socket_path, PROTOCOL_VERSION); + log_debug("%s started (%ld): version %s, socket %s, protocol %d", name, + (long)getpid(), getversion(), socket_path, PROTOCOL_VERSION); log_debug("on %s %s %s; libevent %s (%s)", u.sysname, u.release, u.version, event_get_version(), event_get_method()); diff --git a/tmux.1 b/tmux.1 index 11bdf4bc..bc24c193 100644 --- a/tmux.1 +++ b/tmux.1 @@ -23,7 +23,7 @@ .Sh SYNOPSIS .Nm tmux .Bk -words -.Op Fl 2Cluv +.Op Fl 2CluvV .Op Fl c Ar shell-command .Op Fl f Ar file .Op Fl L Ar socket-name @@ -210,6 +210,11 @@ signal may be sent to the server process to toggle logging between on (as if .Fl v was given) and off. +.It Fl V +Report the +.Nm +version. +.Pp .It Ar command Op Ar flags This specifies one of a set of commands used to control .Nm , @@ -4369,6 +4374,7 @@ The following variables are available, where appropriate: .It Li "session_windows" Ta "" Ta "Number of windows in session" .It Li "socket_path" Ta "" Ta "Server socket path" .It Li "start_time" Ta "" Ta "Server start time" +.It Li "version" Ta "" Ta "Server version" .It Li "window_active" Ta "" Ta "1 if window active" .It Li "window_active_clients" Ta "" Ta "Number of clients viewing this window" .It Li "window_active_clients_list" Ta "" Ta "List of clients viewing this window" diff --git a/tmux.c b/tmux.c index fe2647f5..f98037b5 100644 --- a/tmux.c +++ b/tmux.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -212,6 +213,20 @@ find_home(void) return (home); } +const char * +getversion(void) +{ + static char *version; + struct utsname u; + + if (version == NULL) { + if (uname(&u) < 0) + fatalx("uname failed"); + xasprintf(&version, "openbsd-%s", u.release); + } + return version; +} + int main(int argc, char **argv) { @@ -238,7 +253,7 @@ main(int argc, char **argv) flags = 0; label = path = NULL; - while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUv")) != -1) { + while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUvV")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; @@ -255,6 +270,9 @@ main(int argc, char **argv) case 'f': set_cfg_file(optarg); break; + case 'V': + printf("%s %s\n", getprogname(), getversion()); + exit(0); case 'l': flags |= CLIENT_LOGIN; break; diff --git a/tmux.h b/tmux.h index d56c5fea..24e4277f 100644 --- a/tmux.h +++ b/tmux.h @@ -1769,6 +1769,7 @@ int areshell(const char *); void setblocking(int, int); const char *find_cwd(void); const char *find_home(void); +const char *getversion(void); /* proc.c */ struct imsg;