From b59f5ccb64e61ca595d394160971fbf28c59b3e2 Mon Sep 17 00:00:00 2001 From: Manoj Kasichainula Date: Tue, 3 Aug 1999 23:36:43 +0000 Subject: [PATCH] Fix a couple of potential graceful restart bugs noted by Dean: EINTR was never dealt with in the code to write to the pipe of death, and in pathological cases where the number of processes is greater than PIPE_BUF, we could end up only killing some processes. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83563 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/dexter/dexter.c | 15 ++++++++++++--- server/mpm/mpmt_pthread/mpmt_pthread.c | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 55b0c01951..00ac1525db 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -1404,7 +1404,7 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) } if (is_graceful) { - int i; + int i, bytes_to_write; char char_of_death = '!'; ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, server_conf, @@ -1420,8 +1420,17 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) } } /* give the children the signal to die */ - if (write(pipe_of_death[1], &char_of_death, num_daemons) == -1) { - ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "write pipe_of_death"); + /* XXX - This while loop logic should be made into a utility function */ + bytes_to_write = num_daemons; + while (bytes_to_write > 0) { + i = write(pipe_of_death[1], &char_of_death, bytes_to_write); + if (i == -1) { + if (errno == EINTR) continue; + ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, + "write pipe_of_death"); + break; + } + bytes_to_write -= i; } } else { diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index e8cf350ab4..ddb10e71b2 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -1463,7 +1463,7 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) update_scoreboard_global(); if (is_graceful) { - int i, j; + int i, j, bytes_to_write; char char_of_death = '!'; ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, server_conf, @@ -1472,8 +1472,17 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) /* give the children the signal to die. Sending more bytes than * children is okay, because the pipe is recreated for every * generation */ - if (write(pipe_of_death[1], &char_of_death, ap_daemons_limit) == -1) { - ap_log_error(APLOG_MARK, APLOG_WARNING, server_conf, "write pipe_of_death"); + /* XXX - This while loop logic should be made into a utility function */ + bytes_to_write = ap_daemons_limit; + while (bytes_to_write > 0) { + i = write(pipe_of_death[1], &char_of_death, bytes_to_write); + if (i == -1) { + if (errno == EINTR) continue; + ap_log_error(APLOG_MARK, APLOG_WARNING, server_conf, + "write pipe_of_death"); + break; + } + bytes_to_write -= i; } /* This is mostly for debugging... so that we know what is still -- 2.50.1