All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 00/17] clean up vl.c code
@ 2010-06-10  9:42 Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris Jes.Sorensen
                   ` (17 more replies)
  0 siblings, 18 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

v4 of the vl.c clean up patch. This one just fixes a merge conflict
due to some recent changes to vl.c, and I added the Acked-By: lines I
received for v3. Consider it a house-keeping update to make it easier
to merge.

The patches try to clean up the vl.c code by separating out OS
specific code into OS specific files. Basically it is focused on
moving things into os-posix.c for most UNIX/Linux systems, and
os-win32.c for win32 specific bits.

Cheers,
Jes


Jes Sorensen (17):
  vl.c: Remove double include of netinet/in.h for Solaris
  Create qemu-os-win32.h and move WIN32 specific declarations there
  Introduce os-win32.c and move polling functions from vl.c
  vl.c: Move host_main_loop_wait() to OS specific files.
  Introduce os-posix.c and create os_setup_signal_handling()
  Move win32 early signal handling setup to os_setup_signal_handling()
  Rename os_setup_signal_handling() to os_setup_early_signal_handling()
  Move main signal handler setup to os specificfiles.
  Move find_datadir to OS specific files.
  Rename qemu-options.h to qemu-options.def
  Introduce OS specific cmdline argument handling and move SMB arg to
    os-posix.c
  Move runas handling from vl.c to OS specific files.
  Move chroot handling to OS specific files.
  Move daemonize handling to OS specific files
  Make os_change_process_uid and os_change_root os-posix.c local
  Move line-buffering setup to OS specific files.
  Move set_proc_name() to OS specific files.

 Makefile.objs   |    8 +-
 os-posix.c      |  329 +++++++++++++++++++++++++++++++++++++
 os-win32.c      |  221 +++++++++++++++++++++++++
 qemu-options.h  |   41 +++++
 qemu-os-posix.h |   39 +++++
 qemu-os-win32.h |   52 ++++++
 sysemu.h        |   27 ++--
 vl.c            |  491 ++-----------------------------------------------------
 8 files changed, 713 insertions(+), 495 deletions(-)
 create mode 100644 os-posix.c
 create mode 100644 os-win32.c
 create mode 100644 qemu-options.h
 create mode 100644 qemu-os-posix.h
 create mode 100644 qemu-os-win32.h

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there Jes.Sorensen
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

vl.c: netinet/in.h is already included once above for the

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Andreas Faerber <afaerber@opensolaris.org>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 vl.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 6d08ec8..55fc527 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include <sys/ethernet.h>
 #include <sys/sockio.h>
 #include <netinet/arp.h>
-#include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h> // must come after ip.h
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c Jes.Sorensen
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Create qemu-os-win32.h for WIN32 specific declarations. Move polling
handling declaration into this file from sysemu.h

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 qemu-os-win32.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 sysemu.h        |   17 +----------------
 2 files changed, 44 insertions(+), 16 deletions(-)
 create mode 100644 qemu-os-win32.h

diff --git a/qemu-os-win32.h b/qemu-os-win32.h
new file mode 100644
index 0000000..be108ad
--- /dev/null
+++ b/qemu-os-win32.h
@@ -0,0 +1,43 @@
+/*
+ * win32 specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_WIN32_H
+#define QEMU_OS_WIN32_H
+
+/* Polling handling */
+
+/* return TRUE if no sleep should be done afterwards */
+typedef int PollingFunc(void *opaque);
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque);
+void qemu_del_polling_cb(PollingFunc *func, void *opaque);
+
+/* Wait objects handling */
+typedef void WaitObjectFunc(void *opaque);
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 879446a..13fc9a9 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -9,6 +9,7 @@
 
 #ifdef _WIN32
 #include <windows.h>
+#include "qemu-os-win32.h"
 #endif
 
 /* vl.c */
@@ -71,22 +72,6 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
-#ifdef _WIN32
-/* Polling handling */
-
-/* return TRUE if no sleep should be done afterwards */
-typedef int PollingFunc(void *opaque);
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque);
-void qemu_del_polling_cb(PollingFunc *func, void *opaque);
-
-/* Wait objects handling */
-typedef void WaitObjectFunc(void *opaque);
-
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-#endif
-
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files Jes.Sorensen
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

This introduces os-win32.c. It is meant to carry win32 specific
functions thata are not relevant for all of QEMU as well as win32
versions of various pieces like signal handling etc.

Move win32 polling handler helper functions from vl.c to os-win32.c

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 Makefile.objs |    1 +
 os-win32.c    |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c          |   80 -----------------------------------------
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index 9796dcb..58fdb03 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -144,6 +144,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-$(CONFIG_WIN32) += os-win32.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-win32.c b/os-win32.c
new file mode 100644
index 0000000..5a464cc
--- /dev/null
+++ b/os-win32.c
@@ -0,0 +1,111 @@
+/*
+ * os-win32.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include <windows.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/time.h>
+#include "config-host.h"
+#include "sysemu.h"
+
+/***********************************************************/
+/* Polling handling */
+
+typedef struct PollingEntry {
+    PollingFunc *func;
+    void *opaque;
+    struct PollingEntry *next;
+} PollingEntry;
+
+static PollingEntry *first_polling_entry;
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque)
+{
+    PollingEntry **ppe, *pe;
+    pe = qemu_mallocz(sizeof(PollingEntry));
+    pe->func = func;
+    pe->opaque = opaque;
+    for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
+    *ppe = pe;
+    return 0;
+}
+
+void qemu_del_polling_cb(PollingFunc *func, void *opaque)
+{
+    PollingEntry **ppe, *pe;
+    for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next) {
+        pe = *ppe;
+        if (pe->func == func && pe->opaque == opaque) {
+            *ppe = pe->next;
+            qemu_free(pe);
+            break;
+        }
+    }
+}
+
+/***********************************************************/
+/* Wait objects support */
+typedef struct WaitObjects {
+    int num;
+    HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+    WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+    void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+    WaitObjects *w = &wait_objects;
+
+    if (w->num >= MAXIMUM_WAIT_OBJECTS)
+        return -1;
+    w->events[w->num] = handle;
+    w->func[w->num] = func;
+    w->opaque[w->num] = opaque;
+    w->num++;
+    return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+    int i, found;
+    WaitObjects *w = &wait_objects;
+
+    found = 0;
+    for (i = 0; i < w->num; i++) {
+        if (w->events[i] == handle)
+            found = 1;
+        if (found) {
+            w->events[i] = w->events[i + 1];
+            w->func[i] = w->func[i + 1];
+            w->opaque[i] = w->opaque[i + 1];
+        }
+    }
+    if (found)
+        w->num--;
+}
diff --git a/vl.c b/vl.c
index 55fc527..8927559 100644
--- a/vl.c
+++ b/vl.c
@@ -1497,86 +1497,6 @@ int qemu_set_fd_handler(int fd,
     return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
-#ifdef _WIN32
-/***********************************************************/
-/* Polling handling */
-
-typedef struct PollingEntry {
-    PollingFunc *func;
-    void *opaque;
-    struct PollingEntry *next;
-} PollingEntry;
-
-static PollingEntry *first_polling_entry;
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque)
-{
-    PollingEntry **ppe, *pe;
-    pe = qemu_mallocz(sizeof(PollingEntry));
-    pe->func = func;
-    pe->opaque = opaque;
-    for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
-    *ppe = pe;
-    return 0;
-}
-
-void qemu_del_polling_cb(PollingFunc *func, void *opaque)
-{
-    PollingEntry **ppe, *pe;
-    for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next) {
-        pe = *ppe;
-        if (pe->func == func && pe->opaque == opaque) {
-            *ppe = pe->next;
-            qemu_free(pe);
-            break;
-        }
-    }
-}
-
-/***********************************************************/
-/* Wait objects support */
-typedef struct WaitObjects {
-    int num;
-    HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
-    WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
-    void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
-} WaitObjects;
-
-static WaitObjects wait_objects = {0};
-
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
-{
-    WaitObjects *w = &wait_objects;
-
-    if (w->num >= MAXIMUM_WAIT_OBJECTS)
-        return -1;
-    w->events[w->num] = handle;
-    w->func[w->num] = func;
-    w->opaque[w->num] = opaque;
-    w->num++;
-    return 0;
-}
-
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
-{
-    int i, found;
-    WaitObjects *w = &wait_objects;
-
-    found = 0;
-    for (i = 0; i < w->num; i++) {
-        if (w->events[i] == handle)
-            found = 1;
-        if (found) {
-            w->events[i] = w->events[i + 1];
-            w->func[i] = w->func[i + 1];
-            w->opaque[i] = w->opaque[i + 1];
-        }
-    }
-    if (found)
-        w->num--;
-}
-#endif
-
 /***********************************************************/
 /* machine registration */
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (2 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling() Jes.Sorensen
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move host_main_loop_wait() to OS specific files. Create
qemu-os-posix.h and provide empty inline for the POSIX case.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-win32.c      |   43 +++++++++++++++++++++++++++++++++++++++++++
 qemu-os-posix.h |   33 +++++++++++++++++++++++++++++++++
 qemu-os-win32.h |    1 +
 sysemu.h        |    4 ++++
 vl.c            |   52 +---------------------------------------------------
 5 files changed, 82 insertions(+), 51 deletions(-)
 create mode 100644 qemu-os-posix.h

diff --git a/os-win32.c b/os-win32.c
index 5a464cc..1f7e28b 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
     if (found)
         w->num--;
 }
+
+void os_host_main_loop_wait(int *timeout)
+{
+    int ret, ret2, i;
+    PollingEntry *pe;
+
+    /* XXX: need to suppress polling by better using win32 events */
+    ret = 0;
+    for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
+        ret |= pe->func(pe->opaque);
+    }
+    if (ret == 0) {
+        int err;
+        WaitObjects *w = &wait_objects;
+
+        ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
+        if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
+            if (w->func[ret - WAIT_OBJECT_0])
+                w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
+
+            /* Check for additional signaled events */
+            for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {
+
+                /* Check if event is signaled */
+                ret2 = WaitForSingleObject(w->events[i], 0);
+                if(ret2 == WAIT_OBJECT_0) {
+                    if (w->func[i])
+                        w->func[i](w->opaque[i]);
+                } else if (ret2 == WAIT_TIMEOUT) {
+                } else {
+                    err = GetLastError();
+                    fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);
+                }
+            }
+        } else if (ret == WAIT_TIMEOUT) {
+        } else {
+            err = GetLastError();
+            fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
+        }
+    }
+
+    *timeout = 0;
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
new file mode 100644
index 0000000..96d1036
--- /dev/null
+++ b/qemu-os-posix.h
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_POSIX_H
+#define QEMU_OS_POSIX_H
+
+static inline void os_host_main_loop_wait(int *timeout)
+{
+}
+
+#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index be108ad..4d1cac8 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/sysemu.h b/sysemu.h
index 13fc9a9..5e4feae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -12,6 +12,10 @@
 #include "qemu-os-win32.h"
 #endif
 
+#ifdef CONFIG_POSIX
+#include "qemu-os-posix.h"
+#endif
+
 /* vl.c */
 extern const char *bios_name;
 
diff --git a/vl.c b/vl.c
index 8927559..4097762 100644
--- a/vl.c
+++ b/vl.c
@@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void)
     qemu_notify_event();
 }
 
-#ifdef _WIN32
-static void host_main_loop_wait(int *timeout)
-{
-    int ret, ret2, i;
-    PollingEntry *pe;
-
-
-    /* XXX: need to suppress polling by better using win32 events */
-    ret = 0;
-    for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
-        ret |= pe->func(pe->opaque);
-    }
-    if (ret == 0) {
-        int err;
-        WaitObjects *w = &wait_objects;
-
-        ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
-        if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
-            if (w->func[ret - WAIT_OBJECT_0])
-                w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
-
-            /* Check for additional signaled events */
-            for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {
-
-                /* Check if event is signaled */
-                ret2 = WaitForSingleObject(w->events[i], 0);
-                if(ret2 == WAIT_OBJECT_0) {
-                    if (w->func[i])
-                        w->func[i](w->opaque[i]);
-                } else if (ret2 == WAIT_TIMEOUT) {
-                } else {
-                    err = GetLastError();
-                    fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);
-                }
-            }
-        } else if (ret == WAIT_TIMEOUT) {
-        } else {
-            err = GetLastError();
-            fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
-        }
-    }
-
-    *timeout = 0;
-}
-#else
-static void host_main_loop_wait(int *timeout)
-{
-}
-#endif
-
 void main_loop_wait(int nonblocking)
 {
     IOHandlerRecord *ioh;
@@ -1787,7 +1737,7 @@ void main_loop_wait(int nonblocking)
         qemu_bh_update_timeout(&timeout);
     }
 
-    host_main_loop_wait(&timeout);
+    os_host_main_loop_wait(&timeout);
 
     /* poll any events */
     /* XXX: separate device handlers from system ones */
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling()
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (3 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling() Jes.Sorensen
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Introcuce os-posix.c and move posix specific signal handling
there.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 Makefile.objs   |    1 +
 os-posix.c      |   41 +++++++++++++++++++++++++++++++++++++++++
 qemu-os-posix.h |    2 ++
 vl.c            |    8 +-------
 4 files changed, 45 insertions(+), 7 deletions(-)
 create mode 100644 os-posix.c

diff --git a/Makefile.objs b/Makefile.objs
index 58fdb03..2d94677 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -145,6 +145,7 @@ hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 hw-obj-$(CONFIG_WIN32) += os-win32.o
+hw-obj-$(CONFIG_POSIX) += os-posix.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-posix.c b/os-posix.c
new file mode 100644
index 0000000..914a4d1
--- /dev/null
+++ b/os-posix.c
@@ -0,0 +1,41 @@
+/*
+ * os-posix.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+
+/* Needed early for CONFIG_BSD etc. */
+#include "config-host.h"
+#include "sysemu.h"
+
+void os_setup_signal_handling(void)
+{
+    struct sigaction act;
+    sigfillset(&act.sa_mask);
+    act.sa_flags = 0;
+    act.sa_handler = SIG_IGN;
+    sigaction(SIGPIPE, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/vl.c b/vl.c
index 4097762..29c9697 100644
--- a/vl.c
+++ b/vl.c
@@ -2460,13 +2460,7 @@ int main(int argc, char **argv, char **envp)
 
     QLIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
-    {
-        struct sigaction act;
-        sigfillset(&act.sa_mask);
-        act.sa_flags = 0;
-        act.sa_handler = SIG_IGN;
-        sigaction(SIGPIPE, &act, NULL);
-    }
+    os_setup_signal_handling();
 #else
     SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
     /* Note: cpu_interrupt() is currently not SMP safe, so we force
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling()
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (4 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling() Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling() Jes.Sorensen
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move win32 early signal handling setup to os_setup_signal_handling()

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-win32.c      |   29 +++++++++++++++++++++++++++++
 qemu-os-posix.h |    2 --
 sysemu.h        |    2 ++
 vl.c            |   30 ------------------------------
 4 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 1f7e28b..dfa90bc 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout)
 
     *timeout = 0;
 }
+
+static BOOL WINAPI qemu_ctrl_handler(DWORD type)
+{
+    exit(STATUS_CONTROL_C_EXIT);
+    return TRUE;
+}
+
+void os_setup_signal_handling(void)
+{
+    /* Note: cpu_interrupt() is currently not SMP safe, so we force
+       QEMU to run on a single CPU */
+    HANDLE h;
+    DWORD mask, smask;
+    int i;
+
+    SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+
+    h = GetCurrentProcess();
+    if (GetProcessAffinityMask(h, &mask, &smask)) {
+        for(i = 0; i < 32; i++) {
+            if (mask & (1 << i))
+                break;
+        }
+        if (i != 32) {
+            mask = 1 << i;
+            SetProcessAffinityMask(h, mask);
+        }
+    }
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..96d1036 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,4 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
-void os_setup_signal_handling(void);
-
 #endif
diff --git a/sysemu.h b/sysemu.h
index 5e4feae..e3643ad 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,6 +79,8 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+void os_setup_signal_handling(void);
+
 typedef enum DisplayType
 {
     DT_DEFAULT,
diff --git a/vl.c b/vl.c
index 29c9697..264710d 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg)
     return -1;
 }
 
-#ifdef _WIN32
-static BOOL WINAPI qemu_ctrl_handler(DWORD type)
-{
-    exit(STATUS_CONTROL_C_EXIT);
-    return TRUE;
-}
-#endif
-
 #ifndef _WIN32
 
 static void termsig_handler(int signal)
@@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp)
     qemu_cache_utils_init(envp);
 
     QLIST_INIT (&vm_change_state_head);
-#ifndef _WIN32
     os_setup_signal_handling();
-#else
-    SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-    /* Note: cpu_interrupt() is currently not SMP safe, so we force
-       QEMU to run on a single CPU */
-    {
-        HANDLE h;
-        DWORD mask, smask;
-        int i;
-        h = GetCurrentProcess();
-        if (GetProcessAffinityMask(h, &mask, &smask)) {
-            for(i = 0; i < 32; i++) {
-                if (mask & (1 << i))
-                    break;
-            }
-            if (i != 32) {
-                mask = 1 << i;
-                SetProcessAffinityMask(h, mask);
-            }
-        }
-    }
-#endif
 
     module_call_init(MODULE_INIT_MACHINE);
     machine = find_default_machine();
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling()
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (5 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling() Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles Jes.Sorensen
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Rename os_setup_signal_handling() to os_setup_early_signal_handling()

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c |    2 +-
 os-win32.c |    2 +-
 sysemu.h   |    2 +-
 vl.c       |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 914a4d1..948f662 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -31,7 +31,7 @@
 #include "config-host.h"
 #include "sysemu.h"
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
     struct sigaction act;
     sigfillset(&act.sa_mask);
diff --git a/os-win32.c b/os-win32.c
index dfa90bc..a936f7a 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -159,7 +159,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
     return TRUE;
 }
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
     /* Note: cpu_interrupt() is currently not SMP safe, so we force
        QEMU to run on a single CPU */
diff --git a/sysemu.h b/sysemu.h
index e3643ad..bb05cf4 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,7 +79,7 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-void os_setup_signal_handling(void);
+void os_setup_early_signal_handling(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 264710d..a8fcb65 100644
--- a/vl.c
+++ b/vl.c
@@ -2451,7 +2451,7 @@ int main(int argc, char **argv, char **envp)
     qemu_cache_utils_init(envp);
 
     QLIST_INIT (&vm_change_state_head);
-    os_setup_signal_handling();
+    os_setup_early_signal_handling();
 
     module_call_init(MODULE_INIT_MACHINE);
     machine = find_default_machine();
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (6 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling() Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files Jes.Sorensen
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move main signal handler setup to os specific files.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |   27 +++++++++++++++++++++++++++
 qemu-os-posix.h |    2 ++
 qemu-os-win32.h |    3 +++
 vl.c            |   33 +--------------------------------
 4 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 948f662..01dbec2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -26,6 +26,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -39,3 +41,28 @@ void os_setup_early_signal_handling(void)
     act.sa_handler = SIG_IGN;
     sigaction(SIGPIPE, &act, NULL);
 }
+
+static void termsig_handler(int signal)
+{
+    qemu_system_shutdown_request();
+}
+
+static void sigchld_handler(int signal)
+{
+    waitpid(-1, NULL, WNOHANG);
+}
+
+void os_setup_signal_handling(void)
+{
+    struct sigaction act;
+
+    memset(&act, 0, sizeof(act));
+    act.sa_handler = termsig_handler;
+    sigaction(SIGINT,  &act, NULL);
+    sigaction(SIGHUP,  &act, NULL);
+    sigaction(SIGTERM, &act, NULL);
+
+    act.sa_handler = sigchld_handler;
+    act.sa_flags = SA_NOCLDSTOP;
+    sigaction(SIGCHLD, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 4d1cac8..e7e2ee3 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -41,4 +41,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
 void os_host_main_loop_wait(int *timeout);
+
+static inline void os_setup_signal_handling(void) {}
+
 #endif
diff --git a/vl.c b/vl.c
index a8fcb65..1fd839d 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,35 +1986,6 @@ static int balloon_parse(const char *arg)
     return -1;
 }
 
-#ifndef _WIN32
-
-static void termsig_handler(int signal)
-{
-    qemu_system_shutdown_request();
-}
-
-static void sigchld_handler(int signal)
-{
-    waitpid(-1, NULL, WNOHANG);
-}
-
-static void sighandler_setup(void)
-{
-    struct sigaction act;
-
-    memset(&act, 0, sizeof(act));
-    act.sa_handler = termsig_handler;
-    sigaction(SIGINT,  &act, NULL);
-    sigaction(SIGHUP,  &act, NULL);
-    sigaction(SIGTERM, &act, NULL);
-
-    act.sa_handler = sigchld_handler;
-    act.sa_flags = SA_NOCLDSTOP;
-    sigaction(SIGCHLD, &act, NULL);
-}
-
-#endif
-
 #ifdef _WIN32
 /* Look for support files in the same directory as the executable.  */
 static char *find_datadir(const char *argv0)
@@ -3556,10 +3527,8 @@ int main(int argc, char **argv, char **envp)
 
     cpu_synchronize_all_post_init();
 
-#ifndef _WIN32
     /* must be after terminal init, SDL library changes signal handlers */
-    sighandler_setup();
-#endif
+    os_setup_signal_handling();
 
     set_numa_modes();
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (7 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def Jes.Sorensen
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

This moves the win32 and POSIX versions of find_datadir() to OS
specific files, and removes some #ifdef clutter from vl.c

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c |   64 ++++++++++++++++++++++++++++++++++++++++++
 os-win32.c |   23 +++++++++++++++
 sysemu.h   |    2 +
 vl.c       |   91 +-----------------------------------------------------------
 4 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 01dbec2..621ad06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <libgen.h>
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -66,3 +67,66 @@ void os_setup_signal_handling(void)
     act.sa_flags = SA_NOCLDSTOP;
     sigaction(SIGCHLD, &act, NULL);
 }
+
+/* Find a likely location for support files using the location of the binary.
+   For installed binaries this will be "$bindir/../share/qemu".  When
+   running from the build tree this will be "$bindir/../pc-bios".  */
+#define SHARE_SUFFIX "/share/qemu"
+#define BUILD_SUFFIX "/pc-bios"
+char *os_find_datadir(const char *argv0)
+{
+    char *dir;
+    char *p = NULL;
+    char *res;
+    char buf[PATH_MAX];
+    size_t max_len;
+
+#if defined(__linux__)
+    {
+        int len;
+        len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+        if (len > 0) {
+            buf[len] = 0;
+            p = buf;
+        }
+    }
+#elif defined(__FreeBSD__)
+    {
+        static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+        size_t len = sizeof(buf) - 1;
+
+        *buf = '\0';
+        if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) &&
+            *buf) {
+            buf[sizeof(buf) - 1] = '\0';
+            p = buf;
+        }
+    }
+#endif
+    /* If we don't have any way of figuring out the actual executable
+       location then try argv[0].  */
+    if (!p) {
+        p = realpath(argv0, buf);
+        if (!p) {
+            return NULL;
+        }
+    }
+    dir = dirname(p);
+    dir = dirname(dir);
+
+    max_len = strlen(dir) +
+        MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
+    res = qemu_mallocz(max_len);
+    snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
+    if (access(res, R_OK)) {
+        snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
+        if (access(res, R_OK)) {
+            qemu_free(res);
+            res = NULL;
+        }
+    }
+
+    return res;
+}
+#undef SHARE_SUFFIX
+#undef BUILD_SUFFIX
diff --git a/os-win32.c b/os-win32.c
index a936f7a..1758538 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -181,3 +181,26 @@ void os_setup_early_signal_handling(void)
         }
     }
 }
+
+/* Look for support files in the same directory as the executable.  */
+char *os_find_datadir(const char *argv0)
+{
+    char *p;
+    char buf[MAX_PATH];
+    DWORD len;
+
+    len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
+    if (len == 0) {
+        return NULL;
+    }
+
+    buf[len] = 0;
+    p = buf + len - 1;
+    while (p != buf && *p != '\\')
+        p--;
+    *p = 0;
+    if (access(buf, R_OK) == 0) {
+        return qemu_strdup(buf);
+    }
+    return NULL;
+}
diff --git a/sysemu.h b/sysemu.h
index bb05cf4..72f3734 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,7 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+/* OS specific functions */
 void os_setup_early_signal_handling(void);
+char *os_find_datadir(const char *argv0);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 1fd839d..3e56121 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,95 +1986,6 @@ static int balloon_parse(const char *arg)
     return -1;
 }
 
-#ifdef _WIN32
-/* Look for support files in the same directory as the executable.  */
-static char *find_datadir(const char *argv0)
-{
-    char *p;
-    char buf[MAX_PATH];
-    DWORD len;
-
-    len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
-    if (len == 0) {
-        return NULL;
-    }
-
-    buf[len] = 0;
-    p = buf + len - 1;
-    while (p != buf && *p != '\\')
-        p--;
-    *p = 0;
-    if (access(buf, R_OK) == 0) {
-        return qemu_strdup(buf);
-    }
-    return NULL;
-}
-#else /* !_WIN32 */
-
-/* Find a likely location for support files using the location of the binary.
-   For installed binaries this will be "$bindir/../share/qemu".  When
-   running from the build tree this will be "$bindir/../pc-bios".  */
-#define SHARE_SUFFIX "/share/qemu"
-#define BUILD_SUFFIX "/pc-bios"
-static char *find_datadir(const char *argv0)
-{
-    char *dir;
-    char *p = NULL;
-    char *res;
-    char buf[PATH_MAX];
-    size_t max_len;
-
-#if defined(__linux__)
-    {
-        int len;
-        len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
-        if (len > 0) {
-            buf[len] = 0;
-            p = buf;
-        }
-    }
-#elif defined(__FreeBSD__)
-    {
-        static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-        size_t len = sizeof(buf) - 1;
-
-        *buf = '\0';
-        if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) &&
-            *buf) {
-            buf[sizeof(buf) - 1] = '\0';
-            p = buf;
-        }
-    }
-#endif
-    /* If we don't have any way of figuring out the actual executable
-       location then try argv[0].  */
-    if (!p) {
-        p = realpath(argv0, buf);
-        if (!p) {
-            return NULL;
-        }
-    }
-    dir = dirname(p);
-    dir = dirname(dir);
-
-    max_len = strlen(dir) +
-        MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
-    res = qemu_mallocz(max_len);
-    snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
-    if (access(res, R_OK)) {
-        snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
-        if (access(res, R_OK)) {
-            qemu_free(res);
-            res = NULL;
-        }
-    }
-
-    return res;
-}
-#undef SHARE_SUFFIX
-#undef BUILD_SUFFIX
-#endif
-
 char *qemu_find_file(int type, const char *name)
 {
     int len;
@@ -3223,7 +3134,7 @@ int main(int argc, char **argv, char **envp)
     /* If no data_dir is specified then try to find it relative to the
        executable path.  */
     if (!data_dir) {
-        data_dir = find_datadir(argv[0]);
+        data_dir = os_find_datadir(argv[0]);
     }
     /* If all else fails use the install patch specified when building.  */
     if (!data_dir) {
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (8 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c Jes.Sorensen
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Rename qemu-options.h to qemu-options.def as it is not a header file
for general use and this leaves space for a proper qemu-options.h

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 Makefile.objs |    4 ++--
 vl.c          |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 2d94677..124afe7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -258,8 +258,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
-vl.o: qemu-options.h
+vl.o: qemu-options.def
 
-qemu-options.h: $(SRC_PATH)/qemu-options.hx
+qemu-options.def: $(SRC_PATH)/qemu-options.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
diff --git a/vl.c b/vl.c
index 3e56121..214b9c1 100644
--- a/vl.c
+++ b/vl.c
@@ -1875,7 +1875,7 @@ static void help(int exitcode)
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
         opt_help
 #define DEFHEADING(text) stringify(text) "\n"
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1903,7 +1903,7 @@ enum {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
     opt_enum,
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1921,7 +1921,7 @@ static const QEMUOption qemu_options[] = {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
     { option, opt_arg, opt_enum, arch_mask },
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (9 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files Jes.Sorensen
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Introduce OS specific cmdline argument handling by calling
os_parse_cmd_args() at the end of switch() statement. Move option
enum to qemu-options.h and have it included from os-posix.c and
os-win32.c in addition to vl.c.

In addition move SMB argument to os-posix.c

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 Makefile.objs  |    2 ++
 os-posix.c     |   19 +++++++++++++++++++
 os-win32.c     |   10 ++++++++++
 qemu-options.h |   41 +++++++++++++++++++++++++++++++++++++++++
 sysemu.h       |    1 +
 vl.c           |   19 +++----------------
 6 files changed, 76 insertions(+), 16 deletions(-)
 create mode 100644 qemu-options.h

diff --git a/Makefile.objs b/Makefile.objs
index 124afe7..27595df 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -259,6 +259,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
 vl.o: qemu-options.def
+os-posix.o: qemu-options.def
+os-win32.o: qemu-options.def
 
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
diff --git a/os-posix.c b/os-posix.c
index 621ad06..0deddf3 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,8 @@
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
 #include "sysemu.h"
+#include "net/slirp.h"
+#include "qemu-options.h"
 
 void os_setup_early_signal_handling(void)
 {
@@ -130,3 +132,20 @@ char *os_find_datadir(const char *argv0)
 }
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+    switch (index) {
+#ifdef CONFIG_SLIRP
+    case QEMU_OPTION_smb:
+        if (net_slirp_smb(optarg) < 0)
+            exit(1);
+        break;
+#endif
+    }
+    return;
+}
diff --git a/os-win32.c b/os-win32.c
index 1758538..aefc535 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -31,6 +31,7 @@
 #include <sys/time.h>
 #include "config-host.h"
 #include "sysemu.h"
+#include "qemu-options.h"
 
 /***********************************************************/
 /* Polling handling */
@@ -204,3 +205,12 @@ char *os_find_datadir(const char *argv0)
     }
     return NULL;
 }
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+    return;
+}
diff --git a/qemu-options.h b/qemu-options.h
new file mode 100644
index 0000000..c96f994
--- /dev/null
+++ b/qemu-options.h
@@ -0,0 +1,41 @@
+/*
+ * qemu-options.h
+ *
+ * Defines needed for command line argument processing.
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_OPTIONS_H_
+#define _QEMU_OPTIONS_H_
+
+enum {
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
+    opt_enum,
+#define DEFHEADING(text)
+#include "qemu-options.def"
+#undef DEF
+#undef DEFHEADING
+#undef GEN_DOCS
+};
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 72f3734..2162b1d 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -82,6 +82,7 @@ void do_info_slirp(Monitor *mon);
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
+void os_parse_cmd_args(int index, const char *optarg);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 214b9c1..417c5f3 100644
--- a/vl.c
+++ b/vl.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "qemu-objects.h"
+#include "qemu-options.h"
 #ifdef CONFIG_LINUX
 #include "fsdev/qemu-fsdev.h"
 #endif
@@ -1899,16 +1900,6 @@ static void help(int exitcode)
 
 #define HAS_ARG 0x0001
 
-enum {
-#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
-    opt_enum,
-#define DEFHEADING(text)
-#include "qemu-options.def"
-#undef DEF
-#undef DEFHEADING
-#undef GEN_DOCS
-};
-
 typedef struct QEMUOption {
     const char *name;
     int flags;
@@ -2624,12 +2615,6 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_bootp:
                 legacy_bootp_filename = optarg;
                 break;
-#ifndef _WIN32
-            case QEMU_OPTION_smb:
-                if (net_slirp_smb(optarg) < 0)
-                    exit(1);
-                break;
-#endif
             case QEMU_OPTION_redir:
                 if (net_slirp_redir(optarg) < 0)
                     exit(1);
@@ -3126,6 +3111,8 @@ int main(int argc, char **argv, char **envp)
                     fclose(fp);
                     break;
                 }
+            default:
+                os_parse_cmd_args(popt->index, optarg);
             }
         }
     }
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (10 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 13/17] Move chroot handling " Jes.Sorensen
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move code to handle runas, ie. change of user id of QEMU process
to OS specific files and provide dummy stub for Win32.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |   28 ++++++++++++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   29 +----------------------------
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 0deddf3..8b686a4 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <pwd.h>
 #include <libgen.h>
 
 /* Needed early for CONFIG_BSD etc. */
@@ -36,6 +37,8 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+static struct passwd *user_pwd;
+
 void os_setup_early_signal_handling(void)
 {
     struct sigaction act;
@@ -146,6 +149,31 @@ void os_parse_cmd_args(int index, const char *optarg)
             exit(1);
         break;
 #endif
+    case QEMU_OPTION_runas:
+        user_pwd = getpwnam(optarg);
+        if (!user_pwd) {
+            fprintf(stderr, "User \"%s\" doesn't exist\n", optarg);
+            exit(1);
+        }
+        break;
     }
     return;
 }
+
+void os_change_process_uid(void)
+{
+    if (user_pwd) {
+        if (setgid(user_pwd->pw_gid) < 0) {
+            fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
+            exit(1);
+        }
+        if (setuid(user_pwd->pw_uid) < 0) {
+            fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid);
+            exit(1);
+        }
+        if (setuid(0) != -1) {
+            fprintf(stderr, "Dropping privileges failed\n");
+            exit(1);
+        }
+    }
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..6d8cf79 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,5 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
+void os_change_process_uid(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index e7e2ee3..70fdca5 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,5 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
+static inline void os_change_process_uid(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 417c5f3..4b76e2d 100644
--- a/vl.c
+++ b/vl.c
@@ -34,7 +34,6 @@
 
 #ifndef _WIN32
 #include <libgen.h>
-#include <pwd.h>
 #include <sys/times.h>
 #include <sys/wait.h>
 #include <termios.h>
@@ -2310,9 +2309,7 @@ int main(int argc, char **argv, char **envp)
     const char *incoming = NULL;
 #ifndef _WIN32
     int fd = 0;
-    struct passwd *pwd = NULL;
     const char *chroot_dir = NULL;
-    const char *run_as = NULL;
 #endif
     int show_vnc_port = 0;
     int defconfig = 1;
@@ -3060,9 +3057,6 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_chroot:
                 chroot_dir = optarg;
                 break;
-            case QEMU_OPTION_runas:
-                run_as = optarg;
-                break;
 #endif
             case QEMU_OPTION_xen_domid:
                 if (!(xen_available())) {
@@ -3553,14 +3547,6 @@ int main(int argc, char **argv, char **envp)
 	    exit(1);
     }
 
-    if (run_as) {
-        pwd = getpwnam(run_as);
-        if (!pwd) {
-            fprintf(stderr, "User \"%s\" doesn't exist\n", run_as);
-            exit(1);
-        }
-    }
-
     if (chroot_dir) {
         if (chroot(chroot_dir) < 0) {
             fprintf(stderr, "chroot failed\n");
@@ -3572,20 +3558,7 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-    if (run_as) {
-        if (setgid(pwd->pw_gid) < 0) {
-            fprintf(stderr, "Failed to setgid(%d)\n", pwd->pw_gid);
-            exit(1);
-        }
-        if (setuid(pwd->pw_uid) < 0) {
-            fprintf(stderr, "Failed to setuid(%d)\n", pwd->pw_uid);
-            exit(1);
-        }
-        if (setuid(0) != -1) {
-            fprintf(stderr, "Dropping privileges failed\n");
-            exit(1);
-        }
-    }
+    os_change_process_uid();
 
     if (daemonize) {
         dup2(fd, 0);
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 13/17] Move chroot handling to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (11 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 14/17] Move daemonize " Jes.Sorensen
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move chroot handling to OS specific files.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |   19 +++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   18 +-----------------
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 8b686a4..6417d16 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -38,6 +38,7 @@
 #include "qemu-options.h"
 
 static struct passwd *user_pwd;
+static const char *chroot_dir;
 
 void os_setup_early_signal_handling(void)
 {
@@ -156,6 +157,9 @@ void os_parse_cmd_args(int index, const char *optarg)
             exit(1);
         }
         break;
+    case QEMU_OPTION_chroot:
+        chroot_dir = optarg;
+        break;
     }
     return;
 }
@@ -177,3 +181,18 @@ void os_change_process_uid(void)
         }
     }
 }
+
+void os_change_root(void)
+{
+    if (chroot_dir) {
+        if (chroot(chroot_dir) < 0) {
+            fprintf(stderr, "chroot failed\n");
+            exit(1);
+        }
+        if (chdir("/")) {
+            perror("not able to chdir to /");
+            exit(1);
+        }
+    }
+
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 6d8cf79..91c7b68 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -32,5 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
+void os_change_root(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 70fdca5..e2a97d2 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -44,5 +44,6 @@ void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
+static inline void os_change_root(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 4b76e2d..c5f0e63 100644
--- a/vl.c
+++ b/vl.c
@@ -2309,7 +2309,6 @@ int main(int argc, char **argv, char **envp)
     const char *incoming = NULL;
 #ifndef _WIN32
     int fd = 0;
-    const char *chroot_dir = NULL;
 #endif
     int show_vnc_port = 0;
     int defconfig = 1;
@@ -3053,11 +3052,6 @@ int main(int argc, char **argv, char **envp)
                 default_cdrom = 0;
                 default_sdcard = 0;
                 break;
-#ifndef _WIN32
-            case QEMU_OPTION_chroot:
-                chroot_dir = optarg;
-                break;
-#endif
             case QEMU_OPTION_xen_domid:
                 if (!(xen_available())) {
                     printf("Option %s not supported for this target\n", popt->name);
@@ -3547,17 +3541,7 @@ int main(int argc, char **argv, char **envp)
 	    exit(1);
     }
 
-    if (chroot_dir) {
-        if (chroot(chroot_dir) < 0) {
-            fprintf(stderr, "chroot failed\n");
-            exit(1);
-        }
-        if (chdir("/")) {
-            perror("not able to chdir to /");
-            exit(1);
-        }
-    }
-
+    os_change_root();
     os_change_process_uid();
 
     if (daemonize) {
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (12 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 13/17] Move chroot handling " Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-25 16:41   ` Frank Arnold
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local Jes.Sorensen
                   ` (3 subsequent siblings)
  17 siblings, 1 reply; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move daemonize handling from vl.c to OS specific files. Provide dummy
stubs for Win32.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 os-win32.c      |    5 +++
 qemu-os-posix.h |    2 +
 qemu-os-win32.h |    2 +
 sysemu.h        |    1 +
 vl.c            |  106 ++-----------------------------------------------------
 6 files changed, 115 insertions(+), 103 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 6417d16..1672e06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -39,6 +39,8 @@
 
 static struct passwd *user_pwd;
 static const char *chroot_dir;
+static int daemonize;
+static int fds[2];
 
 void os_setup_early_signal_handling(void)
 {
@@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
     case QEMU_OPTION_chroot:
         chroot_dir = optarg;
         break;
+    case QEMU_OPTION_daemonize:
+        daemonize = 1;
+        break;
     }
     return;
 }
@@ -196,3 +201,100 @@ void os_change_root(void)
     }
 
 }
+
+void os_daemonize(void)
+{
+    if (daemonize) {
+	pid_t pid;
+
+	if (pipe(fds) == -1)
+	    exit(1);
+
+	pid = fork();
+	if (pid > 0) {
+	    uint8_t status;
+	    ssize_t len;
+
+	    close(fds[1]);
+
+	again:
+            len = read(fds[0], &status, 1);
+            if (len == -1 && (errno == EINTR))
+                goto again;
+
+            if (len != 1)
+                exit(1);
+            else if (status == 1) {
+                fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
+                exit(1);
+            } else
+                exit(0);
+	} else if (pid < 0)
+            exit(1);
+
+	close(fds[0]);
+	qemu_set_cloexec(fds[1]);
+
+	setsid();
+
+	pid = fork();
+	if (pid > 0)
+	    exit(0);
+	else if (pid < 0)
+	    exit(1);
+
+	umask(027);
+
+        signal(SIGTSTP, SIG_IGN);
+        signal(SIGTTOU, SIG_IGN);
+        signal(SIGTTIN, SIG_IGN);
+    }
+}
+
+void os_setup_post(void)
+{
+    int fd = 0;
+
+    if (daemonize) {
+	uint8_t status = 0;
+	ssize_t len;
+
+    again1:
+	len = write(fds[1], &status, 1);
+	if (len == -1 && (errno == EINTR))
+	    goto again1;
+
+	if (len != 1)
+	    exit(1);
+
+        if (chdir("/")) {
+            perror("not able to chdir to /");
+            exit(1);
+        }
+	TFR(fd = qemu_open("/dev/null", O_RDWR));
+	if (fd == -1)
+	    exit(1);
+    }
+
+    os_change_root();
+    os_change_process_uid();
+
+    if (daemonize) {
+        dup2(fd, 0);
+        dup2(fd, 1);
+        dup2(fd, 2);
+
+        close(fd);
+    }
+}
+
+void os_pidfile_error(void)
+{
+    if (daemonize) {
+        uint8_t status = 1;
+        if (write(fds[1], &status, 1) != 1) {
+            perror("daemonize. Writing to pipe\n");
+        }
+    } else
+        fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/os-win32.c b/os-win32.c
index aefc535..d98fd77 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -214,3 +214,8 @@ void os_parse_cmd_args(int index, const char *optarg)
 {
     return;
 }
+
+void os_pidfile_error(void)
+{
+    fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 91c7b68..9b07660 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -33,5 +33,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
 void os_change_root(void);
+void os_daemonize(void);
+void os_setup_post(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index e2a97d2..c4aa84a 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
 static inline void os_change_root(void) {}
+static inline void os_daemonize(void) {}
+static inline void os_setup_post(void) {}
 
 #endif
diff --git a/sysemu.h b/sysemu.h
index 2162b1d..346cccd 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -83,6 +83,7 @@ void do_info_slirp(Monitor *mon);
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
 void os_parse_cmd_args(int index, const char *optarg);
+void os_pidfile_error(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index c5f0e63..8902477 100644
--- a/vl.c
+++ b/vl.c
@@ -216,9 +216,6 @@ int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 uint8_t irq0override = 1;
-#ifndef _WIN32
-int daemonize = 0;
-#endif
 const char *watchdog;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
@@ -2301,15 +2298,9 @@ int main(int argc, char **argv, char **envp)
     const char *loadvm = NULL;
     QEMUMachine *machine;
     const char *cpu_model;
-#ifndef _WIN32
-    int fds[2];
-#endif
     int tb_size;
     const char *pid_file = NULL;
     const char *incoming = NULL;
-#ifndef _WIN32
-    int fd = 0;
-#endif
     int show_vnc_port = 0;
     int defconfig = 1;
 
@@ -2975,11 +2966,6 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
-#ifndef _WIN32
-	    case QEMU_OPTION_daemonize:
-		daemonize = 1;
-		break;
-#endif
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
 		    fprintf(stderr, "Too many option ROMs\n");
@@ -3194,64 +3180,10 @@ int main(int argc, char **argv, char **envp)
     }
 #endif
 
-#ifndef _WIN32
-    if (daemonize) {
-	pid_t pid;
-
-	if (pipe(fds) == -1)
-	    exit(1);
-
-	pid = fork();
-	if (pid > 0) {
-	    uint8_t status;
-	    ssize_t len;
-
-	    close(fds[1]);
-
-	again:
-            len = read(fds[0], &status, 1);
-            if (len == -1 && (errno == EINTR))
-                goto again;
-
-            if (len != 1)
-                exit(1);
-            else if (status == 1) {
-                fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
-                exit(1);
-            } else
-                exit(0);
-	} else if (pid < 0)
-            exit(1);
-
-	close(fds[0]);
-	qemu_set_cloexec(fds[1]);
-
-	setsid();
-
-	pid = fork();
-	if (pid > 0)
-	    exit(0);
-	else if (pid < 0)
-	    exit(1);
-
-	umask(027);
-
-        signal(SIGTSTP, SIG_IGN);
-        signal(SIGTTOU, SIG_IGN);
-        signal(SIGTTIN, SIG_IGN);
-    }
-#endif
+    os_daemonize();
 
     if (pid_file && qemu_create_pidfile(pid_file) != 0) {
-#ifndef _WIN32
-        if (daemonize) {
-            uint8_t status = 1;
-            if (write(fds[1], &status, 1) != 1) {
-                perror("daemonize. Writing to pipe\n");
-            }
-        } else
-#endif
-            fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+        os_pidfile_error();
         exit(1);
     }
 
@@ -3519,39 +3451,7 @@ int main(int argc, char **argv, char **envp)
         vm_start();
     }
 
-#ifndef _WIN32
-    if (daemonize) {
-	uint8_t status = 0;
-	ssize_t len;
-
-    again1:
-	len = write(fds[1], &status, 1);
-	if (len == -1 && (errno == EINTR))
-	    goto again1;
-
-	if (len != 1)
-	    exit(1);
-
-        if (chdir("/")) {
-            perror("not able to chdir to /");
-            exit(1);
-        }
-	TFR(fd = qemu_open("/dev/null", O_RDWR));
-	if (fd == -1)
-	    exit(1);
-    }
-
-    os_change_root();
-    os_change_process_uid();
-
-    if (daemonize) {
-        dup2(fd, 0);
-        dup2(fd, 1);
-        dup2(fd, 2);
-
-        close(fd);
-    }
-#endif
+    os_setup_post();
 
     main_loop();
     quit_timers();
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (13 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 14/17] Move daemonize " Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files Jes.Sorensen
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

os_change_process_uid() and os_change_root() are now only called
from os-posix.c, so no need to keep win32 stubs for them.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |    8 ++++----
 qemu-os-posix.h |    2 --
 qemu-os-win32.h |    2 --
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 1672e06..3a96c91 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -169,7 +169,7 @@ void os_parse_cmd_args(int index, const char *optarg)
     return;
 }
 
-void os_change_process_uid(void)
+static void change_process_uid(void)
 {
     if (user_pwd) {
         if (setgid(user_pwd->pw_gid) < 0) {
@@ -187,7 +187,7 @@ void os_change_process_uid(void)
     }
 }
 
-void os_change_root(void)
+static void change_root(void)
 {
     if (chroot_dir) {
         if (chroot(chroot_dir) < 0) {
@@ -276,8 +276,8 @@ void os_setup_post(void)
 	    exit(1);
     }
 
-    os_change_root();
-    os_change_process_uid();
+    change_root();
+    change_process_uid();
 
     if (daemonize) {
         dup2(fd, 0);
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 9b07660..8be583d 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,8 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
-void os_change_process_uid(void);
-void os_change_root(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index c4aa84a..39df333 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,8 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
-static inline void os_change_process_uid(void) {}
-static inline void os_change_root(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (14 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 17/17] Move set_proc_name() " Jes.Sorensen
  2010-06-12  6:33 ` [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Blue Swirl
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move line-buffering setup to OS specific files.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |    5 +++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    2 ++
 vl.c            |    5 +----
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 3a96c91..9bae8fe 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -298,3 +298,8 @@ void os_pidfile_error(void)
     } else
         fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
 }
