]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: Add some helpers for forking and synchronizing
authorSean Anderson <seanga2@gmail.com>
Wed, 24 Nov 2021 18:26:15 +0000 (13:26 -0500)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Dec 2021 12:35:59 +0000 (13:35 +0100)
commit783bb52a96e901133662fe93f8671c982db3934a
treea33f095e66fb979da0d3ffd633459a51f1e26727
parent82ea629868122b1c2dc870ae8869af6e6e258edb
unshare: Add some helpers for forking and synchronizing

There is (or rather, will be) a common pattern in unshare like

/* parent */ /* child */
fork()
do_some_work()
sync() wait();
do_more_work();
wait() exit();

where the parent has to do some tasks (unshare(), fork() again, etc)
before the child can do its work. At the moment this is implemented
explicitly with a pipe().

Add some helper functions to abstract this process away. In addition,
switch to eventfd() instead of pipe(). As the man page for eventfd(2)
notes,

> Applications can use an eventfd file descriptor instead of a pipe (see
> pipe(2)) in all cases where a pipe is used simply to signal events. The
> kernel overhead of an eventfd file descriptor is much lower than that of
> a pipe, and only one file descriptor is required (versus the two required
> for a pipe).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
sys-utils/unshare.c