From: Karel Zak <kzak@redhat.com>
To: Dave Reisner <d@falconindy.com>
Cc: util-linux@vger.kernel.org, Dave Reisner <dreisner@archlinux.org>
Subject: Re: [PATCH 2/2] mountpoint: fallback on stat when /proc isn't mounted
Date: Tue, 11 Oct 2011 10:52:51 +0200 [thread overview]
Message-ID: <20111011085251.GI11730@nb.net.home> (raw)
In-Reply-To: <1318131111-30395-2-git-send-email-dreisner@archlinux.org>
On Sat, Oct 08, 2011 at 11:31:51PM -0400, Dave Reisner wrote:
> mountpoint will fail when /proc isn't available, which lessens its
> usefulness as a tool to detect mountpoints. In this case, mimic what
> sysvinit's mountpoint tool does and compare the device and inode values
> of root and specified target.
>
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> ---
> Rationale: I think this patch is especially important for folks who are still
> using sysvinit. Particularly in the case of a user not having an initramfs, the
> userspace initscripts need to be able to detect, without fail, the presence of
> /proc, /sys, and /dev being mounted (and mount them when they aren't). While
> checking for /proc first and mounting it when mountpoint returns failure will
> result in the correct action, it's reliant on broken behavior -- that is,
> mountpoint returned false because /proc isn't mounted, not because /proc isn't
> a mountpoint.
Good point.
> sys-utils/mountpoint.c | 15 +++++++++++++--
> 1 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c
> index 065d96b..1297d82 100644
> --- a/sys-utils/mountpoint.c
> +++ b/sys-utils/mountpoint.c
> @@ -46,8 +46,19 @@ static dev_t dir_to_device(const char *spec)
> struct libmnt_fs *fs;
> dev_t res = (dev_t)-1;
>
> - if (!tb)
> - return (dev_t)-1;
> + if (!tb) {
> + struct stat root_st, spec_st;
> +
> + /* fallback on using stat when /proc isn't available. return success when
> + * we're examining different devices or encounter an exact match for the
> + * root device */
> + if (stat(spec, &spec_st) == 0 && stat("/", &root_st) == 0 &&
> + root_st.st_dev != spec_st.st_dev ||
> + (root_st.st_dev == spec_st.st_dev && root_st.st_ino == spec_st.st_ino))
Hmm ... && ... || ..., you forgot brackets here ;-)
Anyway, this is very poor solution. The tradition way how to detect
mountpoint is compare "/path" and /path/.."
Fixed, applied.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2011-10-11 8:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-09 3:31 [PATCH 1/2] mountpoint: return dev_t from dir_to_device Dave Reisner
2011-10-09 3:31 ` [PATCH 2/2] mountpoint: fallback on stat when /proc isn't mounted Dave Reisner
2011-10-11 8:52 ` Karel Zak [this message]
2011-10-09 21:23 ` [PATCH 1/2] mountpoint: return dev_t from dir_to_device Dave Reisner
2011-10-11 8:21 ` Karel Zak
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=20111011085251.GI11730@nb.net.home \
--to=kzak@redhat.com \
--cc=d@falconindy.com \
--cc=dreisner@archlinux.org \
--cc=util-linux@vger.kernel.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).