Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor
#ccccff
}
#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;
}

...