[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] daemon: When running external commands, open stdin as /dev/null



On Wed, Nov 04, 2009 at 03:10:27PM +0000, Richard W.M. Jones wrote:
> On Wed, Nov 04, 2009 at 02:49:13PM +0000, Richard W.M. Jones wrote:
> > libguestfs: error: hexdump: hexdump: /test123: hexdump: /sysroot/test123: Bad file descriptor
[...]
> Anyway, I'm still experimenting with this one ...  It might be better
> just to open /dev/null for stdin, since I suppose other programs could
> be unpredictable if they have no stdin at all.

The patch below uses this approach, and I have tested it on Debian and
Fedora.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
>From df1af0bbe21e906c11123e66ec470b60e55c9e44 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones debian5x64 home annexia org>
Date: Wed, 4 Nov 2009 15:47:03 +0000
Subject: [PATCH] daemon: When running external commands, open stdin as /dev/null

Previously when we ran external commands from the daemon, stdin
(ie. fd 0) was closed.  This caused a problem when running the
external hexdump command which seems to break if stdin is closed.

This patch opens stdin on /dev/null.
---
 daemon/guestfsd.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 8c39c39..649a630 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -654,6 +654,7 @@ commandrv (char **stdoutput, char **stderror, char const* const *argv)
 
   if (pid == 0) {		/* Child process. */
     close (0);
+    open ("/dev/null", O_RDONLY); /* Set stdin to /dev/null (ignore failure) */
     close (so_fd[0]);
     close (se_fd[0]);
     dup2 (so_fd[1], 1);
-- 
1.6.5.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]