Received: from eggs.gnu.org ([208.118.235.92]:41332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3jis-0000eZ-AO for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:50:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3jim-0008Cl-Qv for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:49:45 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:35067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3jim-0008Bo-Ha for qemu-devel@nongnu.org; Sat, 03 Mar 2012 02:49:40 -0500 Received: by mail-pw0-f45.google.com with SMTP id uo5so2128329pbc.4 for ; Fri, 02 Mar 2012 23:49:39 -0800 (PST) From: Ronnie Sahlberg Date: Sat, 3 Mar 2012 18:49:17 +1100 Message-Id: <1330760957-17122-2-git-send-email-ronniesahlberg@gmail.com> In-Reply-To: <1330760957-17122-1-git-send-email-ronniesahlberg@gmail.com> References: <1330760957-17122-1-git-send-email-ronniesahlberg@gmail.com> Subject: [Qemu-devel] [PATCH] READCONFIG: allow /dev/fd/ the file to use for --readconfig List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kwolf@redhat.com Cc: Ronnie Sahlberg On many platforms /dev/fd/ ise used to refer to open filedescriptor of the running process. If we fail to open the provided filename and if the filename starts with '/dev/fd/' then assume this is a platform which do not support these special files. In that case read out the descriptor value from the provided string and fdopen it. This allows to use /dev/fd/ syntax on all platforms, those that do provide this indeface in /dev and an emulation of this for the platforms that do not provide /dev/fd Signed-off-by: Ronnie Sahlberg --- qemu-config.c | 16 +++++++++++++++- qemu-options.hx | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 7d9da78..7abc08d 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -814,9 +814,23 @@ out: int qemu_read_config_file(const char *filename) { - FILE *f = fopen(filename, "r"); + FILE *f; int ret; + f = fopen(filename, "r"); + + if (f == NULL && strncmp(filename, "/dev/fd/", 8)) { + int fd; + char *ptr = NULL; + + errno = 0; + fd = strtol(filename + 8, &ptr, 10); + if (errno != 0 || ptr == filename + 8 || *ptr != '\0') { + return -EINVAL; + } + f = fdopen(fd, "r"); + } + if (f == NULL) { return -errno; } diff --git a/qemu-options.hx b/qemu-options.hx index b129996..c70c6e7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2650,7 +2650,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 '/dev/fd/' as filename +to read from an existing, inherited, filedesriptor. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig \n" -- 1.7.3.1