From: "Clément Léger" <cleger@rivosinc.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Michael Tokarev" <mjt@tls.msk.ru>,
"Paolo Bonzini" <pbonzini@redhat.com>,
qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Daniel P . Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH 2/2] qemu/osdep: handle sysconf(_SC_OPEN_MAX) return value == -1
Date: Tue, 3 Sep 2024 09:53:02 +0200 [thread overview]
Message-ID: <563f3b75-bf13-4ca7-a995-f2c8ff1b6799@rivosinc.com> (raw)
In-Reply-To: <294a5480-d871-41e2-8e08-c1067f45d454@linaro.org>
On 02/09/2024 21:38, Philippe Mathieu-Daudé wrote:
> On 30/8/24 13:57, Clément Léger wrote:
>> On 30/08/2024 13:31, Michael Tokarev wrote:
>>> 30.08.2024 14:14, Clément Léger wrote:
>>>> On some systems (MacOS for instance), sysconf(_SC_OPEN_MAX) can return
>>>> -1. In that case we should fallback to using the OPEN_MAX define.
>>>> According to "man sysconf", the OPEN_MAX define should be present and
>>>> provided by either unistd.h and/or limits.h so include them for that
>>>> purpose. For other OSes, just assume a maximum of 1024 files
>>>> descriptors
>>>> as a fallback.
>>>>
>>>> Fixes: 4ec5ebea078e ("qemu/osdep: Move close_all_open_fds() to oslib-
>>>> posix")
>>>> Reported-by: Daniel P. Berrangé <berrange@redhat.com>
>>>> Signed-off-by: Clément Léger <cleger@rivosinc.com>
>>>
>>> Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
>>>
>>>> @@ -928,6 +933,13 @@ static void qemu_close_all_open_fd_fallback(const
>>>> int *skip, unsigned int nskip,
>>>> void qemu_close_all_open_fd(const int *skip, unsigned int nskip)
>>>> {
>>>> int open_max = sysconf(_SC_OPEN_MAX);
>>>> + if (open_max == -1) {
>>>> +#ifdef CONFIG_DARWIN
>>>> + open_max = OPEN_MAX;
>
> Missing errno check.
man sysconf states that:
"On error, -1 is returned and errno is set to indicate the error (for
example, EINVAL, indicating that name is invalid)."
So it seems checking for -1 is enough no ? Or were you thinking about
something else ?
>
>>>> +#else
>>>> + open_max = 1024;
>>>> +#endif
>>>
>>> BTW, Can we PLEASE cap this to 1024 in all cases? :)
>>> (unrelated to this change but still).
>>
>> Hi Michael,
>>
>> Do you mean for all OSes or always using 1024 rather than using the
>> sysconf returned value ?
>
> Alternatively add:
>
> long qemu_sysconf(int name, long unsupported_default);
>
> which returns value, unsupported_default if not supported, or -1.
Acked, should this be a global function even if only used in the
qemu_close_all_open_fd() helper yet ?
Thanks,
Clément
>
>>
>> In any case, the code now uses close_range() or /proc/self/fd and is
>> handling that efficiently.
>>
>> Thanks,
>>
>> Clément
>>
>>>
>>> /mjt
>>
>>
>
next prev parent reply other threads:[~2024-09-03 7:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-30 11:14 [PATCH 0/2] oslib: fix OSes support for qemu_close_all_open_fd() Clément Léger
2024-08-30 11:14 ` [PATCH 1/2] qemu/osdep: fix current process fds path for other OSes Clément Léger
2024-08-30 11:16 ` Daniel P. Berrangé
2024-08-30 11:31 ` Michael Tokarev
2024-08-30 11:14 ` [PATCH 2/2] qemu/osdep: handle sysconf(_SC_OPEN_MAX) return value == -1 Clément Léger
2024-08-30 11:18 ` Daniel P. Berrangé
2024-08-30 11:31 ` Michael Tokarev
2024-08-30 11:57 ` Clément Léger
2024-09-02 19:38 ` Philippe Mathieu-Daudé
2024-09-03 7:53 ` Clément Léger [this message]
2024-09-03 13:34 ` Philippe Mathieu-Daudé
2024-09-03 13:37 ` Clément Léger
2024-09-03 15:02 ` Philippe Mathieu-Daudé
2024-09-03 15:21 ` Daniel P. Berrangé
2024-09-03 17:56 ` Philippe Mathieu-Daudé
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=563f3b75-bf13-4ca7-a995-f2c8ff1b6799@rivosinc.com \
--to=cleger@rivosinc.com \
--cc=berrange@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--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 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).