From: Greg Kurz <groug@kaod.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH v2 1/2] util/log: Derive thread id from getpid() on hosts w/o gettid() syscall
Date: Fri, 21 Oct 2022 16:08:48 +0200 [thread overview]
Message-ID: <20221021160848.28ff96a4@bahia> (raw)
In-Reply-To: <e5d785bb-3865-75a3-f1aa-c99acf127c5f@redhat.com>
On Thu, 20 Oct 2022 12:39:41 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 10/19/22 17:57, Daniel P. Berrangé wrote:
> >> + if (my_id == -1) {
> >> + my_id = getpid() + qatomic_fetch_inc(&counter);
> >> + }
> >> + return my_id;
> > This doesn't look safe for linux-user when we fork, but don't exec.
>
> Linux-user won't ever get here, however bsd-user might. We should have
> get_thread_id() somewhere in util/, for example
>
> https://github.com/wine-mirror/wine/blob/master/dlls/ntdll/unix/server.c
>
We have qemu_get_thread_id() already :
https://git.qemu.org/?p=qemu.git;a=blob;f=util/oslib-posix.c;h=827a7aadba444cdb128284f5b4ba43934c78c3db;hb=HEAD#l96
> > The getpid() will change after the fork, but counter won't be
> > reset, so a thread in the parent could clash with a thread
> > in the forked child.
>
> It might clash even if the counter is reset for that matter.
>
Yes.
> Paolo
>
next prev parent reply other threads:[~2022-10-21 14:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 15:16 [PATCH v2 0/2] util/log: Always send errors to logfile when daemonized Greg Kurz
2022-10-19 15:16 ` [PATCH v2 1/2] util/log: Derive thread id from getpid() on hosts w/o gettid() syscall Greg Kurz
2022-10-19 15:57 ` Daniel P. Berrangé
2022-10-20 8:40 ` Greg Kurz
2022-10-20 10:39 ` Paolo Bonzini
2022-10-21 14:08 ` Greg Kurz [this message]
2022-10-19 15:16 ` [PATCH v2 2/2] util/log: Always send errors to logfile when daemonized Greg Kurz
2022-10-20 2:21 ` Richard Henderson
2022-10-20 9:49 ` Greg Kurz
2022-10-20 9:58 ` Daniel P. Berrangé
2022-10-20 10:52 ` Paolo Bonzini
2022-10-24 9:44 ` Alex Bennée
2022-10-25 8:52 ` Greg Kurz
2022-10-25 9:20 ` 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=20221021160848.28ff96a4@bahia \
--to=groug@kaod.org \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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.