try harder to put background jobs in background; do not print in response to SIGPIPE

This commit is contained in:
rsc 2005-03-18 19:03:25 +00:00
parent ca30274bd9
commit 4ee543e58c
4 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,6 @@
#include <u.h>
#include <signal.h>
#include <sys/ioctl.h>
#include "rc.h"
#include "getflags.h"
#include "exec.h"
@ -220,6 +223,7 @@ void Xappend(void){
}
void Xasync(void){
int null=open("/dev/null", 0);
int tty;
int pid;
char npid[10];
if(null<0){
@ -232,7 +236,33 @@ void Xasync(void){
Xerror("try again");
break;
case 0:
/*
* I don't know what the right thing to do here is,
* so this is all experimentally determined.
* If we just dup /dev/null onto 0, then running
* ssh foo & will reopen /dev/tty, try to read a password,
* get a signal, and repeat, in a tight loop, forever.
* Arguably this is a bug in ssh (it behaves the same
* way under bash as under rc) but I'm fixing it here
* anyway. If we dissociate the process from the tty,
* then it won't be able to open /dev/tty ever again.
* The SIG_IGN on SIGTTOU makes writing the tty
* (via fd 1 or 2, for example) succeed even though
* our pgrp is not the terminal's controlling pgrp.
*/
if((tty=open("/dev/tty", OREAD)) >= 0){
/*
* Should make reads of tty fail, writes succeed.
*/
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
ioctl(tty, TIOCNOTTY);
close(tty);
}
if(isatty(0))
pushredir(ROPEN, null, 0);
else
close(null);
start(runq->code, runq->pc+1, runq->local);
runq->ret=0;
break;

View file

@ -1,3 +1,5 @@
#include <u.h>
#include <signal.h>
#include "rc.h"
#include "getflags.h"
#include "exec.h"
@ -11,7 +13,9 @@ Xasync(void)
{
int null = open("/dev/null", 0);
int pid;
int tcpgrp, pgrp;
char npid[10];
if(null<0){
Xerror("Can't open /dev/null\n");
return;
@ -22,6 +26,12 @@ Xasync(void)
Xerror("try again");
break;
case 0:
/*
* Should make reads of tty fail, writes succeed.
*/
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
pushredir(ROPEN, null, 0);
start(runq->code, runq->pc+1, runq->local);
runq->ret = 0;

View file

@ -403,6 +403,7 @@ notifyf(void *unused0, char *s)
}
goto Out;
}
if(strcmp(s, "sys: write on closed pipe") != 0)
if(strcmp(s, "sys: child") != 0)
pfmt(err, "rc: note: %s\n", s);
noted(NDFLT);

View file

@ -9,6 +9,9 @@
#ifdef Plan9
#include <u.h>
#include <libc.h>
#undef NSIG
#undef SIGINT
#undef SIGQUIT
#define NSIG 32
#define SIGINT 2
#define SIGQUIT 3