From 81977b773bcff2c07f476c5ff3126323145480ae Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 21 Sep 2006 11:14:45 +0200 Subject: [PATCH] server: Kill the process without SIGTERM when the fd socket is closed. --- server/process.c | 40 ++++++++++++++++++++++++++++------------ server/process.h | 2 +- server/request.c | 12 ++++++------ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/server/process.c b/server/process.c index b36ca370852..c50641b5e76 100644 --- a/server/process.c +++ b/server/process.c @@ -408,7 +408,7 @@ static void process_poll_event( struct fd *fd, int event ) process->sigkill_timeout = NULL; process_died( process ); } - else kill_process( process, NULL, 0 ); + else kill_process( process, 0 ); } else if (event & POLLIN) receive_fd( process ); } @@ -512,6 +512,20 @@ static void process_unload_dll( struct process *process, void *base ) else set_error( STATUS_INVALID_PARAMETER ); } +/* terminate a process with the given exit code */ +static void terminate_process( struct process *process, struct thread *skip, int exit_code ) +{ + struct list *ptr, *next; + + LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list ) + { + struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); + + if (exit_code) thread->exit_code = exit_code; + if (thread != skip) kill_thread( thread, 1 ); + } +} + /* kill all processes */ void kill_all_processes( struct process *skip, int exit_code ) { @@ -525,7 +539,7 @@ void kill_all_processes( struct process *skip, int exit_code ) if (process->running_threads) break; } if (&process->entry == &process_list) break; /* no process found */ - kill_process( process, NULL, exit_code ); + terminate_process( process, NULL, exit_code ); } } @@ -544,7 +558,7 @@ void kill_console_processes( struct thread *renderer, int exit_code ) if (process->console && process->console->renderer == renderer) break; } if (&process->entry == &process_list) break; /* no process found */ - kill_process( process, NULL, exit_code ); + terminate_process( process, NULL, exit_code ); } } @@ -638,16 +652,18 @@ void resume_process( struct process *process ) } /* kill a process on the spot */ -void kill_process( struct process *process, struct thread *skip, int exit_code ) +void kill_process( struct process *process, int violent_death ) { - struct list *ptr, *next; - - LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list ) + if (violent_death) terminate_process( process, NULL, 1 ); + else { - struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); + struct list *ptr, *next; - if (exit_code) thread->exit_code = exit_code; - if (thread != skip) kill_thread( thread, 1 ); + LIST_FOR_EACH_SAFE( ptr, next, &process->thread_list ) + { + struct thread *thread = LIST_ENTRY( ptr, struct thread, proc_entry ); + kill_thread( thread, 0 ); + } } } @@ -666,7 +682,7 @@ void kill_debugged_processes( struct thread *debugger, int exit_code ) } if (&process->entry == &process_list) break; /* no process found */ process->debugger = NULL; - kill_process( process, NULL, exit_code ); + terminate_process( process, NULL, exit_code ); } } @@ -960,7 +976,7 @@ DECL_HANDLER(terminate_process) if ((process = get_process_from_handle( req->handle, PROCESS_TERMINATE ))) { reply->self = (current->process == process); - kill_process( process, current, req->exit_code ); + terminate_process( process, current, req->exit_code ); release_object( process ); } } diff --git a/server/process.h b/server/process.h index c447e2f5bbf..af84719d64d 100644 --- a/server/process.h +++ b/server/process.h @@ -120,7 +120,7 @@ extern void remove_process_thread( struct process *process, extern void suspend_process( struct process *process ); extern void resume_process( struct process *process ); extern void kill_all_processes( struct process *skip, int exit_code ); -extern void kill_process( struct process *process, struct thread *skip, int exit_code ); +extern void kill_process( struct process *process, int violent_death ); extern void kill_console_processes( struct thread *renderer, int exit_code ); extern void kill_debugged_processes( struct thread *debugger, int exit_code ); extern void break_process( struct process *process ); diff --git a/server/request.c b/server/request.c index ac5a696e7a7..b0cebd5787d 100644 --- a/server/request.c +++ b/server/request.c @@ -402,13 +402,13 @@ int receive_fd( struct process *process ) if (!ret) { - kill_process( process, NULL, 0 ); + kill_process( process, 0 ); } else if (ret > 0) { fprintf( stderr, "Protocol error: process %04x: partial recvmsg %d for fd\n", process->id, ret ); - kill_process( process, NULL, 1 ); + kill_process( process, 1 ); } else { @@ -416,7 +416,7 @@ int receive_fd( struct process *process ) { fprintf( stderr, "Protocol error: process %04x: ", process->id ); perror( "recvmsg" ); - kill_process( process, NULL, 1 ); + kill_process( process, 1 ); } } return -1; @@ -450,17 +450,17 @@ int send_client_fd( struct process *process, int fd, obj_handle_t handle ) if (ret >= 0) { fprintf( stderr, "Protocol error: process %04x: partial sendmsg %d\n", process->id, ret ); - kill_process( process, NULL, 1 ); + kill_process( process, 1 ); } else if (errno == EPIPE) { - kill_process( process, NULL, 0 ); + kill_process( process, 0 ); } else { fprintf( stderr, "Protocol error: process %04x: ", process->id ); perror( "sendmsg" ); - kill_process( process, NULL, 1 ); + kill_process( process, 1 ); } return -1; }