+
+void os_set_line_buffering(void)
+{
+    setvbuf(stdout, NULL, _IOLBF, 0);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 8be583d..cb210ba 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_set_line_buffering(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 39df333..5a97d8d 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
+/* Win32 doesn't support line-buffering and requires size >= 2 */
+static inline void os_set_line_buffering(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 8902477..f18886a 100644
--- a/vl.c
+++ b/vl.c
@@ -3215,10 +3215,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-#ifndef _WIN32
-    /* Win32 doesn't support line-buffering and requires size >= 2 */
-    setvbuf(stdout, NULL, _IOLBF, 0);
-#endif
+    os_set_line_buffering();
 
     if (init_timer_alarm() < 0) {
         fprintf(stderr, "could not initialize alarm timer\n");
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [Qemu-devel] [PATCH 17/17] Move set_proc_name() to OS specific files.
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (15 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files Jes.Sorensen
@ 2010-06-10  9:42 ` Jes.Sorensen
  2010-06-12  6:33 ` [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Blue Swirl
  17 siblings, 0 replies; 30+ messages in thread
From: Jes.Sorensen @ 2010-06-10  9:42 UTC (permalink / raw)
  To: anthony; +Cc: Jes Sorensen, qemu-devel

From: Jes Sorensen <Jes.Sorensen@redhat.com>

Move handling to change process name to POSIX specific files
plus add a better error message to cover the case where the
feature isn't supported.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Acked-by: Juan Quintela <quintela@redhat.com>
Acked-by: Richard Henderson <rth@redhat.com>
---
 os-posix.c      |   24 ++++++++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   19 +------------------
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 9bae8fe..d89020d 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -37,6 +37,10 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+#ifdef CONFIG_LINUX
+#include <sys/prctl.h>
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -139,6 +143,26 @@ char *os_find_datadir(const char *argv0)
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
 
+void os_set_proc_name(const char *s)
+{
+#if defined(PR_SET_NAME)
+    char name[16];
+    if (!s)
+        return;
+    name[sizeof(name) - 1] = 0;
+    strncpy(name, s, sizeof(name));
+    /* Could rewrite argv[0] too, but that's a bit more complicated.
+       This simple way is enough for `top'. */
+    if (prctl(PR_SET_NAME, name)) {
+        perror("unable to change process name");
+        exit(1);
+    }
+#else
+    fprintf(stderr, "Change of process name not supported by your OS\n");
+    exit(1);
+#endif    	
+}
+
 /*
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index cb210ba..ed5c058 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_set_line_buffering(void);
+void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 5a97d8d..6323f7f 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -47,5 +47,6 @@ static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 /* Win32 doesn't support line-buffering and requires size >= 2 */
 static inline void os_set_line_buffering(void) {}
+static inline void os_set_proc_name(const char *dummy) {}
 
 #endif
diff --git a/vl.c b/vl.c
index f18886a..9eac300 100644
--- a/vl.c
+++ b/vl.c
@@ -59,7 +59,6 @@
 #ifdef __linux__
 #include <pty.h>
 #include <malloc.h>
-#include <sys/prctl.h>
 
 #include <linux/ppdev.h>
 #include <linux/parport.h>
@@ -284,22 +283,6 @@ static int default_driver_check(QemuOpts *opts, void *opaque)
 }
 
 /***********************************************************/
-
-static void set_proc_name(const char *s)
-{
-#if defined(__linux__) && defined(PR_SET_NAME)
-    char name[16];
-    if (!s)
-        return;
-    name[sizeof(name) - 1] = 0;
-    strncpy(name, s, sizeof(name));
-    /* Could rewrite argv[0] too, but that's a bit more complicated.
-       This simple way is enough for `top'. */
-    prctl(PR_SET_NAME, name);
-#endif    	
-}
- 
-/***********************************************************/
 /* real time host monotonic timer */
 
 /* compute with 96 bit intermediate result: (a*b)/c */
@@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp)
 			    exit(1);
 			}
 			p += 8;
-			set_proc_name(p);
+			os_set_proc_name(p);
 		     }	
 		 }	
                 break;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH v4 00/17] clean up vl.c code
  2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
                   ` (16 preceding siblings ...)
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 17/17] Move set_proc_name() " Jes.Sorensen
@ 2010-06-12  6:33 ` Blue Swirl
  17 siblings, 0 replies; 30+ messages in thread
