Set $TMUX without the session when background jobs are run.

This commit is contained in:
Nicholas Marriott
2011-01-23 11:03:43 +00:00
parent 1377427e70
commit b8023044c3
5 changed files with 35 additions and 48 deletions

12
job.c
View File

@ -137,7 +137,8 @@ job_free(struct job *job)
int
job_run(struct job *job)
{
int nullfd, out[2];
struct environ env;
int nullfd, out[2];
if (job->fd != -1 || job->pid != -1)
return (0);
@ -145,13 +146,19 @@ job_run(struct job *job)
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
return (-1);
environ_init(&env);
environ_copy(&global_environ, &env);
server_fill_environ(NULL, &env);
switch (job->pid = fork()) {
case -1:
environ_free(&env);
return (-1);
case 0: /* child */
clear_signals(1);
environ_push(&global_environ);
environ_push(&env);
environ_free(&env);
if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed");
@ -174,6 +181,7 @@ job_run(struct job *job)
execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL);
fatal("execl failed");
default: /* parent */
environ_free(&env);
close(out[1]);
job->fd = out[0];