From owner-freebsd-fs@FreeBSD.ORG Sat Oct 16 07:47:24 2010 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A5E72106564A; Sat, 16 Oct 2010 07:47:24 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 0774C8FC19; Sat, 16 Oct 2010 07:47:23 +0000 (UTC) Received: by bwz16 with SMTP id 16so1889774bwz.13 for ; Sat, 16 Oct 2010 00:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:user-agent:mime-version:content-type; bh=sIxkJOTkRhdxo3ZLg9Xi7WiDlixo6NrBTz0Z4LXS290=; b=GGS6xJ/6IOIj/FPMDOU9m4EMULCZ+2OvuB9LHeSbL8mQ4cnsMsHon3BaL8FrE4wA9O 08RrITW8GPXmTqsKnEKEutBxcq0bB6BQZtKGKGKmvoin4/ICfOilmtacxKS6dtgPGZOI zzVUviqNRiXfEzTMYxzMPsjIHNapP1XOqJVK8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:user-agent:mime-version :content-type; b=yHDNGCT+trAHdDbf6VqkzDoZn1yB0aOt+sa8pAaHgjMEfnAS3uwyB1V9D8yx1V5yze OV990QWkRpLy1wxaY8a1n9el7QTuwR69bFJYHnTld4BbYD8XpGSswK5RSzPG0A6IyXAp kpbNt00mi3A31mN56Cpvxz16gO0qfdsjPyUW8= Received: by 10.204.52.208 with SMTP id j16mr1074796bkg.133.1287215242678; Sat, 16 Oct 2010 00:47:22 -0700 (PDT) Received: from localhost ([95.69.174.185]) by mx.google.com with ESMTPS id r21sm6288093bkj.22.2010.10.16.00.47.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 16 Oct 2010 00:47:21 -0700 (PDT) From: Mikolaj Golub To: freebsd-fs@freebsd.org Date: Sat, 16 Oct 2010 10:47:21 +0300 Message-ID: <86eibq60l2.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Cc: Pawel Jakub Dawidek Subject: hastd: hooks run with masked signals X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Oct 2010 07:47:24 -0000 --=-=-= 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); --=-=-=--