Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 336723

Summary: baselayout-1_12 (rev. 3163): we cannot rely on stat (associated with #291916)
Product: Gentoo Linux Reporter: Amadeusz Żołnowski (RETIRED) <aidecoe>
Component: [OLD] baselayoutAssignee: Gentoo's Team for Core System packages <base-system>
Severity: major    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---
Bug Depends on: 291916    
Bug Blocks: 336726    

Description Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-10 14:22:30 UTC
To solve bug #291916, /usr/bin/stat is used (to check if given directory is a mount point). Although we cannot rely on /usr/bin/stat at this very beginning of rc.

Reproducible: Always

Steps to Reproduce:
1. Move /usr to separate partition and append "/dev/foo /usr fs opts x y" to /etc/fstab.
2. Reboot

Actual Results:  
Fails just before mounting /proc.

Expected Results:  
Mount /proc, /sys (or skip if already mounted) and continue booting.
Comment 1 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-10 14:34:06 UTC
Created attachment 246715 [details, diff]

Provides functions 'is_mounted' and 'is_clean'.

'is_mounted' checks if specified device is really mounted under specified mount point.

'is_clean' checks if there are any files inside given directory (omits hidden ones).
Comment 2 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-10 14:46:10 UTC
Created attachment 246716 [details, diff]

We use new 'is_mounted' (see: instead of 'stat MOUNT_POINT -c %d' and new more generic 'is_clean' instead of check for individual files.
Comment 3 SpanKY gentoo-dev 2010-09-18 09:03:21 UTC
why does is_mounted need to check /proc/mounts ?  seems like simply replacing the call to `stat` with `mountpoint` would be sufficient.

assuming /proc/mounts needs to be checked, it should be done in one shot instead of reading it line by line:
[[ $(</proc/mounts) =~ ... ]]

the is_clean needs to declare "f" local, 
Comment 4 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-18 16:31:57 UTC
Created attachment 247871 [details, diff]

I've corrected it according to SpanKY's suggestions. Thank you!

Why I'm checking /proc/mounts? Previously there was check for files specific to particular file system, so I've done more universal check. As you can see it's optional, so invoking 'is_mounted /some/mount/point' just checks if it's a mount point.
Comment 5 SpanKY gentoo-dev 2010-09-19 22:17:50 UTC
i meant, why is "is_mounted" checking /proc/mounts ?  why cant the func merely call `mountpoint` ?
is_mounted() { mountpoint -q "$1" ; }
Comment 6 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-20 11:21:20 UTC
"is_mounted" is checking /proc/mounts if expected device is really mounted under that mount point and not something else. (Although I can imagine case when that check doesn't give full certainty.)  I agree that just calling `mountpoint` would be sufficient.  Checking /proc/mounts is paranoid a bit.  I'll remove that unnecessary part from "is_mounted" then, OK?
Comment 7 SpanKY gentoo-dev 2010-09-20 20:45:33 UTC
yes, let's keep it simple for now.  it seems to have worked so far for us, so let's avoid the paranoia until we have an actual use case.
Comment 8 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-22 17:44:34 UTC
Created attachment 248375 [details, diff]

Removed /proc/mounts check.
Comment 9 Amadeusz Żołnowski (RETIRED) gentoo-dev 2010-09-22 17:46:56 UTC
Created attachment 248377 [details, diff]

Updated to changes in '*' patch.