Skip to contentSkip to conversation

clean up vl.c code

PATCH Applied [email protected] 4 participants 30 messages Jun 10, 2010 – Jun 28, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

v4 cover clean up vl.c code

From: Jes Sorensen <[email protected]>

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
#1 lore raw

PATCH v4 1/17 vl.c: Remove double include of netinet/in.h for Solaris

From: Jes Sorensen <[email protected]>

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

---
 vl.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
vl.c +0 -1
index 6d08ec8..55fc527 100644
@@ -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
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH v4 2/17 Create qemu-os-win32.h and move WIN32 specific declarations there

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 qemu-os-win32.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 sysemu.h        |   17 +----------------
 2 files changed, 44 insertions(+), 16 deletions(-)
 create mode 100644 qemu-os-win32.h
qemu-os-win32.h new file +43 -0
new file mode 100644
index 0000000..be108ad
@@ -0,0 +1,43 @@
+/*
+ * win32 specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <[email protected]>
+ *
+ * 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
sysemu.h +1 -16
index 879446a..13fc9a9 100644
@@ -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);
 
Signature · 1 line
1.6.5.2
#3 lore raw

PATCH v4 3/17 Introduce os-win32.c and move polling functions from vl.c

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 Makefile.objs |    1 +
 os-win32.c    |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c          |   80 -----------------------------------------
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c
Makefile.objs +1 -0
index 9796dcb..58fdb03 100644
@@ -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
os-win32.c new file +111 -0

111 lines not on this page · raw message

vl.c +0 -80

86 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#4 lore raw

PATCH v4 4/17 vl.c: Move host_main_loop_wait() to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 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
os-win32.c +43 -0
index 5a464cc..1f7e28b 100644
@@ -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;
+}
qemu-os-posix.h new file +33 -0
new file mode 100644
index 0000000..96d1036
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen <[email protected]>
+ *
+ * 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
qemu-os-win32.h +1 -0
index be108ad..4d1cac8 100644
@@ -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
sysemu.h +4 -0
index 13fc9a9..5e4feae 100644
@@ -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;
 
vl.c +1 -51

64 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#5 lore raw

PATCH v4 5/17 Introduce os-posix.c and create os_setup_signal_handling()

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 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
Makefile.objs +1 -0
index 58fdb03..2d94677 100644
@@ -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
os-posix.c new file +41 -0

41 lines not on this page · raw message

qemu-os-posix.h +2 -0
index 96d1036..ff5adb1 100644
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
vl.c +1 -7
index 4097762..29c9697 100644
@@ -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
Signature · 1 line
1.6.5.2
#6 lore raw

PATCH v4 6/17 Move win32 early signal handling setup to os_setup_signal_handling()

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Move win32 early signal handling setup to os_setup_signal_handling()

---
 os-win32.c      |   29 +++++++++++++++++++++++++++++
 qemu-os-posix.h |    2 --
 sysemu.h        |    2 ++
 vl.c            |   30 ------------------------------
 4 files changed, 31 insertions(+), 32 deletions(-)
os-win32.c +29 -0
index 1f7e28b..dfa90bc 100644
@@ -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);
+        }
+    }
+}
qemu-os-posix.h +0 -2
index ff5adb1..96d1036 100644
@@ -30,6 +30,4 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
-void os_setup_signal_handling(void);
-
 #endif
sysemu.h +2 -0
index 5e4feae..e3643ad 100644
@@ -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,
vl.c +0 -30
index 29c9697..264710d 100644
@@ -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();
Signature · 1 line
1.6.5.2
#7 lore raw

PATCH v4 7/17 Rename os_setup_signal_handling() to os_setup_early_signal_handling()

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Rename os_setup_signal_handling() to os_setup_early_signal_handling()

---
 os-posix.c |    2 +-
 os-win32.c |    2 +-
 sysemu.h   |    2 +-
 vl.c       |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
os-posix.c +1 -1
index 914a4d1..948f662 100644
@@ -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);
os-win32.c +1 -1
index dfa90bc..a936f7a 100644
@@ -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 */
sysemu.h +1 -1
index e3643ad..bb05cf4 100644
@@ -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
 {
vl.c +1 -1
index 264710d..a8fcb65 100644
@@ -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();
Signature · 1 line
1.6.5.2
#8 lore raw

PATCH v4 8/17 Move main signal handler setup to os specificfiles.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Move main signal handler setup to os specific files.

---
 os-posix.c      |   27 +++++++++++++++++++++++++++
 qemu-os-posix.h |    2 ++
 qemu-os-win32.h |    3 +++
 vl.c            |   33 +--------------------------------
 4 files changed, 33 insertions(+), 32 deletions(-)
os-posix.c +27 -0
index 948f662..01dbec2 100644
@@ -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);
+}
qemu-os-posix.h +2 -0
index 96d1036..ff5adb1 100644
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
qemu-os-win32.h +3 -0
index 4d1cac8..e7e2ee3 100644
@@ -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
vl.c +1 -32
index a8fcb65..1fd839d 100644
@@ -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();
 
