On 07/11/2017 03:40 PM, Peter Maydell wrote: >>> >>> The problem is you can only bail while you're in the parent >>> before forking. Once you've started the child there's no >>> mechanism for dealing with failure. >> >> Well, you can always exit the child before anything worse can happen. > > You need a mechanism then for causing the parent to notice. > The current code would leave the parent in a blocking > accept() call forever (this is what all the XXX comments > in the current code are about).
You can have the parent create a pipe before forking and does a blocking read, the child then manages fds and writes success (or failure) to its end of the pipe (or an early exit causes the parent to read EOF); when the parent finally gets word on the pipe, then it knows whether the child is dead-on-arrival due to early setup failures, or whether it is now safe to block on accept(). But it can easily get more and more complex the more you want to handle; and if the parent is multi-threaded, you have to be careful that you only call async-signal-safe functions in the child between the fork and exec. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature