summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2024-05-15 09:59:13 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2024-05-15 09:59:13 +0000
commit263815373d139cd2b02804faad11aa2c4e21b0b4 (patch)
tree009a97f98cd20ffac75aba024f0760c57cc3e4e5 /usr.bin/tmux
parent83445d02cf0722a8e0505a59fa60228f2de07ccb (diff)
Use default-shell for command prompt #() and popups as well
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/client.c16
-rw-r--r--usr.bin/tmux/job.c33
-rw-r--r--usr.bin/tmux/tmux.c20
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 47 insertions, 25 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c
index f8195090cbc..dfbf36939be 100644
--- a/usr.bin/tmux/client.c
+++ b/usr.bin/tmux/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.161 2023/07/10 12:00:08 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.162 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -490,20 +490,10 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
static __dead void
client_exec(const char *shell, const char *shellcmd)
{
- const char *name, *ptr;
- char *argv0;
+ char *argv0;
log_debug("shell %s, command %s", shell, shellcmd);
-
- ptr = strrchr(shell, '/');
- if (ptr != NULL && *(ptr + 1) != '\0')
- name = ptr + 1;
- else
- name = shell;
- if (client_flags & CLIENT_LOGIN)
- xasprintf(&argv0, "-%s", name);
- else
- xasprintf(&argv0, "%s", name);
+ argv0 = shell_argv0(shell, !!(client_flags & CLIENT_LOGIN));
setenv("SHELL", shell, 1);
proc_clear_signals(client_proc, 1);
diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c
index f13cb8d67fe..e92daaef81e 100644
--- a/usr.bin/tmux/job.c
+++ b/usr.bin/tmux/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.67 2022/02/01 12:05:42 nicm Exp $ */
+/* $OpenBSD: job.c,v 1.68 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -79,19 +79,28 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
struct environ *env;
pid_t pid;
int nullfd, out[2], master;
- const char *home;
+ const char *home, *shell;
sigset_t set, oldset;
struct winsize ws;
- char **argvp, tty[TTY_NAME_MAX];
+ char **argvp, tty[TTY_NAME_MAX], *argv0;
/*
- * Do not set TERM during .tmux.conf, it is nice to be able to use
- * if-shell to decide on default-terminal based on outside TERM.
+ * Do not set TERM during .tmux.conf (second argument here), it is nice
+ * to be able to use if-shell to decide on default-terminal based on
+ * outside TERM.
*/
env = environ_for_session(s, !cfg_finished);
if (e != NULL)
environ_copy(e, env);
+ if (s != NULL)
+ shell = options_get_string(s->options, "default-shell");
+ else
+ shell = options_get_string(global_s_options, "default-shell");
+ if (!checkshell(shell))
+ shell = _PATH_BSHELL;
+ argv0 = shell_argv0(shell, 0);
+
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, &oldset);
@@ -107,10 +116,11 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
}
if (cmd == NULL) {
cmd_log_argv(argc, argv, "%s:", __func__);
- log_debug("%s: cwd=%s", __func__, cwd == NULL ? "" : cwd);
+ log_debug("%s: cwd=%s, shell=%s", __func__,
+ cwd == NULL ? "" : cwd, shell);
} else {
- log_debug("%s: cmd=%s, cwd=%s", __func__, cmd,
- cwd == NULL ? "" : cwd);
+ log_debug("%s: cmd=%s, cwd=%s, shell=%s", __func__, cmd,
+ cwd == NULL ? "" : cwd, shell);
}
switch (pid) {
@@ -152,7 +162,8 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
closefrom(STDERR_FILENO + 1);
if (cmd != NULL) {
- execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
+ setenv("SHELL", shell, 1);
+ execl(shell, argv0, "-c", cmd, (char *)NULL);
fatal("execl failed");
} else {
argvp = cmd_copy_argv(argc, argv);
@@ -163,6 +174,7 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
sigprocmask(SIG_SETMASK, &oldset, NULL);
environ_free(env);
+ free(argv0);
job = xmalloc(sizeof *job);
job->state = JOB_RUNNING;
@@ -196,12 +208,13 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e, struct sessio
fatalx("out of memory");
bufferevent_enable(job->event, EV_READ|EV_WRITE);
- log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
+ log_debug("run job %p: %s, pid %ld", job, job->cmd, (long)job->pid);
return (job);
fail:
sigprocmask(SIG_SETMASK, &oldset, NULL);
environ_free(env);
+ free(argv0);
return (NULL);
}
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 0df587878be..1332bf3aa5f 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.211 2023/04/17 18:00:19 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.212 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -239,6 +239,24 @@ fail:
return (NULL);
}
+char *
+shell_argv0(const char *shell, int is_login)
+{
+ const char *slash, *name;
+ char *argv0;
+
+ slash = strrchr(shell, '/');
+ if (slash != NULL && slash[1] != '\0')
+ name = slash + 1;
+ else
+ name = shell;
+ if (is_login)
+ xasprintf(&argv0, "-%s", name);
+ else
+ xasprintf(&argv0, "%s", name);
+ return (argv0);
+}
+
void
setblocking(int fd, int state)
{
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 4af59adf4e5..b59ce530026 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1214 2024/04/10 07:36:25 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1215 2024/05/15 09:59:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2062,6 +2062,7 @@ extern int ptm_fd;
extern const char *shell_command;
int checkshell(const char *);
void setblocking(int, int);
+char *shell_argv0(const char *, int);
uint64_t get_timer(void);
const char *sig2name(int);
const char *find_cwd(void);