From owner-freebsd-questions@freebsd.org Mon Oct 2 06:34:36 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1403CE37C4C for ; Mon, 2 Oct 2017 06:34:36 +0000 (UTC) (envelope-from ftp51246-2575596@sh4-5.1blu.de) Received: from sh4-5.1blu.de (sh4-5.1blu.de [178.254.11.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D3915813F4 for ; Mon, 2 Oct 2017 06:34:35 +0000 (UTC) (envelope-from ftp51246-2575596@sh4-5.1blu.de) Received: from ftp51246-2575596 by sh4-5.1blu.de with local (Exim 4.86_2) (envelope-from ) id 1dyuJ8-0005l4-2E for freebsd-questions@freebsd.org; Mon, 02 Oct 2017 08:34:26 +0200 Date: Mon, 2 Oct 2017 08:34:26 +0200 From: Matthias Apitz To: freebsd-questions@freebsd.org Subject: no dead-lock when signal handler calls localtime_r() on FreeBSD, but on Linux Message-ID: <20171002063425.GA21552@sh4-5.1blu.de> Reply-To: Matthias Apitz Mail-Followup-To: Matthias Apitz , freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Operating-System: FreeBSD 12.0-CURRENT r314251 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Oct 2017 06:34:36 -0000 Hello, I'm on the way clarifying a deadlock-issue we face on Linux when localtime_r() is called in a signal-handler funtion. If you compile the code attached below with gcc on Linux, the code gives what one deserves: a dead-lock when Ctrl-C is pressed. Interestingly this does not give a dead-lock on my FreeBSD (12-CURRENT) system. I checked our man page sigaction(2) but the function is not in the list of functions which may be called safe in signal-handlern. Any idea, while this does not give a dead-lock on FreeBSD too? Thanks matthias /* * compile with: gcc -Wall -DUNSAFE -o deadlock deadlock.c * to get a dead-lock * */ #include #include #include #include void handler(int signum) { char result[100]; time_t now; struct tm time1; printf("in handler() now calling localtime_r() ...\n"); fflush(stdout); now = time(NULL); localtime_r(&now, &time1); strftime(result, 100, "%T", &time1); printf("... at %s, user pressed Ctrl-C\n", result); } int main (void) { time_t now; struct tm ltime; if (signal(SIGINT, handler) == SIG_IGN) signal(SIGINT, SIG_IGN); now = time(NULL); while(1) { #ifdef UNSAFE localtime_r(&now, <ime); #endif } return 0; } -- Matthias Apitz | /"\ ASCII Ribbon Campaign: E-mail: guru@unixarea.de | \ / - No HTML/RTF in E-mail WWW: http://www.unixarea.de/ | X - No proprietary attachments phone: +49-176-38902045 | / \ - Respect for open standards | en.wikipedia.org/wiki/ASCII_Ribbon_Campaign