Sync OpenBSD patchset 848:

Set $TMUX without the session when background jobs are run.
This commit is contained in:
Tiago Cunha
2011-02-14 23:11:33 +00:00
parent d37650dc4f
commit d0d1c0e486
5 changed files with 40 additions and 53 deletions

14
job.c
View File

@ -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>
@ -136,7 +136,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);
@ -144,13 +145,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");
@ -173,6 +180,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];