7 ms·
The fish shell http://fishshell.com http://fishshell.com is multithreaded and calls fork, so it can be done. But it is difficult, even if you just call execve()
by ridiculous_fish 12y ago
The fish shell http://fishshell.com http://fishshell.com is multithreaded and calls fork, so it can be done. But it is difficult, even if you just call execve().
An example of a problem we encountered: what if execve() fails? Then we want to print an error message, based on the value of errno. perror() is the preferred way to do this. But on Linux, perror() calls into gettext to show a localized message, and gettext takes a lock, and then you deadlock.
This is a hard problem to solve because it requires knowing the status of all locks. This breaks the abstractions that library authors present, where locks are internal and not exposed.
- ben0x539 12y agoIsn't it easier to have the parent print the error message by passing yet another pipe to the child that closes on exec and can be used to pass up errno?
- ridiculous_fish 12y agoThat's a good idea! I'm not sure if it's easier but it would effectively sidestep this class of issues.
- bdonlan 12y agoYou could also use an inherited shared memory segment (an anonymous mmap with MAP_SHARED) to report failure codes. Since you only need to set this up once, it could result in lower overhead than creating pipes for every exec.