...
The OpenBSD signal()
man page list a few additional functions that are asynchronous-safe in OpenBSD but "probably not on other systems" including: snprintf()
, vsnprintf()
, and syslog_r()
(but only when the syslog_data struct
is initialized as a local variable).
...
Compliant
...
Solution
...
Signal
...
handlers
...
should
...
be
...
as
...
concise
...
as
...
possible,
...
ideally
...
unconditionally
...
setting
...
a
...
flag
...
and
...
returning.
...
They
...
may
...
also
...
call
...
the
...
_Exit()
...
function.
Code Block | ||||
---|---|---|---|---|
| =
| |||
}
#include <signal.h>
void int_handler() {
_Exit(0);
}
int main(void) {
char *foo = (char *)malloc(sizeof("Hello World."));
if (foo == NULL) {
/* handle error condition */
}
signal(SIGINT, int_handler);
strcpy(foo, "Hello World.");
puts(foo);
free(foo);
return 0;
}
|
...