From 41206e70b43b6c1b7cfa768d02dc2131c6e4ce8f Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 9 Jan 2007 10:21:44 +1000 Subject: [PATCH] Make the bg builtin check that all specified jobs exist before sending any of them to background. Also make sure that the string to pid conversion didn't throw errors. darcs-hash:20070109002144-ac50b-c3954d98bab5cd95699966b2d1f2480797a9094d.gz --- builtin.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/builtin.c b/builtin.c index a0d0f6df3..5d8116d8f 100644 --- a/builtin.c +++ b/builtin.c @@ -2478,12 +2478,36 @@ static int builtin_bg( wchar_t **argv ) } else { - for( argv++; !res && *argv != 0; argv++ ) + wchar_t *end; + int i; + int pid; + int err = 0; + + for( i=1; argv[i]; i++ ) { - int pid = wcstol( *argv, 0, 10 ); - res |= send_to_bg( job_get_from_pid( pid ), *argv); + errno=0; + pid = (int)wcstol( argv[i], &end, 10 ); + if( errno || pid < 0 || *end || !job_get_from_pid( pid ) ) + { + sb_printf( sb_err, + _( L"%ls: '%ls' is not a job\n" ), + argv[0], + argv[i] ); + err = 1; + break; + } + } + + if( !err ) + { + for( i=1; !res && argv[i]; i++ ) + { + pid = (int)wcstol( argv[i], 0, 10 ); + res |= send_to_bg( job_get_from_pid( pid ), *argv); + } } } + return res; }