From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 9 03:14:54 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 315C4AFB; Wed, 9 Jan 2013 03:14:54 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.10]) by mx1.freebsd.org (Postfix) with ESMTP id E2555DB2; Wed, 9 Jan 2013 03:14:53 +0000 (UTC) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.14.5/8.14.5/NETPLEX) with ESMTP id r093EqVN008066; Tue, 8 Jan 2013 22:14:52 -0500 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.2.7 (mail.netplex.net [204.213.176.10]); Tue, 08 Jan 2013 22:14:52 -0500 (EST) Date: Tue, 8 Jan 2013 22:14:52 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Richard Sharpe Subject: Re: Is it possible to block pending queued RealTime signals (AIO originating)? In-Reply-To: <1357686894.6752.37.camel@localhost.localdomain> Message-ID: References: <1357608470.6752.22.camel@localhost.localdomain> <50EB888A.2030802@freebsd.org> <1357626838.6752.27.camel@localhost.localdomain> <50EBC480.8000306@freebsd.org> <1357661646.6752.30.camel@localhost.localdomain> <1357686894.6752.37.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org, David Xu X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Daniel Eischen List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jan 2013 03:14:54 -0000 On Tue, 8 Jan 2013, Richard Sharpe wrote: > [ ... ] > > Well, it turns out that your suggestion was correct. > > I did some more searching and found another similar suggestion, so I > gave it a whirl, and it works. > > Now, my problem is that Jeremy Allison thinks that it is a fugly hack. > This means that I will probably have big problems getting a patch for > this into Samba. I don't understand why JA thinks this is a hack. Their current method doesn't work, or at least isn't portable. I've tried this on Solaris 10, and it works just as it does in FreeBSD. Test program included after signature. $ ./test_sigprocmask Sending signal 16 Got signal 16, blocked: true Blocking signal 16 using method 0 Handled signal 16, blocked: false Sending signal 16 Got signal 16, blocked: true Blocking signal 16 using method 1 Handled signal 16, blocked: true -- DE #include #include #include #include #include #define SIGNAL_TO_USE SIGUSR1 static int got_signal = 0; static int method = 0; static char * signal_blocked_str(sigset_t *set) { if (sigismember(set, SIGNAL_TO_USE)) return ("true"); else return ("false"); } static void sighandler(int sig, int code, ucontext_t *ucp) { sigset_t set; sigprocmask(SIG_SETMASK, NULL, &set); printf("Got signal %d, blocked: %s\n", SIGNAL_TO_USE, signal_blocked_str(&set)); printf("Blocking signal %d using method %d\n", SIGNAL_TO_USE, method); if (method == 0) { sigaddset(&set, SIGNAL_TO_USE); sigprocmask(SIG_SETMASK, &set, NULL); } else sigaddset(&ucp->uc_sigmask, SIGNAL_TO_USE); got_signal = 1; } int main(int argc, char **argv) { sigset_t mask; struct sigaction act; /* Install the handler. */ sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGNAL_TO_USE); act.sa_handler = sighandler; act.sa_flags = SA_SIGINFO; assert(sigaction(SIGNAL_TO_USE, &act, NULL) == 0); /* Unblock the signal. */ sigemptyset(&mask); sigaddset(&mask, SIGNAL_TO_USE); sigprocmask(SIG_UNBLOCK, &mask, NULL); printf("Sending signal %d\n", SIGNAL_TO_USE); kill(getpid(), SIGNAL_TO_USE); while (got_signal == 0) { sleep(1); } sigprocmask(SIG_SETMASK, NULL, &mask); printf("Handled signal %d, blocked: %s\n\n", SIGNAL_TO_USE, signal_blocked_str(&mask)); method = 1; printf("Sending signal %d\n", SIGNAL_TO_USE); kill(getpid(), SIGNAL_TO_USE); while (got_signal == 0) { sleep(1); } sigprocmask(SIG_SETMASK, NULL, &mask); printf("Handled signal %d, blocked: %s\n", SIGNAL_TO_USE, signal_blocked_str(&mask)); return (0); }