Signature · 1 line
1.6.5.2
#9 lore raw

PATCH v4 9/17 Move find_datadir to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 os-posix.c |   64 ++++++++++++++++++++++++++++++++++++++++++
 os-win32.c |   23 +++++++++++++++
 sysemu.h   |    2 +
 vl.c       |   91 +-----------------------------------------------------------
 4 files changed, 90 insertions(+), 90 deletions(-)
os-posix.c +64 -0
index 01dbec2..621ad06 100644
@@ -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
os-win32.c +23 -0
index a936f7a..1758538 100644
@@ -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;
+}
sysemu.h +2 -0
index bb05cf4..72f3734 100644
@@ -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
 {
vl.c +1 -90

103 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#10 lore raw

PATCH v4 10/17 Rename qemu-options.h to qemu-options.def

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 Makefile.objs |    4 ++--
 vl.c          |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
Makefile.objs +2 -2
index 2d94677..124afe7 100644
@@ -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)$@")
 
vl.c +3 -3
index 3e56121..214b9c1 100644
@@ -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
Signature · 1 line
1.6.5.2
#11 lore raw

PATCH v4 11/17 Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 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
Makefile.objs +2 -0
index 124afe7..27595df 100644
@@ -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)$@")
os-posix.c +19 -0
index 621ad06..0deddf3 100644
@@ -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;
+}
os-win32.c +10 -0
index 1758538..aefc535 100644
@@ -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;
+}
qemu-options.h new file +41 -0

41 lines not on this page · raw message

sysemu.h +1 -0
index 72f3734..2162b1d 100644
@@ -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
 {
vl.c +3 -16
index 214b9c1..417c5f3 100644
@@ -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);
             }
         }
     }
Signature · 1 line
1.6.5.2
#12 lore raw

PATCH v4 12/17 Move runas handling from vl.c to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 os-posix.c      |   28 ++++++++++++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   29 +----------------------------
 4 files changed, 31 insertions(+), 28 deletions(-)
os-posix.c +28 -0
index 0deddf3..8b686a4 100644
@@ -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);
+        }
+    }
+}
qemu-os-posix.h +1 -0
index ff5adb1..6d8cf79 100644
@@ -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
qemu-os-win32.h +1 -0
index e7e2ee3..70fdca5 100644
@@ -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
vl.c +1 -28
index 417c5f3..4b76e2d 100644
@@ -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);
Signature · 1 line
1.6.5.2
#13 lore raw

PATCH v4 13/17 Move chroot handling to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Move chroot handling to OS specific files.

---
 os-posix.c      |   19 +++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   18 +-----------------
 4 files changed, 22 insertions(+), 17 deletions(-)
os-posix.c +19 -0
index 8b686a4..6417d16 100644
@@ -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);
+        }
+    }
+
+}
qemu-os-posix.h +1 -0
index 6d8cf79..91c7b68 100644
@@ -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
qemu-os-win32.h +1 -0
index 70fdca5..e2a97d2 100644
@@ -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
vl.c +1 -17
index 4b76e2d..c5f0e63 100644
@@ -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) {
Signature · 1 line
1.6.5.2
#14 lore raw

PATCH v4 14/17 Move daemonize handling to OS specific files

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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

---
 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(-)
os-posix.c +102 -0
index 6417d16..1672e06 100644
@@ -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));
+}
os-win32.c +5 -0
index aefc535..d98fd77 100644
@@ -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));
+}
qemu-os-posix.h +2 -0
index 91c7b68..9b07660 100644
@@ -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
qemu-os-win32.h +2 -0
index e2a97d2..c4aa84a 100644
@@ -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
sysemu.h +1 -0
index 2162b1d..346cccd 100644
@@ -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
 {
vl.c +3 -103

141 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#15 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 5 lines · On Thu, 2010-06-10 at 05:42 -0400, [email protected] wrote:
os-posix.c +0 -0
index 6417d16..1672e06 100644

os-posix.c void os_parse_cmd_args(int index, const char *optarg) · line 170

Quoted 9 lines
os-posix.c +3 -0
@@ -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.

Signature · 15 lines
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
#16 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 19 lines · Frank Arnold
Quoted 5 lines · On Thu, 2010-06-10 at 05:42 -0400, [email protected] wrote:
os-posix.c +0 -0
index 6417d16..1672e06 100644

os-posix.c void os_parse_cmd_args(int index, const char *optarg) · line 170

Quoted 9 lines
os-posix.c +3 -0
@@ -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.

Quoted 8 lines

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

#17 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 26 lines · Jes Sorensen
Quoted 25 lines · Frank Arnold
Quoted 5 lines · On Thu, 2010-06-10 at 05:42 -0400, [email protected] wrote:
os-posix.c +0 -0
index 6417d16..1672e06 100644

os-posix.c void os_parse_cmd_args(int index, const char *optarg) · line 170

Quoted 9 lines
os-posix.c +3 -0
@@ -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.

Quoted 8 lines
Quoted 2 lines

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.

Signature · 15 lines
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
#18 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 43 lines · Frank Arnold
Quoted 26 lines · Jes Sorensen
Quoted 25 lines · Frank Arnold
Quoted 5 lines · On Thu, 2010-06-10 at 05:42 -0400, [email protected] wrote:
os-posix.c +0 -0
index 6417d16..1672e06 100644

os-posix.c void os_parse_cmd_args(int index, const char *optarg) · line 170

Quoted 9 lines
os-posix.c +3 -0
@@ -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.

Quoted 8 lines
Quoted 2 lines

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);

