From 04b4e75f33ae0775d70b8e33080f46d66275cdcc Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Thu, 10 May 2012 16:50:41 -0300 Subject: qemu-ga: make reopen_fd_to_null() public The next commit wants to use it. Signed-off-by: Luiz Capitulino Reviewed-by: Eric Blake Signed-off-by: Michael Roth --- qemu-ga.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'qemu-ga.c') diff --git a/qemu-ga.c b/qemu-ga.c index cf61cb95e5..8d53e04a0f 100644 --- a/qemu-ga.c +++ b/qemu-ga.c @@ -140,6 +140,23 @@ static gboolean register_signal_handlers(void) return true; } + +/* TODO: use this in place of all post-fork() fclose(std*) callers */ +void reopen_fd_to_null(int fd) +{ + int nullfd; + + nullfd = open("/dev/null", O_RDWR); + if (nullfd < 0) { + return; + } + + dup2(nullfd, fd); + + if (nullfd != fd) { + close(nullfd); + } +} #endif static void usage(const char *cmd) -- cgit v1.2.3