mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Sync OpenBSD patchset 848:
Set $TMUX without the session when background jobs are run.
This commit is contained in:
parent
d37650dc4f
commit
d0d1c0e486
4
cmd.c
4
cmd.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd.c,v 1.148 2011-01-07 14:45:34 tcunha Exp $ */
|
/* $Id: cmd.c,v 1.149 2011-02-14 23:11:33 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -355,7 +355,7 @@ cmd_current_session(struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Use the session from the TMUX environment variable. */
|
/* Use the session from the TMUX environment variable. */
|
||||||
if (data != NULL && data->pid == getpid()) {
|
if (data != NULL && data->pid == getpid() && data->idx != -1) {
|
||||||
s = session_find_by_index(data->idx);
|
s = session_find_by_index(data->idx);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
return (s);
|
return (s);
|
||||||
|
12
job.c
12
job.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: job.c,v 1.20 2011-01-21 23:44:13 tcunha Exp $ */
|
/* $Id: job.c,v 1.21 2011-02-14 23:11:33 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -136,6 +136,7 @@ job_free(struct job *job)
|
|||||||
int
|
int
|
||||||
job_run(struct job *job)
|
job_run(struct job *job)
|
||||||
{
|
{
|
||||||
|
struct environ env;
|
||||||
int nullfd, out[2];
|
int nullfd, out[2];
|
||||||
|
|
||||||
if (job->fd != -1 || job->pid != -1)
|
if (job->fd != -1 || job->pid != -1)
|
||||||
@ -144,13 +145,19 @@ job_run(struct job *job)
|
|||||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
|
environ_init(&env);
|
||||||
|
environ_copy(&global_environ, &env);
|
||||||
|
server_fill_environ(NULL, &env);
|
||||||
|
|
||||||
switch (job->pid = fork()) {
|
switch (job->pid = fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
|
environ_free(&env);
|
||||||
return (-1);
|
return (-1);
|
||||||
case 0: /* child */
|
case 0: /* child */
|
||||||
clear_signals(1);
|
clear_signals(1);
|
||||||
|
|
||||||
environ_push(&global_environ);
|
environ_push(&env);
|
||||||
|
environ_free(&env);
|
||||||
|
|
||||||
if (dup2(out[1], STDOUT_FILENO) == -1)
|
if (dup2(out[1], STDOUT_FILENO) == -1)
|
||||||
fatal("dup2 failed");
|
fatal("dup2 failed");
|
||||||
@ -173,6 +180,7 @@ job_run(struct job *job)
|
|||||||
execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL);
|
execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL);
|
||||||
fatal("execl failed");
|
fatal("execl failed");
|
||||||
default: /* parent */
|
default: /* parent */
|
||||||
|
environ_free(&env);
|
||||||
close(out[1]);
|
close(out[1]);
|
||||||
|
|
||||||
job->fd = out[0];
|
job->fd = out[0];
|
||||||
|
18
server-fn.c
18
server-fn.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: server-fn.c,v 1.118 2011-01-03 23:27:54 tcunha Exp $ */
|
/* $Id: server-fn.c,v 1.119 2011-02-14 23:11:33 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -30,14 +30,20 @@ void server_callback_identify(int, short, void *);
|
|||||||
void
|
void
|
||||||
server_fill_environ(struct session *s, struct environ *env)
|
server_fill_environ(struct session *s, struct environ *env)
|
||||||
{
|
{
|
||||||
char tmuxvar[MAXPATHLEN], *term;
|
char var[MAXPATHLEN], *term;
|
||||||
|
u_int idx;
|
||||||
xsnprintf(tmuxvar, sizeof tmuxvar,
|
long pid;
|
||||||
"%s,%ld,%u", socket_path, (long) getpid(), s->idx);
|
|
||||||
environ_set(env, "TMUX", tmuxvar);
|
|
||||||
|
|
||||||
|
if (s != NULL) {
|
||||||
term = options_get_string(&s->options, "default-terminal");
|
term = options_get_string(&s->options, "default-terminal");
|
||||||
environ_set(env, "TERM", term);
|
environ_set(env, "TERM", term);
|
||||||
|
|
||||||
|
idx = s->idx;
|
||||||
|
} else
|
||||||
|
idx = -1;
|
||||||
|
pid = getpid();
|
||||||
|
xsnprintf(var, sizeof var, "%s,%ld,%d", socket_path, pid, idx);
|
||||||
|
environ_set(env, "TMUX", var);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
47
tmux.c
47
tmux.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.c,v 1.235 2011-01-21 23:46:50 tcunha Exp $ */
|
/* $Id: tmux.c,v 1.236 2011-02-14 23:11:33 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -47,8 +47,8 @@ time_t start_time;
|
|||||||
char socket_path[MAXPATHLEN];
|
char socket_path[MAXPATHLEN];
|
||||||
int login_shell;
|
int login_shell;
|
||||||
char *environ_path;
|
char *environ_path;
|
||||||
pid_t environ_pid;
|
pid_t environ_pid = -1;
|
||||||
u_int environ_idx;
|
int environ_idx = -1;
|
||||||
|
|
||||||
__dead void usage(void);
|
__dead void usage(void);
|
||||||
void parseenvironment(void);
|
void parseenvironment(void);
|
||||||
@ -128,45 +128,18 @@ areshell(const char *shell)
|
|||||||
void
|
void
|
||||||
parseenvironment(void)
|
parseenvironment(void)
|
||||||
{
|
{
|
||||||
char *env, *path_pid, *pid_idx, buf[256];
|
char *env, path[256];
|
||||||
size_t len;
|
long pid;
|
||||||
const char *errstr;
|
int idx;
|
||||||
long long ll;
|
|
||||||
|
|
||||||
environ_pid = -1;
|
|
||||||
if ((env = getenv("TMUX")) == NULL)
|
if ((env = getenv("TMUX")) == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((path_pid = strchr(env, ',')) == NULL || path_pid == env)
|
if (sscanf(env, "%255s,%ld,%d", path, &pid, &idx) != 3)
|
||||||
return;
|
return;
|
||||||
if ((pid_idx = strchr(path_pid + 1, ',')) == NULL)
|
environ_path = xstrdup(path);
|
||||||
return;
|
environ_pid = pid;
|
||||||
if ((pid_idx == path_pid + 1 || pid_idx[1] == '\0'))
|
environ_idx = idx;
|
||||||
return;
|
|
||||||
|
|
||||||
/* path */
|
|
||||||
len = path_pid - env;
|
|
||||||
environ_path = xmalloc(len + 1);
|
|
||||||
memcpy(environ_path, env, len);
|
|
||||||
environ_path[len] = '\0';
|
|
||||||
|
|
||||||
/* pid */
|
|
||||||
len = pid_idx - path_pid - 1;
|
|
||||||
if (len > (sizeof buf) - 1)
|
|
||||||
return;
|
|
||||||
memcpy(buf, path_pid + 1, len);
|
|
||||||
buf[len] = '\0';
|
|
||||||
|
|
||||||
ll = strtonum(buf, 0, LONG_MAX, &errstr);
|
|
||||||
if (errstr != NULL)
|
|
||||||
return;
|
|
||||||
environ_pid = ll;
|
|
||||||
|
|
||||||
/* idx */
|
|
||||||
ll = strtonum(pid_idx + 1, 0, UINT_MAX, &errstr);
|
|
||||||
if (errstr != NULL)
|
|
||||||
return;
|
|
||||||
environ_idx = ll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
8
tmux.h
8
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.605 2011-01-21 23:56:11 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.606 2011-02-14 23:11:33 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -379,8 +379,8 @@ enum msgtype {
|
|||||||
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
||||||
*/
|
*/
|
||||||
struct msg_command_data {
|
struct msg_command_data {
|
||||||
pid_t pid; /* pid from $TMUX or -1 */
|
pid_t pid; /* PID from $TMUX or -1 */
|
||||||
u_int idx; /* index from $TMUX */
|
int idx; /* index from $TMUX or -1 */
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
char argv[COMMAND_LENGTH];
|
char argv[COMMAND_LENGTH];
|
||||||
@ -1297,7 +1297,7 @@ extern char socket_path[MAXPATHLEN];
|
|||||||
extern int login_shell;
|
extern int login_shell;
|
||||||
extern char *environ_path;
|
extern char *environ_path;
|
||||||
extern pid_t environ_pid;
|
extern pid_t environ_pid;
|
||||||
extern u_int environ_idx;
|
extern int environ_idx;
|
||||||
void logfile(const char *);
|
void logfile(const char *);
|
||||||
const char *getshell(void);
|
const char *getshell(void);
|
||||||
int checkshell(const char *);
|
int checkshell(const char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user