Quoted 7 lines

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:

Quoted 1 line

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

#19 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

In reply to Frank Arnold
Quoted 7 lines · Frank Arnold

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);

Quoted 7 lines

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

#20 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

In reply to Frank Arnold
Quoted 7 lines · Frank Arnold

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);

Quoted 7 lines

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

#21 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 24 lines · Jes Sorensen
Quoted 7 lines · Frank Arnold

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);

Quoted 7 lines

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.

Quoted 4 lines

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.

#22 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 12 lines · Blue Swirl
Quoted 10 lines · Jes Sorensen

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.

Quoted 7 lines

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

#23 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 19 lines · Jes Sorensen
Quoted 18 lines · Blue Swirl
Quoted 10 lines · Jes Sorensen

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.

Quoted 6 lines
Quoted 1 line

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.

#24 lore raw

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

Quoted 8 lines · Blue Swirl
Quoted 4 lines · Jes Sorensen

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

#25 lore raw

[Qemu-devel] Re: [PATCH 14/17] Move daemonize handling to OS specific files

In reply to Jes Sorensen
Quoted 19 lines · Jes Sorensen
Quoted 18 lines · Blue Swirl
Quoted 10 lines · Jes Sorensen

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.

Quoted 6 lines
Quoted 1 line

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

#26 lore raw

PATCH v4 15/17 Make os_change_process_uid and os_change_root os-posix.c local

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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.

---
 os-posix.c      |    8 ++++----
 qemu-os-posix.h |    2 --
 qemu-os-win32.h |    2 --
 3 files changed, 4 insertions(+), 8 deletions(-)
os-posix.c +4 -4
index 1672e06..3a96c91 100644
@@ -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);
qemu-os-posix.h +0 -2
index 9b07660..8be583d 100644
@@ -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);
 
qemu-os-win32.h +0 -2
index c4aa84a..39df333 100644
@@ -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) {}
 
Signature · 1 line
1.6.5.2
#27 lore raw

PATCH v4 16/17 Move line-buffering setup to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Move line-buffering setup to OS specific files.

---
 os-posix.c      |    5 +++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    2 ++
 vl.c            |    5 +----
 4 files changed, 9 insertions(+), 4 deletions(-)
os-posix.c +5 -0
index 3a96c91..9bae8fe 100644
@@ -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);
+}
qemu-os-posix.h +1 -0
index 8be583d..cb210ba 100644
@@ -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);
qemu-os-win32.h +2 -0
index 39df333..5a97d8d 100644
@@ -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
vl.c +1 -4
index 8902477..f18886a 100644
@@ -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");
Signature · 1 line
1.6.5.2
#28 lore raw

PATCH v4 17/17 Move set_proc_name() to OS specific files.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

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.

---
 os-posix.c      |   24 ++++++++++++++++++++++++
 qemu-os-posix.h |    1 +
 qemu-os-win32.h |    1 +
 vl.c            |   19 +------------------
 4 files changed, 27 insertions(+), 18 deletions(-)
os-posix.c +24 -0
index 9bae8fe..d89020d 100644
@@ -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
qemu-os-posix.h +1 -0
index cb210ba..ed5c058 100644
@@ -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);
qemu-os-win32.h +1 -0
index 5a97d8d..6323f7f 100644
@@ -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
vl.c +1 -18
index f18886a..9eac300 100644
@@ -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;
Signature · 1 line
1.6.5.2
Applied
#29 lore raw
In reply to [email protected]

Thanks, applied.

Quoted 53 lines · On Thu, Jun 10, 2010 at 9:42 AM, <[email protected]> wrote:

From: Jes Sorensen <[email protected]>

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