utils: add patch_fd() and patch_stdio() helpers
authorJo-Philipp Wich <jo@mein.io>
Tue, 17 May 2016 15:00:43 +0000 (17:00 +0200)
committerJohn Crispin <john@phrozen.org>
Mon, 16 May 2016 18:59:59 +0000 (20:59 +0200)
Introduce two new helper functions to deal with stdio redirecation in a
uniform, reliable manner:

The patch_fd() function will attempt to redirect the given fd number to the
specified file, using the supplied flags for the open() syscall. When the
device is NULL, "/dev/null" is asumed, when the device is a relative path,
openat() is used to open it relative to the "/dev" directory. When the device
cannot be openend, a fallback to "/dev/null" is attempted.

The patch_stdio() function is essentially a wrapper around patch_fd(),
providing an easy interface to redirect stdin, stdout and stderr to the same
given device.

Both function return 0 on success and -1 on error. The errno variable will
be set accordingly.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>

No differences found