Bug 86604 - fork() is not async-signal-safe
Summary: fork() is not async-signal-safe
Status: RESOLVED FIXED
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-23 03:19 UTC by Nicholas Miell
Modified: 2014-12-18 05:58 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Nicholas Miell 2014-11-23 03:19:04 UTC
fork() is not async-signal-safe and thus cannot be safely called from a signal handler, the crash handler does this.
Comment 1 Zbigniew Jedrzejewski-Szmek 2014-11-23 05:36:47 UTC
signal(7) lists fork as safe, no?
Comment 2 Nicholas Miell 2014-11-23 05:45:16 UTC
signal(7) is probably out of date, see https://sourceware.org/bugzilla/show_bug.cgi?id=4737 and https://www.opengroup.org/austin/docs/austin_446.txt

Although I guess the removal of fork() from the async-signal-safe list and the addition of posix_spawn() may not be fully ratified yet.

On the other hand, glibc can deadlock if you do it.
Comment 3 Zbigniew Jedrzejewski-Szmek 2014-11-23 06:08:44 UTC
Bugger. The signal handler calls fork twice. Second time to launch a shell, we could use posix_spawn here. But the first time it forks to kill itself and dump core. posix_spawn does not really work for that case.
Comment 4 Lennart Poettering 2014-12-01 01:26:01 UTC
Hmm, I wonder if we can instead just invoke the syscall directly, foregoing glibc's wrapper around it. Of course this would mean to forego most other glibc apis in the child then, too.
Comment 5 David Herrmann 2014-12-15 16:02:24 UTC
Why not use siglongjmp() to leave the signal handler and then fork()?
Comment 6 Nicholas Miell 2014-12-15 18:31:12 UTC
longjmp() and siglongjmp() are themselves not async-signal-safe and thus cannot be called from a signal handler.
Comment 7 Zbigniew Jedrzejewski-Szmek 2014-12-18 05:58:25 UTC
fork() replaced with syscall(__NR_CLONE, ...) in http://cgit.freedesktop.org/systemd/systemd/commit/?id=ee05e7795b. I think this should be OK now.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.