[Cook] deadlock in interrupt() at cook/desist.c:57
Peter Miller
pmiller at opensource.org.au
Fri Nov 20 12:41:53 EST 2009
On Wed, 2009-11-18 at 11:03 -0700, Martin Sebor wrote:
> I've had cook deadlock on me several times. From the stack trace
> and the source code it appears that it calls malloc() from a signal
> handler (invoked in response to SIGINT). Since malloc() is not
> async-signal safe, calling it from signal handlers is unsafe and
> leads to undefined behavior.
Does the attached patch fix the problem for you?
(As a side effect, it makes the interrupt message slightly less
responsive.)
--
Peter Miller <pmiller at opensource.org.au>
-------------- next part --------------
MIME-Version: 1.0
Content-Type: application/aegis-patch
Subject: cook.2.32 - desist vs malloc
Content-Name: cook.2.32.C022.patch
Content-Disposition: attachment; filename=cook.2.32.C022.patch
X-Aegis-Project-Name: cook.2.32
X-Aegis-Change-Number: 22
#
# The desist interrupt handler could sometimes deadlock because it use
# malloc (vis the error message printing functions). This can cause
# processes to hang.
#
# My thanks to Martin Sebor <msebor at gmail.com> for reporting this bug.
#
# Aegis-Change-Set-Begin
# QlpoMzFBWSZTWfVJceUAAE/fgAAQUGWAD0ACDA6/79/qMAFZJINCNCp70U9MVPRMQDRtDUGG
# hkNMmgGIaaaNDRg00Q1GVPDU01PKNNGJp6g2pWheYHghOBpJNO57ciRsFVe7Xv22ELVsEU8+
# s5mIk7sF6N4jYQzi683gR31sD7V16EYxIletAE+6r6mRpoDseVP2bPBxglhPZUEgmNS+9WeV
# epzFEdyxdHrBFeFw+w1r5vyZI9HZRliraYCBDHg7yr7arp30dt/FhC3DMweiBbnijQyR9SNC
# LsRUk8R/PIU8EG7yf2iKlHkqVKjQcYJGzLXCsKrfjAXhmYPrMNvY0TJN2J8Ng63CiwIzNZOG
# BuEj9IWvEgi8o70ssZNYMW6YVTKD+McMzDySiDNs30C706O4VzcEAwLzUKVhdCmhRcAIwImQ
# H5NIZ2pbhE2zHASSGQyzZaXCRpuzMB1skP8XckU4UJD1SXHl
# Aegis-Change-Set-End
#
Index: cook/desist.c
--- cook/desist.c
+++ cook/desist.c
@@ -50,14 +50,7 @@
static RETSIGTYPE
interrupt(int n)
{
- sub_context_ty *scp;
-
- star_eoln();
- desist_flag++;
- scp = sub_context_new();
- sub_var_set(scp, "Name", "%s", safe_strsignal(n));
- error_intl(scp, i18n("interrupted by $name"));
- sub_context_delete(scp);
+ desist_flag = n;
signal(n, interrupt);
}
@@ -79,9 +72,19 @@
{
int result;
- result = (desist_flag != 0);
+ result = desist_flag;
desist_flag = 0;
- return result;
+ if (result != 0)
+ {
+ sub_context_ty *scp;
+
+ star_eoln();
+ scp = sub_context_new();
+ sub_var_set(scp, "Name", "%s", safe_strsignal(result));
+ error_intl(scp, i18n("interrupted by $name"));
+ sub_context_delete(scp);
+ }
+ return (result != 0);
}
More information about the Cook-users
mailing list