From e95effb043c5e082e53db814088190f7152993f2 Mon Sep 17 00:00:00 2001 From: axel Date: Wed, 1 Feb 2006 22:27:15 +1000 Subject: [PATCH] Readd the terminal flag for jobs, as not all jobs under job control should be given the terminal. darcs-hash:20060201122715-ac50b-7efc499e8905e9898c214816d0a3468e077c7005.gz --- common.h | 4 ++-- exec.c | 39 ++++++++++++++++++++------------------- parser.c | 7 +++---- proc.c | 26 +++++++++++++++++++------- proc.h | 3 +++ 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/common.h b/common.h index 7fa8ed407..278554a41 100644 --- a/common.h +++ b/common.h @@ -177,8 +177,8 @@ int my_wcswidth( const wchar_t *c ); /** This functions returns the end of the quoted substring beginning at - \c in. It can handle both single and double quotes. Returns 0 on - error. + \c in. The type of quoting character is detemrined by examining \c + in. Returns 0 on error. \param in the position of the opening quote */ diff --git a/exec.c b/exec.c index bb502a1d6..5f293eb92 100644 --- a/exec.c +++ b/exec.c @@ -409,13 +409,13 @@ static int setup_child_process( job_t *j, process_t *p ) /* Wait till shell puts os in our own group */ while( getpgrp() != j->pgid ) sleep(0); - - /* Wait till shell gives us stdin */ - if ( j->fg ) - { - while( tcgetpgrp( 0 ) != j->pgid ) - sleep(0); - } + } + + /* Wait till shell gives us stdin */ + if ( j->terminal && j->fg ) + { + while( tcgetpgrp( 0 ) != j->pgid ) + sleep(0); } res = handle_child_io( j->io, (p==0) ); @@ -624,23 +624,24 @@ static int handle_new_child( job_t *j, process_t *p ) wperror( L"setpgid" ); } } - - if( j->fg ) - { - if( tcsetpgrp (0, j->pgid) ) - { - debug( 1, _( L"Could not send job %d ('%ls') to foreground" ), - j->job_id, - j->command ); - wperror( L"tcsetpgrp" ); - return -1; - } - } } else { j->pgid = getpid(); } + + if( j->terminal && j->fg ) + { + if( tcsetpgrp (0, j->pgid) ) + { + debug( 1, _( L"Could not send job %d ('%ls') to foreground" ), + j->job_id, + j->command ); + wperror( L"tcsetpgrp" ); + return -1; + } + } + return 0; } diff --git a/parser.c b/parser.c index 85106b72a..fc4c48bad 100644 --- a/parser.c +++ b/parser.c @@ -2179,13 +2179,12 @@ static void eval_job( tokenizer *tok ) case TOK_STRING: { j = job_create(); - j->command=0; j->fg=1; - j->constructed=0; + j->terminal = j->job_control && (!is_subshell && !is_event); j->skip_notification = is_subshell || is_block || is_event || (!is_interactive); - + current_block->job = j; - + if( is_interactive ) { if( tcgetattr (0, &j->tmodes) ) diff --git a/proc.c b/proc.c index 366a3b5cc..381260393 100644 --- a/proc.c +++ b/proc.c @@ -880,9 +880,8 @@ void job_continue (job_t *j, int cont) if( !job_is_completed( j ) ) { - if( j->job_control && j->fg ) + if( j->terminal && j->fg ) { - /* Put the job into the foreground. */ signal_block(); if( tcsetpgrp (0, j->pgid) ) @@ -916,15 +915,28 @@ void job_continue (job_t *j, int cont) if( cont ) { process_t *p; + for( p=j->first_process; p; p=p->next ) p->stopped=0; - for( p=j->first_process; p; p=p->next ) + + if( j->job_control ) { - if (kill ( p->pid, SIGCONT) < 0) + if( killpg( j->pgid, SIGCONT ) ) { - wperror (L"kill (SIGCONT)"); + wperror( L"killpg (SIGCONT)" ); return; - } + } + } + else + { + for( p=j->first_process; p; p=p->next ) + { + if (kill ( p->pid, SIGCONT) < 0) + { + wperror (L"kill (SIGCONT)"); + return; + } + } } } @@ -1007,7 +1019,7 @@ void job_continue (job_t *j, int cont) /* Put the shell back in the foreground. */ - if( j->job_control && j->fg ) + if( j->terminal && j->fg ) { signal_block(); if( tcsetpgrp (0, getpid()) ) diff --git a/proc.h b/proc.h index a0cba675e..a68253310 100644 --- a/proc.h +++ b/proc.h @@ -166,6 +166,9 @@ typedef struct job /** Whether the job is under job control */ int job_control; + /** Whether the job wants to own the terminal when in the foreground */ + int terminal; + /** Pointer to the next job */ struct job *next; }