From: "Alejandro Colomar (mailing lists; readonly)" <alx.mailinglists@gmail.com>
To: mtk.manpages@gmail.com, Davide Giorgio <davide@giorgiodavide.it>
Cc: linux-man <linux-man@vger.kernel.org>
Subject: Re: pivot_root - wrong check on mount(2)
Date: Thu, 26 Nov 2020 13:28:10 +0100 [thread overview]
Message-ID: <fd7fea8a-b6ea-353d-522b-493782929237@gmail.com> (raw)
In-Reply-To: <CAKgNAkhqn+NRbrmnaTpjMuj96eC6M94vxm8X4w9-F=_cqZi8gg@mail.gmail.com>
On 11/26/20 10:31 AM, Michael Kerrisk (man-pages) wrote:
> Hello Davide,
>
> On Thu, 26 Nov 2020 at 01:01, Davide Giorgio <davide@giorgiodavide.it> wrote:
>>
>> Good morning,
>>
>> reading the pivot_root man page
>> (https://man7.org/linux/man-pages/man2/pivot_root.2.html)
>> there seems to be an error in the example source program
>> "pivot_root_demo.c".
>> In particular, there is a wrong check on the return value of mount(2).
>> https://man7.org/linux/man-pages/man2/mount.2.html#RETURN_VALUE
>>
>> The error is in this line
>> if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == 1)
>>
>> that should be
>> if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == -1)
>>
>>
>> Thank you for your work, kind regards
>
> Thanks! Fixed!
Hi Michael,
What about fixing this from a different approach:
instead of comparing against -1
for functions that either return either 0 or -1,
we can include those functions in the greater family of
functions that return either 0 or non-zero (error code).
I propose comparing against 0:
- if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) == 1)
+ if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0)
I consider this to be safer, simpler,
and although negligible, also faster.
What are your thoughts?
Thanks,
Alex
>
> Cheers,
>
> Michael
>
next prev parent reply other threads:[~2020-11-26 12:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 0:01 pivot_root - wrong check on mount(2) Davide Giorgio
2020-11-26 9:31 ` Michael Kerrisk (man-pages)
2020-11-26 12:28 ` Alejandro Colomar (mailing lists; readonly) [this message]
2020-11-26 13:40 ` Alejandro Colomar (man-pages)
2020-11-27 8:30 ` Michael Kerrisk (man-pages)
2020-11-27 8:45 ` Alejandro Colomar (man-pages)
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=fd7fea8a-b6ea-353d-522b-493782929237@gmail.com \
--to=alx.mailinglists@gmail.com \
--cc=davide@giorgiodavide.it \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/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.