Message ID | CAN05THSkBr6dN+Yn-7FWh5Mj7r6DUqWCwtxWpRzmTV2cddKj6w@mail.gmail.com |
---|---|
State | New |
Headers | show |
26.01.2012 13:54, ronnie sahlberg wrote: > Ok so what about this > > You use a filename starting with "/proc/self/fd/" and you dont have a > proc filesystem mounted? you are on your own! No you're not: >>> IF ! STRNCMP (filename, "/proc/self/fd/", 14) THEN >>> fopen(filename, "r") >>> ELSE >>> fdopen(atoi(filename+14), "r") >>> FI If the filename starts with /proc/self/fd/, qemu will not try to open that file but parse the rest of the string as a filedescriptor number. /mjt
On Thu, Jan 26, 2012 at 08:54:11PM +1100, ronnie sahlberg wrote: > Ok so what about this > > You use a filename starting with "/proc/self/fd/" and you dont have a > proc filesystem mounted? you are on your own! IMHO that would be bad - turning what could easily be a platform neutral feature into one that only works on Linux, just to avoid dealing with command line parsing properly. Regards, Daniel
26.01.2012 18:55, Michael Tokarev wrote: > 26.01.2012 13:54, ronnie sahlberg wrote: >> Ok so what about this >> >> You use a filename starting with "/proc/self/fd/" and you dont have a >> proc filesystem mounted? you are on your own! BTW, usual idiom (which was implemented in gawk for example) is to use /dev/fd/N here, not /proc/self/fd/N which is really linux-specific. Linux traditionally had that symlinked to /proc/self/fd, so it should work as is on linux too. (I think /dev/fd/N is more widely used than /proc/self/fd -- solaris? *bsd?) /mjt > No you're not: > >>>> IF ! STRNCMP (filename, "/proc/self/fd/", 14) THEN >>>> fopen(filename, "r") >>>> ELSE >>>> fdopen(atoi(filename+14), "r") >>>> FI > > If the filename starts with /proc/self/fd/, qemu will > not try to open that file but parse the rest of the > string as a filedescriptor number. > > /mjt >
From 65aa496d77b839f1c48745fc5545e3e6772f724c Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg <ronniesahlberg@gmail.com> Date: Thu, 26 Jan 2012 20:47:40 +1100 Subject: [PATCH] READCONFIG: make /proc/self/fd/ a magic prefix to refer to a specific filedesriptor inherited from the parent. Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com> --- qemu-config.c | 16 ++++++++++++++-- qemu-options.hx | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index b030205..9e709d4 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -770,8 +770,20 @@ out: int qemu_read_config_file(const char *filename) { - FILE *f = fopen(filename, "r"); - int ret; + FILE *f; + int ret, fd; + char *ptr = NULL; + + if (strncmp(filename, "/proc/self/fd/", 14)) { + f = fopen(filename, "r"); + } else { + errno = 0; + fd = strtol(filename + 14, &ptr, 10); + if (errno != 0 || ptr == filename + 14 || *ptr != '\0') { + return -EINVAL; + } + f = fdopen(fd, "r"); + } if (f == NULL) { return -errno; diff --git a/qemu-options.hx b/qemu-options.hx index 3a07ae8..e54af58 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2577,7 +2577,8 @@ DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, STEXI @item -readconfig @var{file} @findex -readconfig -Read device configuration from @var{file}. +Read device configuration from @var{file}. Use '/proc/self/fd/<n>' as filename +to read from an existing, inherited, filedesriptor. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig <file>\n" -- 1.7.3.1