From: Blue Swirl @ 2010-06-12  6:33 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: qemu-devel

Thanks, applied.


On Thu, Jun 10, 2010 at 9:42 AM,  <Jes.Sorensen@redhat.com> wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> v4 of the vl.c clean up patch. This one just fixes a merge conflict
> due to some recent changes to vl.c, and I added the Acked-By: lines I
> received for v3. Consider it a house-keeping update to make it easier
> to merge.
>
> The patches try to clean up the vl.c code by separating out OS
> specific code into OS specific files. Basically it is focused on
> moving things into os-posix.c for most UNIX/Linux systems, and
> os-win32.c for win32 specific bits.
>
> Cheers,
> Jes
>
>
> Jes Sorensen (17):
>  vl.c: Remove double include of netinet/in.h for Solaris
>  Create qemu-os-win32.h and move WIN32 specific declarations there
>  Introduce os-win32.c and move polling functions from vl.c
>  vl.c: Move host_main_loop_wait() to OS specific files.
>  Introduce os-posix.c and create os_setup_signal_handling()
>  Move win32 early signal handling setup to os_setup_signal_handling()
>  Rename os_setup_signal_handling() to os_setup_early_signal_handling()
>  Move main signal handler setup to os specificfiles.
>  Move find_datadir to OS specific files.
>  Rename qemu-options.h to qemu-options.def
>  Introduce OS specific cmdline argument handling and move SMB arg to
>    os-posix.c
>  Move runas handling from vl.c to OS specific files.
>  Move chroot handling to OS specific files.
>  Move daemonize handling to OS specific files
>  Make os_change_process_uid and os_change_root os-posix.c local
>  Move line-buffering setup to OS specific files.
>  Move set_proc_name() to OS specific files.
>
>  Makefile.objs   |    8 +-
>  os-posix.c      |  329 +++++++++++++++++++++++++++++++++++++
>  os-win32.c      |  221 +++++++++++++++++++++++++
>  qemu-options.h  |   41 +++++
>  qemu-os-posix.h |   39 +++++
>  qemu-os-win32.h |   52 ++++++
>  sysemu.h        |   27 ++--
>  vl.c            |  491 ++-----------------------------------------------------
>  8 files changed, 713 insertions(+), 495 deletions(-)
>  create mode 100644 os-posix.c
>  create mode 100644 os-win32.c
>  create mode 100644 qemu-options.h
>  create mode 100644 qemu-os-posix.h
>  create mode 100644 qemu-os-win32.h
>
>
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-10  9:42 ` [Qemu-devel] [PATCH 14/17] Move daemonize " Jes.Sorensen
@ 2010-06-25 16:41   ` Frank Arnold
  2010-06-25 17:02     ` Jes Sorensen
  0 siblings, 1 reply; 30+ messages in thread
From: Frank Arnold @ 2010-06-25 16:41 UTC (permalink / raw)
  To: Jes.Sorensen; +Cc: Andre Przywara, qemu-devel

On Thu, 2010-06-10 at 05:42 -0400, Jes.Sorensen@redhat.com wrote:
> diff --git a/os-posix.c b/os-posix.c
> index 6417d16..1672e06 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
>      case QEMU_OPTION_chroot:
>          chroot_dir = optarg;
>          break;
> +    case QEMU_OPTION_daemonize:
> +        daemonize = 1;
> +        break;
>      }
>      return;
>  }

This move broke the -daemonize option for us. We are using the qemu-kvm
tree.

The issue is that the QEMU_OPTION_* enumeration between vl.c and
os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c
but is not in os-posix.c. This excludes the option -mem-prealloc in
os-posix.c, see qemu-options.def for the ifdef statement. All subsequent
options are off by one in comparison to vl.c.

Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm
not sure if there is a more generic fix to that problem.

-- 
Frank Arnold 
System Design Technician, Software Test
AMD Operating System Research Center
Dresden, Germany
Tel: +49 351 448 356702


Legal Information:
Advanced Micro Devices GmbH
Einsteinring 24
85609 Dornach b. München

Geschäftsführer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis München
Registergericht München, HRB Nr. 43632

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-25 16:41   ` Frank Arnold
@ 2010-06-25 17:02     ` Jes Sorensen
  2010-06-25 17:34       ` Frank Arnold
  0 siblings, 1 reply; 30+ messages in thread
