Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> it's not safe to do anything more complex than setting a flag

Though I generally agree with the sentiment, there are other limited but still useful things you can do, for example write() is allowed:

    const char msg[] = "\ncaught signal, finishing..\n";
    write(2, msg, sizeof(msg)); // 1 == stdout, 2 == stderr


Which is how the infamous self-pipe trick works: https://cr.yp.to/docs/selfpipe.html

Nowadays signalfd and pidfd are the better options.


write is async signal-safe, but you should save errno before the write and restore it afterward...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: