qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	libvir-list@redhat.com, "Stefan Weil" <sw@weilnetz.de>,
	qemu-devel@nongnu.org, "Hanna Reitz" <hreitz@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code
Date: Fri, 4 Mar 2022 16:09:38 -0600	[thread overview]
Message-ID: <20220304220938.kaif7apy472zx2hy@redhat.com> (raw)
In-Reply-To: <20220304185620.3272401-8-berrange@redhat.com>

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@redhat.com>
> ---
>  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@redhat.com>

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



  reply	other threads:[~2022-03-04 22:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 18:56 [PATCH v2 0/8] softmmu: move and refactor -runas, -chroot and -daemonize Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 1/8] softmmu: remove deprecated --enable-fips option Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 2/8] os-posix: refactor code handling the -runas argument Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 3/8] os-posix: refactor code handling the -chroot argument Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code Daniel P. Berrangé
2022-03-04 21:46   ` Eric Blake
2022-03-04 18:56 ` [PATCH v2 5/8] softmmu: refactor use of is_daemonized() method Daniel P. Berrangé
2022-03-04 22:02   ` Eric Blake
2022-03-04 18:56 ` [PATCH v2 6/8] chardev: add API to block use of the stdio implementation Daniel P. Berrangé
2022-03-04 22:03   ` Eric Blake
2022-03-04 18:56 ` [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code Daniel P. Berrangé
2022-03-04 22:09   ` Eric Blake [this message]
2022-03-04 18:56 ` [PATCH v2 8/8] softmmu: remove is_daemonized() method Daniel P. Berrangé
2022-03-04 22:11   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220304220938.kaif7apy472zx2hy@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).