softmmu: move and refactor -runas, -chroot and -daemonize
PATCH v2 2/8 os-posix: refactor code handling the -runas argument
In reply to Daniel P. BerrangéChange the change_process_uid() function so that it takes its input as parameters instead of relying on static global variables.
--- os-posix.c | 83 +++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 44 deletions(-)
os-posix.c +39 -44
@@ -42,13 +42,9 @@#include <sys/prctl.h> #endif -/* -* Must set all three of these at once. -* Legal combinations are unset by name by uid -*/ -static struct passwd *user_pwd;/* NULL non-NULL NULL */ -static uid_t user_uid = (uid_t)-1 ;/* -1 -1 >=0 */ -static gid_t user_gid = (gid_t)-1 ;/* -1 -1 >=0 */ +static char *user_name; +static uid_t user_uid = (uid_t)-1 ; +static gid_t user_gid = (gid_t)-1 ;static const char *chroot_dir;static int daemonize;
@@ -100,7 +96,8 @@ void os_set_proc_name(const char *s) } -static bool os_parse_runas_uid_gid (const char *optarg) +static bool os_parse_runas_uid_gid (const char *optarg, +uid_t *runas_uid,gid_t *runas_gid) {unsigned long lv;const char *ep;
@@ -120,9 +117,8 @@ static bool os_parse_runas_uid_gid(const char *optarg)return false; } - user_pwd =NULL ; - user_uid = got_uid; - user_gid = got_gid; + *runas_uid = got_uid; + *runas_gid = got_gid;return true; }
@@ -132,13 +128,18 @@ static bool os_parse_runas_uid_gid(const char *optarg)*/ int os_parse_cmd_args (int index,const char *optarg) { +struct passwd *user_pwd; +switch (index) {case QEMU_OPTION_runas: user_pwd =getpwnam (optarg);if (user_pwd) { - user_uid =-1 ; - user_gid =-1 ; - }else if (!os_parse_runas_uid_gid (optarg)) { + user_uid = user_pwd->pw_uid; + user_gid = user_pwd->pw_gid; + user_name =g_strdup (user_pwd->pw_name); + }else if (!os_parse_runas_uid_gid (optarg, + &user_uid, + &user_gid)) {error_report ("User \"%s\" doesn't exist" " (and is not <uid>:<gid>)" , optarg);
@@ -158,41 +159,33 @@ int os_parse_cmd_args(int index, const char *optarg)return 0 ; } -static void change_process_uid (void ) +static void change_process_uid (uid_t uid,gid_t gid,const char *name) { -assert ((user_uid == (uid_t)-1 ) || user_pwd ==NULL ); -assert ((user_uid == (uid_t)-1 ) == - (user_gid == (gid_t)-1 )); - -if (user_pwd || user_uid != (uid_t)-1 ) { -gid_t intended_gid = user_pwd ? user_pwd->pw_gid : user_gid; -uid_t intended_uid = user_pwd ? user_pwd->pw_uid : user_uid; -if (setgid (intended_gid) <0 ) { -error_report ("Failed to setgid(%d)" , intended_gid); -exit (1 ); - } -if (user_pwd) { -if (initgroups (user_pwd->pw_name, user_pwd->pw_gid) <0 ) { -error_report ("Failed to initgroups(\"%s\", %d)" , - user_pwd->pw_name, user_pwd->pw_gid); -exit (1 ); - } - }else { -if (setgroups (1 , &user_gid) <0 ) { -error_report ("Failed to setgroups(1, [%d])" , - user_gid); -exit (1 ); - } - } -if (setuid (intended_uid) <0 ) { -error_report ("Failed to setuid(%d)" , intended_uid); +if (setgid (gid) <0 ) { +error_report ("Failed to setgid(%d)" , gid); +exit (1 ); + } +if (name) { +if (initgroups (name, gid) <0 ) { +error_report ("Failed to initgroups(\"%s\", %d)" , + name, gid);exit (1 ); } -if (setuid (0 ) !=-1 ) { -error_report ("Dropping privileges failed" ); + }else { +if (setgroups (1 , &gid) <0 ) { +error_report ("Failed to setgroups(1, [%d])" , + gid);exit (1 ); } } +if (setuid (uid) <0 ) { +error_report ("Failed to setuid(%d)" , uid); +exit (1 ); + } +if (setuid (0 ) !=-1 ) { +error_report ("Dropping privileges failed" ); +exit (1 ); + } }static void change_root (void )
@@ -275,7 +268,9 @@ void os_setup_post(void) }change_root (); -change_process_uid (); +if (user_uid !=-1 && user_gid !=-1 ) { +change_process_uid (user_uid, user_gid, user_name); + }if (daemonize) {uint8_t status =0 ;
Signature · 1 line
2.34.1
v2 cover softmmu: move and refactor -runas, -chroot and -daemonize
This small series was motivated by my thoughts on the proposals in
https://lists.gnu.org/archive/html/qemu-devel/2022-03/msg01135.html
It demonstrates the approach I mention there, and has the further benefit of untangling and isolating the implementation of UID changing, chrooting and daemonizing, from the parsing of the corresponding command line options.
Changed in v2:
- Fix mistake that left stderr open when daemonizing
- Remove use of is_daemonized from chardev
- Remove use of is_daemonized from logging
- Eliminate is_daemonized function
Daniel P. Berrangé (8):
softmmu: remove deprecated --enable-fips option
os-posix: refactor code handling the -runas argument
os-posix: refactor code handling the -chroot argument
util: remove use of is_daemonized flag from logging code
softmmu: refactor use of is_daemonized() method
chardev: add API to block use of the stdio implementation
softmmu: move parsing of -runas, -chroot and -daemonize code
softmmu: remove is_daemonized() method
chardev/char-stdio.c | 12 +- docs/about/deprecated.rst | 12 -- docs/about/removed-features.rst | 11 ++ include/chardev/char-stdio.h | 29 ++++ include/qemu/log.h | 1 + include/qemu/osdep.h | 3 - include/sysemu/os-posix.h | 6 +- include/sysemu/os-win32.h | 6 - os-posix.c | 227 ++++++++++---------------------- os-win32.c | 9 -- qemu-options.hx | 10 -- softmmu/vl.c | 92 +++++++++++-- stubs/is-daemonized.c | 9 -- stubs/meson.build | 1 - ui/vnc.c | 7 - util/log.c | 12 +- util/osdep.c | 28 ---- 17 files changed, 213 insertions(+), 262 deletions(-) create mode 100644 include/chardev/char-stdio.h delete mode 100644 stubs/is-daemonized.c
Signature · 1 line
2.34.1
PATCH v2 5/8 softmmu: refactor use of is_daemonized() method
Use of the is_daemonized() method is isolated to allow it to be more easily eliminated in a future change.
--- softmmu/vl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
softmmu/vl.c +7 -6
@@ -1371,11 +1371,11 @@ static void qemu_disable_default_devices(void) } } -static void qemu_create_default_devices (void ) +static void qemu_create_default_devices (bool daemonize) {MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); -if (is_daemonized ()) { +if (daemonize) {/* According to documentation and historically, -nographic redirects * serial port, parallel port and monitor to stdio, which does not work * with -daemonize. We can redirect these to null instead, but since
@@ -2455,7 +2455,8 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } -static void qemu_validate_options (const QDict *machine_opts) +static void qemu_validate_options (const QDict *machine_opts, +bool daemonize) {const char *kernel_filename =qdict_get_try_str (machine_opts,"kernel" );const char *initrd_filename =qdict_get_try_str (machine_opts,"initrd" );
@@ -2484,7 +2485,7 @@ static void qemu_validate_options(const QDict *machine_opts) }#ifdef CONFIG_CURSES -if (is_daemonized () && dpy.type ==DISPLAY_TYPE_CURSES ) { +if (daemonize && dpy.type ==DISPLAY_TYPE_CURSES ) {error_report ("curses display cannot be used with -daemonize" );exit (1 ); }
@@ -3676,7 +3677,7 @@ void qemu_init(int argc, char **argv, char **envp)*/ loc_set_none (); -qemu_validate_options (machine_opts_dict); +qemu_validate_options (machine_opts_dict,is_daemonized ());qemu_process_sugar_options ();/*
@@ -3714,7 +3715,7 @@ void qemu_init(int argc, char **argv, char **envp)suspend_mux_open ();qemu_disable_default_devices (); -qemu_create_default_devices (); +qemu_create_default_devices (is_daemonized ());qemu_create_early_backends ();qemu_apply_legacy_machine_options (machine_opts_dict);
Signature · 1 line
2.34.1
PATCH v2 3/8 os-posix: refactor code handling the -chroot argument
In reply to Daniel P. BerrangéChange the change_root() function so that it takes its input as parameters instead of relying on static global variables.
--- os-posix.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
os-posix.c +11 -12
@@ -188,19 +188,16 @@ static void change_process_uid(uid_t uid, gid_t gid, const char *name) } } -static void change_root (void ) +static void change_root (const char *root) { -if (chroot_dir) { -if (chroot (chroot_dir) <0 ) { -error_report ("chroot failed" ); -exit (1 ); - } -if (chdir ("/" )) { -error_report ("not able to chdir to /: %s" ,strerror (errno)); -exit (1 ); - } +if (chroot (root) <0 ) { +error_report ("chroot failed" ); +exit (1 ); + } +if (chdir ("/" )) { +error_report ("not able to chdir to /: %s" ,strerror (errno)); +exit (1 ); } - }void os_daemonize (void )
@@ -267,7 +264,9 @@ void os_setup_post(void) } } -change_root (); +if (chroot_dir) { +change_root (chroot_dir); + }if (user_uid !=-1 && user_gid !=-1 ) {change_process_uid (user_uid, user_gid, user_name); }
Signature · 1 line
2.34.1
PATCH v2 4/8 util: remove use of is_daemonized flag from logging code
In reply to Daniel P. BerrangéWe want to decouple knowledge of daemonization from other code. What the logging code really wants to know is whether it can use stdio or not. Add an API to let the logging code be informed of this fact explicitly.
--- include/qemu/log.h | 1 + softmmu/vl.c | 3 +++ util/log.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-)
include/qemu/log.h +1 -0
@@ -147,6 +147,7 @@ typedef struct QEMULogItem {extern const QEMULogItem qemu_log_items[]; +void qemu_log_stdio_disable (void );void qemu_set_log (int log_flags);void qemu_log_needs_buffers (void );void qemu_set_log_filename (const char *filename,Error **errp);
softmmu/vl.c +3 -0
@@ -3664,6 +3664,9 @@ void qemu_init(int argc, char **argv, char **envp)error_report ("Option not supported in this build" );exit (1 ); } +if (is_daemonized ()) { +qemu_log_stdio_disable (); + } } } }
util/log.c +9 -3
@@ -33,6 +33,12 @@ QemuLogFile *qemu_logfile;int qemu_loglevel;static int log_append =0 ;static GArray *debug_regions; +static bool stdio_disabled; + +void qemu_log_stdio_disable (void ) +{ + stdio_disabled = true; +}/* Return the number of characters emitted. */ int qemu_log (const char *fmt, ...)
@@ -92,7 +98,7 @@ void qemu_set_log(int log_flags)* If we are daemonized, * we will only log if there is a logfilename. */ -if (qemu_loglevel && (!is_daemonized () || logfilename)) { +if (qemu_loglevel && (!stdio_disabled || logfilename)) { need_to_open_file = true; }QEMU_LOCK_GUARD (&qemu_logfile_mutex);
@@ -110,7 +116,7 @@ void qemu_set_log(int log_flags)_exit (1 ); }/* In case we are a daemon redirect stderr to logfile */ -if (is_daemonized ()) { +if (stdio_disabled) {dup2 (fileno (logfile->fd),STDERR_FILENO );fclose (logfile->fd);/* This will skip closing logfile in qemu_log_close() */
@@ -118,7 +124,7 @@ void qemu_set_log(int log_flags) } }else {/* Default to stderr if no log file specified */ -assert (!is_daemonized ()); +assert (!stdio_disabled); logfile->fd = stderr; }/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
Signature · 1 line
2.34.1
PATCH v2 1/8 softmmu: remove deprecated --enable-fips option
In reply to Daniel P. BerrangéUsers requiring FIPS support must build QEMU with either the libgcrypt or gnutls libraries as the crytography backend.
--- docs/about/deprecated.rst | 12 ------------ docs/about/removed-features.rst | 11 +++++++++++ include/qemu/osdep.h | 3 --- os-posix.c | 8 -------- qemu-options.hx | 10 ---------- ui/vnc.c | 7 ------- util/osdep.c | 28 ---------------------------- 7 files changed, 11 insertions(+), 68 deletions(-)
docs/about/deprecated.rst +0 -12
@@ -67,18 +67,6 @@ and will cause a warning. The replacement for the ``nodelay`` short-form boolean option is ``nodelay=on`` rather than ``delay=off``. -``--enable-fips`` (since 6.0) -''''''''''''''''''''''''''''' - -This option restricts usage of certain cryptographic algorithms when -the host is operating in FIPS mode. - -If FIPS compliance is required, QEMU should be built with the ``libgcrypt`` -library enabled as a cryptography provider. - -Neither the ``nettle`` library, or the built-in cryptography provider are -supported on FIPS enabled hosts. - ``-writeconfig`` (since 6.0) '''''''''''''''''''''''''''''
docs/about/removed-features.rst +11 -0
@@ -336,6 +336,17 @@ for the RISC-V ``virt`` machine and ``sifive_u`` machine. The ``-no-quit`` was a synonym for ``-display ...,window-close=off`` which should be used instead. +``--enable-fips`` (removed in 7.0) +'''''''''''''''''''''''''''''''''' + +This option restricted usage of certain cryptographic algorithms when +the host is operating in FIPS mode. + +If FIPS compliance is required, QEMU should be built with the ``libgcrypt`` +or ``gnutls`` library enabled as a cryptography provider. + +Neither the ``nettle`` library, or the built-in cryptography provider are +supported on FIPS enabled hosts. QEMU Machine Protocol (QMP) commands ------------------------------------
include/qemu/osdep.h +0 -3
@@ -534,9 +534,6 @@ static inline void qemu_timersub(const struct timeval *val1,void qemu_set_cloexec (int fd); -void fips_set_state (bool requested); -bool fips_get_state (void ); -/* Return a dynamically allocated pathname denoting a file or directory that is * appropriate for storing local state. *
os-posix.c +0 -8
@@ -151,14 +151,6 @@ int os_parse_cmd_args(int index, const char *optarg)case QEMU_OPTION_daemonize: daemonize =1 ;break ; -#if defined(CONFIG_LINUX ) -case QEMU_OPTION_enablefips: -warn_report ("-enable-fips is deprecated, please build QEMU with " -"the `libgcrypt` library as the cryptography provider " -"to enable FIPS compliance" ); -fips_set_state (true); -break ; -#endif default :return -1 ; }
qemu-options.hx +0 -10
@@ -4655,16 +4655,6 @@ HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL) DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL) -#ifdef __linux__ -DEF("enable-fips", 0, QEMU_OPTION_enablefips, - "-enable-fips enable FIPS 140-2 compliance\n", - QEMU_ARCH_ALL) -#endif -SRST -``-enable-fips`` - Enable FIPS 140-2 compliance mode. -ERST - DEF("msg", HAS_ARG, QEMU_OPTION_msg, "-msg [timestamp[=on|off]][,guest-name=[on|off]]\n" " control error message format\n"
ui/vnc.c +0 -7
@@ -4051,13 +4051,6 @@ void vnc_display_open(const char *id, Error **errp) password =qemu_opt_get_bool (opts,"password" , false); }if (password) { -if (fips_get_state ()) { -error_setg (errp, -"VNC password auth disabled due to FIPS mode, " -"consider using the VeNCrypt or SASL authentication " -"methods as an alternative" ); - goto fail; - }if (!qcrypto_cipher_supports (QCRYPTO_CIPHER_ALG_DES ,QCRYPTO_CIPHER_MODE_ECB )) { error_setg(errp,
util/osdep.c +0 -28
@@ -43,8 +43,6 @@ extern int madvise(char *, size_t, int);#include "qemu/hw-version.h" #include "monitor/monitor.h" -static bool fips_enabled = false; -static const char *hw_version =QEMU_HW_VERSION ;int socket_set_cork (int fd,int v)
@@ -526,32 +524,6 @@ const char *qemu_hw_version(void)return hw_version; } -void fips_set_state (bool requested) -{ -#ifdef __linux__ -if (requested) { -FILE *fds =fopen ("/proc/sys/crypto/fips_enabled" ,"r" ); -if (fds !=NULL ) { - fips_enabled = (fgetc (fds) =='1' ); -fclose (fds); - } - } -#else - fips_enabled = false; -#endif /* __linux__ */ - -#ifdef _FIPS_DEBUG -fprintf (stderr,"FIPS mode %s (requested %s)\n" , - (fips_enabled ?"enabled" :"disabled" ), - (requested ?"enabled" :"disabled" )); -#endif -} - -bool fips_get_state (void ) -{ -return fips_enabled; -} -#ifdef _WIN32static void socket_cleanup (void ) {
Signature · 1 line
2.34.1
PATCH v2 8/8 softmmu: remove is_daemonized() method
In reply to Daniel P. BerrangéThere are no longer any users of this method, so it can be removed to prevent future accidental (mis)use.
--- include/sysemu/os-posix.h | 2 -- include/sysemu/os-win32.h | 5 ----- os-posix.c | 5 ----- stubs/is-daemonized.c | 9 --------- stubs/meson.build | 1 - 5 files changed, 22 deletions(-) delete mode 100644 stubs/is-daemonized.c
include/sysemu/os-posix.h +0 -2
@@ -57,8 +57,6 @@ int os_mlock(void);typedef struct timeval qemu_timeval ;#define qemu_gettimeofday (tp) gettimeofday(tp, NULL) -bool is_daemonized (void ); -/** * qemu_alloc_stack: * @sz: pointer to a size_t holding the requested usable stack size
include/sysemu/os-win32.h +0 -5
@@ -76,11 +76,6 @@ typedef struct { } qemu_timeval;int qemu_gettimeofday (qemu_timeval *tp); -static inline bool is_daemonized (void ) -{ -return false; -} -static inline int os_mlock (void ) {return -ENOSYS ;
os-posix.c +0 -5
@@ -232,11 +232,6 @@ void os_set_line_buffering(void)setvbuf (stdout,NULL , _IOLBF,0 ); } -bool is_daemonized (void ) -{ -return daemonize; -} -int os_mlock (void ) {#ifdef HAVE_MLOCKALL
stubs/is-daemonized.c deleted +0 -9
@@ -1,9 +0,0 @@ -#include "qemu/osdep.h" - -/* Win32 has its own inline stub */ -#ifndef _WIN32 -bool is_daemonized (void ) -{ -return false; -} -#endif
stubs/meson.build +0 -1
@@ -18,7 +18,6 @@ if linux_io_uring.found() endif stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('isa-bus.c')) -stub_ss.add(files('is-daemonized.c')) if libaio.found() stub_ss.add(files('linux-aio.c')) endif
Signature · 1 line
2.34.1
PATCH v2 6/8 chardev: add API to block use of the stdio implementation
In reply to Daniel P. BerrangéWhen daemonizing QEMU it is not possible to use the stdio chardev backend because the file descriptors are connected to /dev/null. Currently the chardev checks for this scenario directly, but to decouple it from the system emulator daemonizing code, we reverse the relationship. Now the system emulator calls a helper to explicitly disable use of the stdio backend.
--- chardev/char-stdio.c | 12 ++++++++++-- include/chardev/char-stdio.h | 29 +++++++++++++++++++++++++++++ softmmu/vl.c | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 include/chardev/char-stdio.h
chardev/char-stdio.c +10 -2
@@ -28,6 +28,7 @@#include "qemu/sockets.h" #include "qapi/error.h" #include "chardev/char.h" +#include "chardev/char-stdio.h" #ifdef _WIN32#include "chardev/char-win.h"
@@ -37,6 +38,13 @@#include "chardev/char-fd.h" #endif +static bool stdio_disabled; + +void qemu_chr_stdio_disable (void ) +{ + stdio_disabled = true; +} +#ifndef _WIN32/* init terminal so that we can grab keys */ static struct termios oldtty;
@@ -90,8 +98,8 @@ static void qemu_chr_open_stdio(Chardev *chr,ChardevStdio *opts = backend->u.stdio.data;struct sigaction act; -if (is_daemonized ()) { -error_setg (errp,"cannot use stdio with -daemonize" ); +if (stdio_disabled) { +error_setg (errp,"cannot use stdio with this configuration" );return ; }
include/chardev/char-stdio.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* 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 CHAR_STDIO_H +#define CHAR_STDIO_H + +void qemu_chr_stdio_disable (void ); + +#endif /* CHAR_STDIO_H */
softmmu/vl.c +2 -0
@@ -69,6 +69,7 @@#include "exec/gdbstub.h" #include "qemu/timer.h" #include "chardev/char.h" +#include "chardev/char-stdio.h" #include "qemu/bitmap.h" #include "qemu/log.h" #include "sysemu/blockdev.h"
@@ -3667,6 +3668,7 @@ void qemu_init(int argc, char **argv, char **envp) }if (is_daemonized ()) {qemu_log_stdio_disable (); +qemu_chr_stdio_disable (); } } }
Signature · 1 line
2.34.1
PATCH v2 7/8 softmmu: move parsing of -runas, -chroot and -daemonize code
In reply to Daniel P. BerrangéWith the future intent to try to move to a fully QAPI driven configuration system, we want to have any current command parsing well isolated from logic that applies the resulting configuration.
We also don't want os-posix.c to contain code that is specific to the system emulators, as this file is linked to other binaries too.
To satisfy these goals, we move parsing of the -runas, -chroot and -daemonize code out of the os-posix.c helper code, and pass the parsed data into APIs in os-posix.c.
As a side benefit the 'os_daemonize()' function now lives up to its name and will always daemonize, instead of using global state to decide to be a no-op sometimes.
--- include/sysemu/os-posix.h | 4 +- include/sysemu/os-win32.h | 1 - os-posix.c | 148 +++++++++++--------------------------- os-win32.c | 9 --- softmmu/vl.c | 86 ++++++++++++++++++---- 5 files changed, 117 insertions(+), 131 deletions(-)
include/sysemu/os-posix.h +3 -1
@@ -46,7 +46,9 @@ 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 ); +void os_setup_post (const char *chroot_dir, +uid_t uid,gid_t gid, +const char *username);int os_mlock (void );#define closesocket (s) close(s)
include/sysemu/os-win32.h +0 -1
@@ -61,7 +61,6 @@ struct tm *localtime_r(const time_t *timep, struct tm *result);static inline void os_setup_signal_handling (void ) {}static inline void os_daemonize (void ) {} -static inline void os_setup_post (void ) {}void os_set_line_buffering (void );static inline void os_set_proc_name (const char *dummy) {}
os-posix.c +41 -107
186 lines not on this page · raw message
os-win32.c +0 -9
@@ -61,12 +61,3 @@ void os_set_line_buffering(void)setbuf (stdout,NULL );setbuf (stderr,NULL ); } - -/* -* Parse OS specific command line options. -* return 0 if option handled, -1 otherwise -*/ -int os_parse_cmd_args (int index,const char *optarg) -{ -return -1 ; -}
softmmu/vl.c +73 -13
138 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code
In reply to Daniel P. BerrangéQuoted 11 lines · Daniel P. Berrangé
We want to decouple knowledge of daemonization from other code. What the logging code really wants to know is whether it can use stdio or not. Add an API to let the logging code be informed of this fact explicitly.
Signed-off-by Daniel P. Berrangé <[email protected]>--- include/qemu/log.h | 1 + softmmu/vl.c | 3 +++ util/log.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 5/8] softmmu: refactor use of is_daemonized() method
In reply to Daniel P. BerrangéQuoted 7 lines · Daniel P. Berrangé
Use of the
is_daemonized()method is isolated to allow it to be more easily eliminated in a future change.Signed-off-by Daniel P. Berrangé <[email protected]>--- softmmu/vl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 6/8] chardev: add API to block use of the stdio implementation
In reply to Daniel P. BerrangéQuoted 7 lines · Daniel P. Berrangé
When daemonizing QEMU it is not possible to use the stdio chardev backend because the file descriptors are connected to
/dev/null. Currently the chardev checks for this scenario directly, but to decouple it from the system emulator daemonizing code, we reverse the relationship. Now the system emulator calls a helper to explicitly disable use of the stdio backend.
Quoted 8 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- chardev/char-stdio.c | 12 ++++++++++-- include/chardev/char-stdio.h | 29 +++++++++++++++++++++++++++++ softmmu/vl.c | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 include/chardev/char-stdio.h
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code
In reply to Daniel P. BerrangéQuoted 27 lines · Daniel P. Berrangé
With the future intent to try to move to a fully QAPI driven configuration system, we want to have any current command parsing well isolated from logic that applies the resulting configuration.
We also don't want
os-posix.cto contain code that is specific to the system emulators, as this file is linked to other binaries too.To satisfy these goals, we move parsing of the -runas, -chroot and -daemonize code out of the
os-posix.chelper code, and pass the parsed data into APIs inos-posix.c.As a side benefit the '
os_daemonize()' function now lives up to its name and will always daemonize, instead of using global state to decide to be a no-op sometimes.Signed-off-by Daniel P. Berrangé <[email protected]>--- include/sysemu/os-posix.h | 4 +- include/sysemu/os-win32.h | 1 - os-posix.c | 148 +++++++++++--------------------------- os-win32.c | 9 --- softmmu/vl.c | 86 ++++++++++++++++++---- 5 files changed, 117 insertions(+), 131 deletions(-)
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 2814
Quoted 4 lines
softmmu/vl.c +1
-0@@ -2780,6 +2811,14 @@ void qemu_init(int argc, char **argv, char **envp)MachineClass *machine_class;bool userconfig = true;FILE *vmstate_dump_file =NULL ; +bool daemonize = false;
Given this declaration,...
Quoted 32 lines
softmmu/vl.c +20
-3+#ifndef WIN32 +struct passwd *pwd; +uid_t runas_uid =-1 ; +gid_t runas_gid =-1 ; + g_autofree char *runas_name = NULL; +const char *chroot_dir =NULL ; +#endif /* !WIN32 */ qemu_add_opts (&qemu_drive_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);@@ -3661,15 +3700,34 @@ void qemu_init(int argc, char **argv, char **envp)case QEMU_OPTION_nouserconfig:/* Nothing to be parsed here. Especially, do not error out below. */ break ; -default : -if (os_parse_cmd_args (popt->index, optarg)) { -error_report ("Option not supported in this build" ); +#ifndef WIN32 +case QEMU_OPTION_runas: + pwd =getpwnam (optarg); +if (pwd) { + runas_uid = pwd->pw_uid; + runas_gid = pwd->pw_gid; + runas_name =g_strdup (pwd->pw_name); + }else if (!os_parse_runas_uid_gid (optarg, + &runas_uid, + &runas_gid)) { +error_report ("User \"%s\" doesn't exist" +" (and is not <uid>:<gid>)" , + optarg);exit (1 ); }
softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 3723
Quoted 10 lines
softmmu/vl.c +6
-4-if (is_daemonized ()) { -qemu_log_stdio_disable (); -qemu_chr_stdio_disable (); - } +break ; +case QEMU_OPTION_chroot: + chroot_dir = optarg; +break ; +case QEMU_OPTION_daemonize: + daemonize =1 ;
...this should s/1/true/. With that tweak,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v2 8/8] softmmu: remove is_daemonized() method
In reply to Daniel P. BerrangéQuoted 4 lines · Daniel P. Berrangé
There are no longer any users of this method, so it can be removed to prevent future accidental (mis)use.
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 8 lines
--- include/sysemu/os-posix.h | 2 -- include/sysemu/os-win32.h | 5 ----- os-posix.c | 5 ----- stubs/is-daemonized.c | 9 --------- stubs/meson.build | 1 - 5 files changed, 22 deletions(-) delete mode 100644 stubs/is-daemonized.c
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org