From: Ronnie Sahlberg <ronniesahlberg@gmail.com>
To: qemu-devel@nongnu.org, kwolf@redhat.com
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: [Qemu-devel] [PATCH] READCONFIG: allow /dev/fd/ the file to use for --readconfig
Date: Sat, 3 Mar 2012 18:49:17 +1100 [thread overview]
Message-ID: <1330760957-17122-2-git-send-email-ronniesahlberg@gmail.com> (raw)
In-Reply-To: <1330760957-17122-1-git-send-email-ronniesahlberg@gmail.com>
On many platforms /dev/fd/<n> ise used to refer to open filedescriptor <n> 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/<n> 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 <ronniesahlberg@gmail.com>
---
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/<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
next prev parent reply other threads:[~2012-03-03 7:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-03 7:49 [Qemu-devel] [PATCH] readconfig: add emulation of /dev/fd/ to platforms that that lacks this API Ronnie Sahlberg
2012-03-03 7:49 ` Ronnie Sahlberg [this message]
2012-03-19 16:43 ` Anthony Liguori
2012-03-20 8:02 ` ronnie sahlberg
-- strict thread matches above, loose matches on Subject: below --
2012-03-03 7:57 Ronnie Sahlberg
2012-03-03 7:57 ` [Qemu-devel] [PATCH] READCONFIG: allow /dev/fd/ the file to use for --readconfig Ronnie Sahlberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1330760957-17122-2-git-send-email-ronniesahlberg@gmail.com \
--to=ronniesahlberg@gmail.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).