From: Jes Sorensen @ 2010-06-25 17:02 UTC (permalink / raw)
  To: Frank Arnold; +Cc: Andre Przywara, qemu-devel

On 06/25/10 18:41, Frank Arnold wrote:
> On Thu, 2010-06-10 at 05:42 -0400, Jes.Sorensen@redhat.com wrote:
>> diff --git a/os-posix.c b/os-posix.c
>> index 6417d16..1672e06 100644
>> --- a/os-posix.c
>> +++ b/os-posix.c
>> @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
>>      case QEMU_OPTION_chroot:
>>          chroot_dir = optarg;
>>          break;
>> +    case QEMU_OPTION_daemonize:
>> +        daemonize = 1;
>> +        break;
>>      }
>>      return;
>>  }
> 
> This move broke the -daemonize option for us. We are using the qemu-kvm
> tree.
> 
> The issue is that the QEMU_OPTION_* enumeration between vl.c and
> os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c
> but is not in os-posix.c. This excludes the option -mem-prealloc in
> os-posix.c, see qemu-options.def for the ifdef statement. All subsequent
> options are off by one in comparison to vl.c.
> 
> Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm
> not sure if there is a more generic fix to that problem.

Thanks for the update. What do you mean that it changes the numbering,
do you get a compile time error or are you saying that it is the order
of parsing the options that change?

