Comment by monocasa
4 years ago
> fork() -> fork bombs -> fork() is a footgun!
> You have to know how to use it. Yes. So what?
No, you have to own everything that you could call. For one example of many, are you in and out of a library that longjump's? That's really fun.
Basically vfork's sharing of the full on mutable stack between the parent and child is full on bananers.
> Links or it didn't happen :)
You know that some people write proprietary code, even for unixen, right?
> No, you have to own everything that you could call. For one example of many, are you in and out of a library that longjump's? That's really fun.
That is also true of fork().
You're supposed to only use async-signal-safe functions on the child-side of fork().
It is surprisingly easy to do dumb things with fork().
> You know that some people write proprietary code, even for unixen, right?
I was hoping it was in open source code.
> That is also true of fork().
> You're supposed to only use async-signal-safe functions on the child-side of fork().
Not practically, there's way more code out there designed day one for fork(). Next to none designed for vfork() explicitly.
Signal safety has more to do with shared mutability, which isn't a concern for fork. You can get into gross situations mixing fork and threads, but that's equally true of vfork.
> Signal safety has more to do with shared mutability, which isn't a concern for fork.
And yet that's what the spec says about child-side code following fork(). There's a reason for that. It's not just about signals. Async-signal-safe means, yes, that you can use it in an asynchronous signal handler, but there are contexts other than async signal handlers that require async-signal-safe code.
> You can get into gross situations mixing fork and threads...
You can get into bad situations just using fork and no threads.
> Not practically, there's way more code out there designed day one for fork(). Next to none designed for vfork() explicitly.
The adjustments needed to make fork-using code use vfork instead are often small. I recently did that to existing code: https://github.com/heimdal/heimdal/pull/957/commits
3 replies →