From 2ee2003d564e9c39f62b436690a98721ab640ef0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 7 Nov 2015 12:20:23 +0000 Subject: [PATCH] daemon: Allow --channel fd:N In this case, the daemon has been passed an open file descriptor which it uses directly for the channel. --- daemon/guestfsd.c | 40 +++++++++++++++++++++++----------------- daemon/guestfsd.pod | 5 +++++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 994023db1..0a29aa6b3 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -284,23 +284,29 @@ main (int argc, char *argv[]) int sock; if (!listen_mode) { - sock = open (channel, O_RDWR|O_CLOEXEC); - if (sock == -1) { - fprintf (stderr, - "\n" - "Failed to connect to virtio-serial channel.\n" - "\n" - "This is a fatal error and the appliance will now exit.\n" - "\n" - "Usually this error is caused by either QEMU or the appliance\n" - "kernel not supporting the vmchannel method that the\n" - "libguestfs library chose to use. Please run\n" - "'libguestfs-test-tool' and provide the complete, unedited\n" - "output to the libguestfs developers, either in a bug report\n" - "or on the libguestfs redhat com mailing list.\n" - "\n"); - perror (channel); - exit (EXIT_FAILURE); + if (STRPREFIX (channel, "fd:")) { + if (sscanf (channel+3, "%d", &sock) != 1) + error (EXIT_FAILURE, 0, "cannot parse --channel %s", channel); + } + else { + sock = open (channel, O_RDWR|O_CLOEXEC); + if (sock == -1) { + fprintf (stderr, + "\n" + "Failed to connect to virtio-serial channel.\n" + "\n" + "This is a fatal error and the appliance will now exit.\n" + "\n" + "Usually this error is caused by either QEMU or the appliance\n" + "kernel not supporting the vmchannel method that the\n" + "libguestfs library chose to use. Please run\n" + "'libguestfs-test-tool' and provide the complete, unedited\n" + "output to the libguestfs developers, either in a bug report\n" + "or on the libguestfs redhat com mailing list.\n" + "\n"); + perror (channel); + exit (EXIT_FAILURE); + } } } else { diff --git a/daemon/guestfsd.pod b/daemon/guestfsd.pod index f1672ae0b..d2c3cc745 100644 --- a/daemon/guestfsd.pod +++ b/daemon/guestfsd.pod @@ -54,10 +54,15 @@ Display brief help. =item B<--channel> CHANNEL +=item B<--channel> fd:N + Pass the name of the virtio-serial channel, serial port, etc. over which guestfsd will communicate with the library. If this parameter is not given, then an internal default port is used. +The C form causes guestfsd to use the file descriptor C +directly. + =item B<-l> =item B<--listen>