Re: [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 04, 2022 at 06:56:19PM +0000, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
> ---
>  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(-)

> @@ -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,...

> +#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);
>                  }
> -                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,

Reviewed-by: Eric Blake <eblake@xxxxxxxxxx>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux