[sheepdog] [PATCH v2] logger: avoid using SIGHUP for detecting death of sheep
Liu Yuan
namei.unix at gmail.com
Tue Jan 21 12:17:18 CET 2014
On Tue, Jan 21, 2014 at 07:32:36PM +0900, Hitoshi Mitake wrote:
> It seems that current method of detecting sheep's death from logger
> process sometimes fails. The SIGHUP is caught as a request of log
> rotation.
>
> The problem comes from that SIGHUP is used for both of log rotation
> request and death detection, and getppid() somestimes returns value
> not equal to 1 when SIGHUP which is caused by the death rises.
>
> This patch lets logger detect death of sheep viapolling. The detection
> mechanism is simple: calling getppid() at the tail of the log flush
> loop every time. It would be enough for practical death detection.
>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
>
> v2: simply break logger's loop when sheep dies
>
> lib/logger.c | 17 ++++-------------
> 1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/lib/logger.c b/lib/logger.c
> index f855ab4..8be2bfd 100644
> --- a/lib/logger.c
> +++ b/lib/logger.c
> @@ -554,17 +554,6 @@ static void crash_handler(int signo)
>
> static void sighup_handler(int signo)
> {
> - if (getppid() == 1)
> - /*
> - * My parent (sheep process) is dead. This SIGHUP is sent
> - * because of prctl(PR_SET_PDEATHSIG, SIGHUP)
> - */
> - return crash_handler(signo);
> -
> - /*
> - * My parent sheep process is still alive, this SIGHUP is a request
> - * for log rotation.
> - */
> rotate_log();
> }
>
> @@ -602,8 +591,6 @@ static void logger(char *log_dir, char *outfile)
> install_crash_handler(crash_handler);
> install_sighandler(SIGHUP, sighup_handler, false);
>
> - prctl(PR_SET_PDEATHSIG, SIGHUP);
> -
> /*
> * we need to check the aliveness of the sheep process since
> * it could die before the logger call prctl.
> @@ -631,6 +618,10 @@ static void logger(char *log_dir, char *outfile)
>
> unblock_sighup();
>
> + if (getppid() == 1)
> + /* My parent (sheep process) is dead. */
> + break;
> +
> sleep(1);
> }
>
> --
> 1.7.10.4
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
Applied thanks
Yuan
More information about the sheepdog
mailing list