Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Oct 2010 10:47:21 +0300
From:      Mikolaj Golub <to.my.trociny@gmail.com>
To:        freebsd-fs@freebsd.org
Cc:        Pawel Jakub Dawidek <pjd@freebsd.org>
Subject:   hastd: hooks run with masked signals
Message-ID:  <86eibq60l2.fsf@kopusha.home.net>

next in thread | raw e-mail | index | archive | help
--=-=-=

Hi,

Main hastd process uses sigprocmask(2)/sigtimedwait(2) API. Currently when
a hook is started it inherits signal mask from the main process, so hooks are
run with SIGHUP, SIGINT, SIGTERM and SIGCHLD blocked. This is not an issue for
short living, self exiting processes but if one want to start some daemon by
hook then there is an issue with terminating it. 

Here is a hook to reproduce this:

#!/bin/sh

#DAEMON=/etc/rc.d/bsnmpd
DAEMON=/etc/rc.d/lpd

case $1 in
    start|connect)
        ${DAEMON} onestart
        ;;
    stop|disconnect)
        ${DAEMON} onestop
        ;;
    status)
        ${DAEMON} onestatus
        ;;
    role)
        exit 0
        ;;
    *)
        echo "usage: $0 stop|start|status|role|connect|disconnect"
        exit 1
        ;;
esac

And after connect event we have lpd running with SIGHUP, SIGINT, SIGTERM and
SIGCHLD blocked:

 1396 100075 lpd              HUP      -B
 1396 100075 lpd              INT      -B
 1396 100075 lpd              TERM     -B
 1396 100075 lpd              CHLD     -B

What do you think about the attached patch?

-- 
Mikolaj Golub

--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=hooks.c.sigprocmask.patch

Index: sbin/hastd/hooks.c
===================================================================
--- sbin/hastd/hooks.c	(revision 213902)
+++ sbin/hastd/hooks.c	(working copy)
@@ -355,6 +355,7 @@ hook_execv(const char *path, va_list ap)
 	char *args[64];
 	unsigned int ii;
 	pid_t pid;
+	sigset_t mask;
 
 	assert(hooks_initialized);
 
@@ -382,6 +383,8 @@ hook_execv(const char *path, va_list ap)
 		return;
 	case 0:		/* Child. */
 		descriptors();
+		PJDLOG_VERIFY(sigemptyset(&mask) == 0);
+		PJDLOG_VERIFY(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
 		execv(path, args);
 		pjdlog_errno(LOG_ERR, "Unable to execute %s", path);
 		exit(EX_SOFTWARE);

--=-=-=--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86eibq60l2.fsf>