Are you building on Linux or another OS?

Cheers,
Jes

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-25 17:02     ` Jes Sorensen
@ 2010-06-25 17:34       ` Frank Arnold
  2010-06-25 17:45         ` Frank Arnold
                           ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Frank Arnold @ 2010-06-25 17:34 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Przywara, Andre, qemu-devel

On Fri, 2010-06-25 at 13:02 -0400, Jes Sorensen wrote:
> On 06/25/10 18:41, Frank Arnold wrote:
> > On Thu, 2010-06-10 at 05:42 -0400, Jes.Sorensen@redhat.com wrote:
> >> diff --git a/os-posix.c b/os-posix.c
> >> index 6417d16..1672e06 100644
> >> --- a/os-posix.c
> >> +++ b/os-posix.c
> >> @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
> >>      case QEMU_OPTION_chroot:
> >>          chroot_dir = optarg;
> >>          break;
> >> +    case QEMU_OPTION_daemonize:
> >> +        daemonize = 1;
> >> +        break;
> >>      }
> >>      return;
> >>  }
> > 
> > This move broke the -daemonize option for us. We are using the qemu-kvm
> > tree.
> > 
> > The issue is that the QEMU_OPTION_* enumeration between vl.c and
> > os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c
> > but is not in os-posix.c. This excludes the option -mem-prealloc in
> > os-posix.c, see qemu-options.def for the ifdef statement. All subsequent
> > options are off by one in comparison to vl.c.
> > 
> > Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm
> > not sure if there is a more generic fix to that problem.
> 
> Thanks for the update. What do you mean that it changes the numbering,
> do you get a compile time error or are you saying that it is the order
> of parsing the options that change?
> 
> Are you building on Linux or another OS?

We are doing KVM testing, so it is Linux.

What I did is putting lines like this somewhere into vl.c and
os-posix.c:
fprintf(stderr, "os: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
fprintf(stderr, "vl: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);

Resulting in the following output on stderr:
os: QEMU_OPTION_daemonize: 85
vl: QEMU_OPTION_daemonize: 86

No compile time errors. The preprocessing of qemu-options.h is done
separately for both files. This results in a missing option definition
for os-posix.c and discrepancy in the option enumeration.


-- 
Frank Arnold 
Systems Design Technician, Software Test
AMD Operating System Research Center
Dresden, Germany
Tel: +49 351 448 356702


Legal Information:
Advanced Micro Devices GmbH
Einsteinring 24
85609 Dornach b. München

Geschäftsführer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis München
Registergericht München, HRB Nr. 43632

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-25 17:34       ` Frank Arnold
@ 2010-06-25 17:45         ` Frank Arnold
  2010-06-28  9:30         ` Jes Sorensen
  2010-06-28 14:50         ` Jes Sorensen
  2 siblings, 0 replies; 30+ messages in thread
From: Frank Arnold @ 2010-06-25 17:45 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Przywara, Andre, qemu-devel

On Fri, 2010-06-25 at 19:34 +0200, Frank Arnold wrote:
> On Fri, 2010-06-25 at 13:02 -0400, Jes Sorensen wrote:
> > On 06/25/10 18:41, Frank Arnold wrote:
> > > On Thu, 2010-06-10 at 05:42 -0400, Jes.Sorensen@redhat.com wrote:
> > >> diff --git a/os-posix.c b/os-posix.c
> > >> index 6417d16..1672e06 100644
> > >> --- a/os-posix.c
> > >> +++ b/os-posix.c
> > >> @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
> > >>      case QEMU_OPTION_chroot:
> > >>          chroot_dir = optarg;
> > >>          break;
> > >> +    case QEMU_OPTION_daemonize:
> > >> +        daemonize = 1;
> > >> +        break;
> > >>      }
> > >>      return;
> > >>  }
> > > 
> > > This move broke the -daemonize option for us. We are using the qemu-kvm
> > > tree.
> > > 
> > > The issue is that the QEMU_OPTION_* enumeration between vl.c and
> > > os-posix.c is out of sync. In our case MAP_POPULATE is defined in vl.c
> > > but is not in os-posix.c. This excludes the option -mem-prealloc in
> > > os-posix.c, see qemu-options.def for the ifdef statement. All subsequent
> > > options are off by one in comparison to vl.c.
> > > 
> > > Just including sys/mman.h in os-posix.c fixes the issue for me. But I'm
> > > not sure if there is a more generic fix to that problem.
> > 
> > Thanks for the update. What do you mean that it changes the numbering,
> > do you get a compile time error or are you saying that it is the order
> > of parsing the options that change?
> > 
> > Are you building on Linux or another OS?
> 
> We are doing KVM testing, so it is Linux.
> 
> What I did is putting lines like this somewhere into vl.c and
> os-posix.c:
> fprintf(stderr, "os: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> fprintf(stderr, "vl: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> 
> Resulting in the following output on stderr:
> os: QEMU_OPTION_daemonize: 85
> vl: QEMU_OPTION_daemonize: 86
> 
> No compile time errors. The preprocessing of qemu-options.h is done
> separately for both files. This results in a missing option definition
> for os-posix.c and discrepancy in the option enumeration.

Sorry, missed the part where your patch comes into play:

>From vl.c the function os_parse_cmd_args is called with option index 86,
and the switch statement in os-posix.c's os_parse_cmd_args checks for 85
to set the daemonize. Obviously, this wont work.

-- Frank

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-25 17:34       ` Frank Arnold
  2010-06-25 17:45         ` Frank Arnold
@ 2010-06-28  9:30         ` Jes Sorensen
  2010-06-28 14:50         ` Jes Sorensen
  2 siblings, 0 replies; 30+ messages in thread
From: Jes Sorensen @ 2010-06-28  9:30 UTC (permalink / raw)
  To: Frank Arnold; +Cc: Przywara, Andre, qemu-devel

On 06/25/10 19:34, Frank Arnold wrote:
> We are doing KVM testing, so it is Linux.
> 
> What I did is putting lines like this somewhere into vl.c and
> os-posix.c:
> fprintf(stderr, "os: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> fprintf(stderr, "vl: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> 
> Resulting in the following output on stderr:
> os: QEMU_OPTION_daemonize: 85
> vl: QEMU_OPTION_daemonize: 86
> 
> No compile time errors. The preprocessing of qemu-options.h is done
> separately for both files. This results in a missing option definition
> for os-posix.c and discrepancy in the option enumeration.

Ok this is truly odd! Let me try and see if I can reproduce it here.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-25 17:34       ` Frank Arnold
  2010-06-25 17:45         ` Frank Arnold
  2010-06-28  9:30         ` Jes Sorensen
