From: Markus Armbruster <armbru@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] vl.c: move pidfile creation up the line
Date: Thu, 03 Nov 2016 08:35:53 +0100 [thread overview]
Message-ID: <8737j9582u.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1478096330-18081-1-git-send-email-mjt@msgid.tls.msk.ru> (Michael Tokarev's message of "Wed, 2 Nov 2016 17:18:50 +0300")
Michael Tokarev <mjt@tls.msk.ru> writes:
> With current code, pid file is open after various
> sockets, chardevs, fsdevs and the like. This causes
> interesting effects, for example when monitor is a
> unix-socket, and another qemu instance is already
> running, new qemu first "damages" the socket and
> next complain that it can't acquire the pid file and
> exits, making running qemu unreachable.
>
> Move pid file creation earlier, right after the call
> to os_daemonize(), where we know our process id (pid).
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> vl.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> v2: move the pid file creation even earlier, as per
> comment by Markus Armbruster
>
> diff --git a/vl.c b/vl.c
> index 368510f..ce7e998 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4058,6 +4058,11 @@ int main(int argc, char **argv, char **envp)
>
> os_daemonize();
>
> + if (pid_file && qemu_create_pidfile(pid_file) != 0) {
> + error_report("could not acquire pid file: %s", strerror(errno));
> + exit(1);
> + }
> +
> if (qemu_init_main_loop(&main_loop_err)) {
> error_report_err(main_loop_err);
> exit(1);
> @@ -4335,11 +4340,6 @@ int main(int argc, char **argv, char **envp)
> }
> #endif
>
> - if (pid_file && qemu_create_pidfile(pid_file) != 0) {
> - error_report("could not acquire pid file: %s", strerror(errno));
> - exit(1);
> - }
> -
> if (qemu_opts_foreach(qemu_find_opts("device"),
> device_help_func, NULL, NULL)) {
> exit(0);
Right after os_daemonize() is as early as possible. There might be
stuff happening before os_daemonize() that shouldn't, but I'm not
demanding you search for it to get this patch in.
The wider problem: we spread around parsing, checking and acting upon
command line options pretty carelessly, even though checking after
daemonize and acting before it is problematic.
Regardless,
Reviewed-by: Markus Armbruster <armbru@redhat.com>
WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] vl.c: move pidfile creation up the line
Date: Thu, 03 Nov 2016 08:35:53 +0100 [thread overview]
Message-ID: <8737j9582u.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1478096330-18081-1-git-send-email-mjt@msgid.tls.msk.ru> (Michael Tokarev's message of "Wed, 2 Nov 2016 17:18:50 +0300")
Michael Tokarev <mjt@tls.msk.ru> writes:
> With current code, pid file is open after various
> sockets, chardevs, fsdevs and the like. This causes
> interesting effects, for example when monitor is a
> unix-socket, and another qemu instance is already
> running, new qemu first "damages" the socket and
> next complain that it can't acquire the pid file and
> exits, making running qemu unreachable.
>
> Move pid file creation earlier, right after the call
> to os_daemonize(), where we know our process id (pid).
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> vl.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> v2: move the pid file creation even earlier, as per
> comment by Markus Armbruster
>
> diff --git a/vl.c b/vl.c
> index 368510f..ce7e998 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4058,6 +4058,11 @@ int main(int argc, char **argv, char **envp)
>
> os_daemonize();
>
> + if (pid_file && qemu_create_pidfile(pid_file) != 0) {
> + error_report("could not acquire pid file: %s", strerror(errno));
> + exit(1);
> + }
> +
> if (qemu_init_main_loop(&main_loop_err)) {
> error_report_err(main_loop_err);
> exit(1);
> @@ -4335,11 +4340,6 @@ int main(int argc, char **argv, char **envp)
> }
> #endif
>
> - if (pid_file && qemu_create_pidfile(pid_file) != 0) {
> - error_report("could not acquire pid file: %s", strerror(errno));
> - exit(1);
> - }
> -
> if (qemu_opts_foreach(qemu_find_opts("device"),
> device_help_func, NULL, NULL)) {
> exit(0);
Right after os_daemonize() is as early as possible. There might be
stuff happening before os_daemonize() that shouldn't, but I'm not
demanding you search for it to get this patch in.
The wider problem: we spread around parsing, checking and acting upon
command line options pretty carelessly, even though checking after
daemonize and acting before it is problematic.
Regardless,
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2016-11-03 7:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-02 14:18 [Qemu-trivial] [PATCH v2] vl.c: move pidfile creation up the line Michael Tokarev
2016-11-02 14:18 ` [Qemu-devel] " Michael Tokarev
2016-11-02 14:22 ` [Qemu-trivial] " Daniel P. Berrange
2016-11-02 14:22 ` Daniel P. Berrange
2016-11-03 7:35 ` Markus Armbruster [this message]
2016-11-03 7:35 ` Markus Armbruster
2016-11-03 8:41 ` [Qemu-trivial] " Paolo Bonzini
2016-11-03 8:41 ` [Qemu-devel] " Paolo Bonzini
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=8737j9582u.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.