From 445f6539cf3d2cfcc0ff36db24ede8bb5415c5ed Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 25 Apr 2006 01:34:34 +1000 Subject: [PATCH] Fix two bugs in the jobs builtin, causing freezes and other incorrect behaviours darcs-hash:20060424153434-ac50b-2434329395cbd4a258d6fb9f15e166065b2eb164.gz --- builtin.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/builtin.c b/builtin.c index 67dfb03ec..83c4ebb92 100644 --- a/builtin.c +++ b/builtin.c @@ -2077,7 +2077,7 @@ static void make_first( job_t *j ) */ static int builtin_fg( wchar_t **argv ) { - job_t *j; + job_t *j=0; if( argv[1] == 0 ) { @@ -2127,27 +2127,40 @@ static int builtin_fg( wchar_t **argv ) } else { - int pid = abs(wcstol( argv[1], 0, 10 )); - j = job_get_from_pid( pid ); - if( !j ) + wchar_t *end; + int pid = abs(wcstol( argv[1], &end, 10 )); + + if( *end ) { - sb_printf( sb_err, - _( L"%ls: No suitable job: %d\n" ), - argv[0], - pid ); - builtin_print_help( argv[0], sb_err ); + sb_printf( sb_err, + _( L"%ls: Argument must be a number: %ls\n" ), + argv[0], + argv[1] ); + builtin_print_help( argv[0], sb_err ); } - if( !j->job_control ) + else { - sb_printf( sb_err, - _( L"%ls: Can't put job %d, '%ls' to foreground because it is not under job control\n" ), - argv[0], - pid, - j->command ); - builtin_print_help( argv[0], sb_err ); - j=0; + j = job_get_from_pid( pid ); + if( !j || !j->constructed || job_is_completed( j )) + { + sb_printf( sb_err, + _( L"%ls: No suitable job: %d\n" ), + argv[0], + pid ); + builtin_print_help( argv[0], sb_err ); + j=0; + } + else if( !j->job_control ) + { + sb_printf( sb_err, + _( L"%ls: Can't put job %d, '%ls' to foreground because it is not under job control\n" ), + argv[0], + pid, + j->command ); + builtin_print_help( argv[0], sb_err ); + j=0; + } } - } if( j )