@ 2010-06-28 14:50         ` Jes Sorensen
  2010-06-28 15:42           ` Blue Swirl
  2 siblings, 1 reply; 30+ messages in thread
From: Jes Sorensen @ 2010-06-28 14:50 UTC (permalink / raw)
  To: Frank Arnold; +Cc: Przywara, Andre, qemu-devel

On 06/25/10 19:34, Frank Arnold wrote:
> We are doing KVM testing, so it is Linux.
> 
> What I did is putting lines like this somewhere into vl.c and
> os-posix.c:
> fprintf(stderr, "os: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> fprintf(stderr, "vl: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
> 
> Resulting in the following output on stderr:
> os: QEMU_OPTION_daemonize: 85
> vl: QEMU_OPTION_daemonize: 86
> 
> No compile time errors. The preprocessing of qemu-options.h is done
> separately for both files. This results in a missing option definition
> for os-posix.c and discrepancy in the option enumeration.

Hi Frank,

I figured out what was causing it. qemu-options.def has an
#ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
being included. Pretty much every other #ifdef in qemu-options.def are
based on CONFIG_foo settings or things like _WIN32 which do not change
depending on header file inclusion.

I think the easiest fix is to just add sys/mmap.h to the include list in
os-posix.c, so I just posted a patch for that. Though, in principle we
really shouldn't base qemu-options.def settings on defines pulled in
from system header files.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-28 14:50         ` Jes Sorensen
@ 2010-06-28 15:42           ` Blue Swirl
  2010-06-28 16:03             ` Jes Sorensen
  0 siblings, 1 reply; 30+ messages in thread
From: Blue Swirl @ 2010-06-28 15:42 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Frank Arnold, qemu-devel, Przywara, Andre

On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
> On 06/25/10 19:34, Frank Arnold wrote:
>> We are doing KVM testing, so it is Linux.
>>
>> What I did is putting lines like this somewhere into vl.c and
>> os-posix.c:
>> fprintf(stderr, "os: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
>> fprintf(stderr, "vl: QEMU_OPTION_daemonize: %i", QEMU_OPTION_daemonize);
>>
>> Resulting in the following output on stderr:
>> os: QEMU_OPTION_daemonize: 85
>> vl: QEMU_OPTION_daemonize: 86
>>
>> No compile time errors. The preprocessing of qemu-options.h is done
>> separately for both files. This results in a missing option definition
>> for os-posix.c and discrepancy in the option enumeration.
>
> Hi Frank,
>
> I figured out what was causing it. qemu-options.def has an
> #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
> being included. Pretty much every other #ifdef in qemu-options.def are
> based on CONFIG_foo settings or things like _WIN32 which do not change
> depending on header file inclusion.
>
> I think the easiest fix is to just add sys/mmap.h to the include list in
> os-posix.c, so I just posted a patch for that. Though, in principle we
> really shouldn't base qemu-options.def settings on defines pulled in
> from system header files.

I think more flags should be added to arch_mask field, like
QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
should be removed. Prealloc command line flag stuff should be
conditional to CONFIG_LINUX only, there should be another check for
MAP_POPULATE where mem_preallocate is set.

Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-28 15:42           ` Blue Swirl
@ 2010-06-28 16:03             ` Jes Sorensen
  2010-06-28 16:20               ` Blue Swirl
  2010-06-28 16:46               ` [Qemu-devel] " Paolo Bonzini
  0 siblings, 2 replies; 30+ messages in thread
From: Jes Sorensen @ 2010-06-28 16:03 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Frank Arnold, qemu-devel, Przywara, Andre

On 06/28/10 17:42, Blue Swirl wrote:
> On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
>> I figured out what was causing it. qemu-options.def has an
>> #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
>> being included. Pretty much every other #ifdef in qemu-options.def are
>> based on CONFIG_foo settings or things like _WIN32 which do not change
>> depending on header file inclusion.
>>
>> I think the easiest fix is to just add sys/mmap.h to the include list in
>> os-posix.c, so I just posted a patch for that. Though, in principle we
>> really shouldn't base qemu-options.def settings on defines pulled in
>> from system header files.
> 
> I think more flags should be added to arch_mask field, like
> QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
> should be removed. Prealloc command line flag stuff should be
> conditional to CONFIG_LINUX only, there should be another check for
> MAP_POPULATE where mem_preallocate is set.
> 
> Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.

Yeah, the problem with tying it to CONFIG_LINUX is that older version of
Linux may not support it. Looking through the list, MAP_POPULATE is
really an oddball in there though, so maybe it would be cleaner to catch
it via configure and then use CONFIG_MAP_POPULATE or something like that?

Cheers,
Jes

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-28 16:03             ` Jes Sorensen
@ 2010-06-28 16:20               ` Blue Swirl
  2010-06-28 16:30                 ` Jes Sorensen
  2010-06-28 16:46               ` [Qemu-devel] " Paolo Bonzini
  1 sibling, 1 reply; 30+ messages in thread
From: Blue Swirl @ 2010-06-28 16:20 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Frank Arnold, qemu-devel, Przywara, Andre

On Mon, Jun 28, 2010 at 4:03 PM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
> On 06/28/10 17:42, Blue Swirl wrote:
>> On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
>>> I figured out what was causing it. qemu-options.def has an
>>> #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
>>> being included. Pretty much every other #ifdef in qemu-options.def are
>>> based on CONFIG_foo settings or things like _WIN32 which do not change
>>> depending on header file inclusion.
>>>
>>> I think the easiest fix is to just add sys/mmap.h to the include list in
>>> os-posix.c, so I just posted a patch for that. Though, in principle we
>>> really shouldn't base qemu-options.def settings on defines pulled in
>>> from system header files.
>>
>> I think more flags should be added to arch_mask field, like
>> QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
>> should be removed. Prealloc command line flag stuff should be
>> conditional to CONFIG_LINUX only, there should be another check for
>> MAP_POPULATE where mem_preallocate is set.
>>
>> Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.
>
> Yeah, the problem with tying it to CONFIG_LINUX is that older version of
> Linux may not support it. Looking through the list, MAP_POPULATE is
> really an oddball in there though, so maybe it would be cleaner to catch
> it via configure and then use CONFIG_MAP_POPULATE or something like that?

There'd be 1:1 relation between MAP_POPULATE and CONFIG_MAP_POPULATE,
so maybe not.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-28 16:20               ` Blue Swirl
@ 2010-06-28 16:30                 ` Jes Sorensen
  0 siblings, 0 replies; 30+ messages in thread
From: Jes Sorensen @ 2010-06-28 16:30 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Frank Arnold, qemu-devel, Przywara, Andre

On 06/28/10 18:20, Blue Swirl wrote:
> On Mon, Jun 28, 2010 at 4:03 PM, Jes Sorensen <Jes.Sorensen@redhat.com> wrote:
>> Yeah, the problem with tying it to CONFIG_LINUX is that older version of
>> Linux may not support it. Looking through the list, MAP_POPULATE is
>> really an oddball in there though, so maybe it would be cleaner to catch
>> it via configure and then use CONFIG_MAP_POPULATE or something like that?
> 
> There'd be 1:1 relation between MAP_POPULATE and CONFIG_MAP_POPULATE,
> so maybe not.

That is correct, but CONFIG_MAP_POPULATE would be in config.h so it
would not get missed out in cases where someone includes qemu-options.h
without including sys/mmap.h first. But it is a corner case, so my patch
should be fine.

Cheers,
Jes

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Qemu-devel] Re: [PATCH 14/17] Move daemonize handling to OS specific files
  2010-06-28 16:03             ` Jes Sorensen
  2010-06-28 16:20               ` Blue Swirl
@ 2010-06-28 16:46               ` Paolo Bonzini
  1 sibling, 0 replies; 30+ messages in thread
From: Paolo Bonzini @ 2010-06-28 16:46 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: Blue Swirl, Frank Arnold, qemu-devel, Przywara, Andre

On 06/28/2010 06:03 PM, Jes Sorensen wrote:
> On 06/28/10 17:42, Blue Swirl wrote:
>> On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen<Jes.Sorensen@redhat.com>  wrote:
>>> I figured out what was causing it. qemu-options.def has an
>>> #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
>>> being included. Pretty much every other #ifdef in qemu-options.def are
>>> based on CONFIG_foo settings or things like _WIN32 which do not change
>>> depending on header file inclusion.
>>>
>>> I think the easiest fix is to just add sys/mmap.h to the include list in
>>> os-posix.c, so I just posted a patch for that. Though, in principle we
>>> really shouldn't base qemu-options.def settings on defines pulled in
>>> from system header files.
>>
>> I think more flags should be added to arch_mask field, like
>> QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
>> should be removed. Prealloc command line flag stuff should be
>> conditional to CONFIG_LINUX only, there should be another check for
>> MAP_POPULATE where mem_preallocate is set.
>>
>> Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.
>
> Yeah, the problem with tying it to CONFIG_LINUX is that older version of
> Linux may not support it. Looking through the list, MAP_POPULATE is
> really an oddball in there though, so maybe it would be cleaner to catch
> it via configure and then use CONFIG_MAP_POPULATE or something like that?

Or create a header file system.h that pulls all we need from the system, 
and remove (almost) all <...> includes from elsewhere.

Paolo

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2010-06-28 16:54 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-10  9:42 [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling() Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling() Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling() Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 13/17] Move chroot handling " Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 14/17] Move daemonize " Jes.Sorensen
2010-06-25 16:41   ` Frank Arnold
2010-06-25 17:02     ` Jes Sorensen
2010-06-25 17:34       ` Frank Arnold
2010-06-25 17:45         ` Frank Arnold
2010-06-28  9:30         ` Jes Sorensen
2010-06-28 14:50         ` Jes Sorensen
2010-06-28 15:42           ` Blue Swirl
2010-06-28 16:03             ` Jes Sorensen
2010-06-28 16:20               ` Blue Swirl
2010-06-28 16:30                 ` Jes Sorensen
2010-06-28 16:46               ` [Qemu-devel] " Paolo Bonzini
2010-06-10  9:42 ` [Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files Jes.Sorensen
2010-06-10  9:42 ` [Qemu-devel] [PATCH 17/17] Move set_proc_name() " Jes.Sorensen
2010-06-12  6:33 ` [Qemu-devel] [PATCH v4 00/17] clean up vl.c code Blue Swirl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.