Readd the terminal flag for jobs, as not all jobs under job control should be given the terminal.

darcs-hash:20060201122715-ac50b-7efc499e8905e9898c214816d0a3468e077c7005.gz
This commit is contained in:
axel 2006-02-01 22:27:15 +10:00
parent 7a1a5a6f01
commit e95effb043
5 changed files with 47 additions and 32 deletions

View file

@ -177,8 +177,8 @@ int my_wcswidth( const wchar_t *c );
/** /**
This functions returns the end of the quoted substring beginning at This functions returns the end of the quoted substring beginning at
\c in. It can handle both single and double quotes. Returns 0 on \c in. The type of quoting character is detemrined by examining \c
error. in. Returns 0 on error.
\param in the position of the opening quote \param in the position of the opening quote
*/ */

17
exec.c
View file

@ -409,14 +409,14 @@ static int setup_child_process( job_t *j, process_t *p )
/* Wait till shell puts os in our own group */ /* Wait till shell puts os in our own group */
while( getpgrp() != j->pgid ) while( getpgrp() != j->pgid )
sleep(0); sleep(0);
}
/* Wait till shell gives us stdin */ /* Wait till shell gives us stdin */
if ( j->fg ) if ( j->terminal && j->fg )
{ {
while( tcgetpgrp( 0 ) != j->pgid ) while( tcgetpgrp( 0 ) != j->pgid )
sleep(0); sleep(0);
} }
}
res = handle_child_io( j->io, (p==0) ); res = handle_child_io( j->io, (p==0) );
@ -624,8 +624,13 @@ static int handle_new_child( job_t *j, process_t *p )
wperror( L"setpgid" ); wperror( L"setpgid" );
} }
} }
}
else
{
j->pgid = getpid();
}
if( j->fg ) if( j->terminal && j->fg )
{ {
if( tcsetpgrp (0, j->pgid) ) if( tcsetpgrp (0, j->pgid) )
{ {
@ -636,11 +641,7 @@ static int handle_new_child( job_t *j, process_t *p )
return -1; return -1;
} }
} }
}
else
{
j->pgid = getpid();
}
return 0; return 0;
} }

View file

@ -2179,9 +2179,8 @@ static void eval_job( tokenizer *tok )
case TOK_STRING: case TOK_STRING:
{ {
j = job_create(); j = job_create();
j->command=0;
j->fg=1; 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); j->skip_notification = is_subshell || is_block || is_event || (!is_interactive);
current_block->job = j; current_block->job = j;

18
proc.c
View file

@ -880,9 +880,8 @@ void job_continue (job_t *j, int cont)
if( !job_is_completed( j ) ) if( !job_is_completed( j ) )
{ {
if( j->job_control && j->fg ) if( j->terminal && j->fg )
{ {
/* Put the job into the foreground. */ /* Put the job into the foreground. */
signal_block(); signal_block();
if( tcsetpgrp (0, j->pgid) ) if( tcsetpgrp (0, j->pgid) )
@ -916,8 +915,20 @@ void job_continue (job_t *j, int cont)
if( cont ) if( cont )
{ {
process_t *p; process_t *p;
for( p=j->first_process; p; p=p->next ) for( p=j->first_process; p; p=p->next )
p->stopped=0; p->stopped=0;
if( j->job_control )
{
if( killpg( j->pgid, SIGCONT ) )
{
wperror( L"killpg (SIGCONT)" );
return;
}
}
else
{
for( p=j->first_process; p; p=p->next ) for( p=j->first_process; p; p=p->next )
{ {
if (kill ( p->pid, SIGCONT) < 0) if (kill ( p->pid, SIGCONT) < 0)
@ -927,6 +938,7 @@ void job_continue (job_t *j, int cont)
} }
} }
} }
}
if( j->fg ) if( j->fg )
{ {
@ -1007,7 +1019,7 @@ void job_continue (job_t *j, int cont)
/* /*
Put the shell back in the foreground. Put the shell back in the foreground.
*/ */
if( j->job_control && j->fg ) if( j->terminal && j->fg )
{ {
signal_block(); signal_block();
if( tcsetpgrp (0, getpid()) ) if( tcsetpgrp (0, getpid()) )

3
proc.h
View file

@ -166,6 +166,9 @@ typedef struct job
/** Whether the job is under job control */ /** Whether the job is under job control */
int job_control; int job_control;
/** Whether the job wants to own the terminal when in the foreground */
int terminal;
/** Pointer to the next job */ /** Pointer to the next job */
struct job *next; struct job *next;
} }