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!


regards
ronnie sahlberg



On Thu, Jan 26, 2012 at 8:27 PM, Kevin Wolf <kw...@redhat.com> wrote:
> Am 26.01.2012 10:18, schrieb ronnie sahlberg:
>> Kevin,
>>
>> Collissions are bad, but what about
>>
>> IF ! STRNCMP (filename, "/proc/self/fd/", 14)  THEN
>>          fopen(filename, "r")
>> ELSE
>>         fdopen(atoi(filename+14), "r")
>> FI
>>
>> modulo better validation for the atio() arguments.
>>
>>
>> Probability of anyone using "/proc/self/fd/" as a prefix for normal
>> files is very small.
>> Small enough it will be justifiable to say "do that and you are on your 
>> own". ?
>
> Interesting idea. Maybe that could work.
>
> Kevin

Attachment: 0001-READCONFIG-make-proc-self-fd-a-magic-prefix-to-refer.patch.gz
Description: GNU Zip compressed data

From 65aa496d77b839f1c48745fc5545e3e6772f724c Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <ronniesahlb...@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 <ronniesahlb...@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

Reply via email to