mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-27 21:10:29 +00:00
Fix flakes in runitd and popen_test
This commit is contained in:
parent
801224df67
commit
2ebc5781a1
18 changed files with 123 additions and 34 deletions
|
@ -34,17 +34,27 @@
|
|||
#include "libc/thread/tls.h"
|
||||
|
||||
textwindows int _check_interrupts(bool restartable, struct Fd *fd) {
|
||||
int rc;
|
||||
int e, rc;
|
||||
e = errno;
|
||||
if (_weaken(pthread_testcancel_np) &&
|
||||
(rc = _weaken(pthread_testcancel_np)())) {
|
||||
errno = rc;
|
||||
return -1;
|
||||
}
|
||||
if (_weaken(_check_sigalrm)) _weaken(_check_sigalrm)();
|
||||
if (!__tls_enabled || !(__get_tls()->tib_flags & TIB_FLAG_TIME_CRITICAL)) {
|
||||
if (_weaken(_check_sigchld)) _weaken(_check_sigchld)();
|
||||
if (fd && _weaken(_check_sigwinch)) _weaken(_check_sigwinch)(fd);
|
||||
if (_weaken(_check_sigalrm)) {
|
||||
_weaken(_check_sigalrm)();
|
||||
}
|
||||
if (_weaken(__sig_check) && _weaken(__sig_check)(restartable)) return eintr();
|
||||
if (!__tls_enabled || !(__get_tls()->tib_flags & TIB_FLAG_TIME_CRITICAL)) {
|
||||
if (_weaken(_check_sigchld)) {
|
||||
_weaken(_check_sigchld)();
|
||||
}
|
||||
if (fd && _weaken(_check_sigwinch)) {
|
||||
_weaken(_check_sigwinch)(fd);
|
||||
}
|
||||
}
|
||||
if (_weaken(__sig_check) && _weaken(__sig_check)(restartable)) {
|
||||
return eintr();
|
||||
}
|
||||
errno = e;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -479,6 +479,15 @@ static int __sigaction(int sig, const struct sigaction *act,
|
|||
* frequently calling sigprocmask() out of an abundance of caution, will
|
||||
* no longer need to pay its outrageous cost.
|
||||
*
|
||||
* Signal handlers should avoid clobbering global variables like `errno`
|
||||
* because most signals are asynchronous, i.e. the signal handler might
|
||||
* be called at any assembly instruction. If something like a `SIGCHLD`
|
||||
* handler doesn't save / restore the `errno` global when calling wait,
|
||||
* then any i/o logic in the main program that checks `errno` will most
|
||||
* likely break. This is rare in practice, since systems usually design
|
||||
* signals to favor delivery from cancellation points before they block
|
||||
* however that's not guaranteed.
|
||||
*
|
||||
* @return 0 on success or -1 w/ errno
|
||||
* @see xsigaction() for a much better api
|
||||
* @asyncsignalsafe
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue