From bc1efb1556d84ed62fdfd48a3f44988ac0312678 Mon Sep 17 00:00:00 2001 From: axel Date: Mon, 20 Nov 2006 23:12:24 +1000 Subject: [PATCH] Minor code edit - move a bit of code into its own function darcs-hash:20061120131224-ac50b-974496cc800377e4e06475491f89998b9640fbba.gz --- proc.c | 34 ++++++++++++++++++++++++++++++++++ proc.h | 5 +++++ reader.c | 20 +------------------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/proc.c b/proc.c index af191460c..5476d9707 100644 --- a/proc.c +++ b/proc.c @@ -301,6 +301,40 @@ int job_get_flag( job_t *j, int flag ) return j->flags&flag?1:0; } +int job_signal( job_t *j, int signal ) +{ + pid_t my_pid = getpid(); + int res = 0; + + if( j->pgid != my_pid ) + { + res = killpg( j->pgid, SIGHUP ); + } + else + { + process_t *p; + + for( p = j->first_process; p; p=p->next ) + { + if( ! p->completed ) + { + if( p->pid ) + { + if( kill( p->pid, SIGHUP ) ) + { + res = -1; + break; + } + } + } + } + + } + + return res; + +} + /** Store the status of the process pid that was returned by waitpid. diff --git a/proc.h b/proc.h index cfed6acc6..dd2ee1356 100644 --- a/proc.h +++ b/proc.h @@ -366,6 +366,11 @@ int job_reap( int interactive ); */ void job_handle_signal( int signal, siginfo_t *info, void *con ); +/** + Send the specified signal to all processes in the specified job. +*/ +int job_signal( job_t *j, int signal ); + #ifdef HAVE__PROC_SELF_STAT /** Use the procfs filesystem to look up how many jiffies of cpu time diff --git a/reader.c b/reader.c index 2a2b7cf59..9cf71b6f6 100644 --- a/reader.c +++ b/reader.c @@ -1918,29 +1918,11 @@ static int read_i() } else { - pid_t my_pid = getpid(); for( j = first_job; j; j=j->next ) { if( ! job_is_completed( j ) ) { - if( j->pgid != my_pid ) - { - killpg( j->pgid, SIGHUP ); - } - else - { - process_t *p; - for( p = j->first_process; p; p=p->next ) - { - if( ! p->completed ) - { - if( p->pid ) - { - kill( p->pid, SIGHUP ); - } - } - } - } + job_signal( j, SIGHUP ); } } }