Some code fix suggestions in mountall.c

Bug #433672 reported by Anderson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mountall (Ubuntu)
Won't Fix
Undecided
Unassigned

Bug Description

Binary package hint: mountall

Until I discover I'm affected by the bug #430542, I looked mountall's source code during several hours in order to learn how to get my system bootable again. I got my computer working again by changing my "/etc/fstab".

But... I think there are 2 things to be improved in mountall-0.1.6.

-------------------------------

The function "cleanup" (src/mountall.c:907) walks through the list of mount entries and removes the ones which have unknown file system type. The function "parse_filesystems" (src/mountall.c:848) discovers what file system types the kernel supports.

But there is a problem here: some file system types are implemented by kernel modules. These modules may not be loaded into kernel yet, so those file system types won't appear in /proc/filesystem. But, unfortunately, the function "parse_filesystems" don't try to check if unknown file system types could be implemented by not-loaded modules. As a result, "cleanup" drops mount entries which should be mounted.

This is my first suggestion: the function "cleanup" should try to load file system modules before discarding invalid mount entries.

-------------------------------

First, a code example:

// File "test.c" begin
#include <assert.h>
int main (void) {
    int test = 1;
    assert (test--);
    return (test);
}
// File "test.c" end

Build the code with these command lines:
$ gcc -o test_a test.c
$ gcc -DNDEBUG -o test_b test.c

Run these executables:
$ ./test_a ; echo $?
$ ./test_b ; echo $?

You will see the decrement is not executed when NDEBUG is defined (test_b).

Such problem may happen in several lines within mountall.c:
1165: nih_assert (i++ < num_paths);
1675: nih_assert (i++ < num_paths);
1717: nih_assert (i++ < num_paths);
2325: nih_assert (udev = udev_new ());
2326: nih_assert (udev_monitor = udev_monitor_new_from_netlink (udev, "udev"));
2327: nih_assert (udev_monitor_filter_add_match_subsystem_devtype (udev_monitor, "block", NULL) == 0);
2328: nih_assert (udev_monitor_enable_receiving (udev_monitor) == 0);

Perhaps, such errors don't happen now, because "nih_assert" is always compiled. But, in the future, some developer may implement a macro that affects nih_assert() just like NDEBUG affects assert()... If this day comes, the code will break...

This is my second suggestion: change the assertion lines. By example:

1165: nih_assert (i++ < num_paths);

Change to:

1165: nih_assert (i < num_paths); i++;

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

cleanup only discards filesystem entries where device is NULL, ie. builtins - these are required to be built-in, and is used to implement the architecture-dependent filesystems like spufs

This will never remove a mount record for a filesystem specified in fstab or found from mountinfo

Changed in mountall (Ubuntu):
status: New → Won't Fix
Revision history for this message
Anderson (amg1127) wrote :

You mean... "binfmt_misc.ko" should be builtin?

Should I file a new bug requesting this?

$ modinfo binfmt_misc
filename: /lib/modules/2.6.31-10-generic/kernel/fs/binfmt_misc.ko
license: GPL
srcversion: 3E510EDCB9B738EAD58BC9E
depends:
vermagic: 2.6.31-10-generic SMP mod_unload modversions

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote : Re: [Bug 433672] Re: Some code fix suggestions in mountall.c

On Mon, 2009-09-21 at 19:01 +0000, Anderson wrote:

> You mean... "binfmt_misc.ko" should be builtin?
>
If it's builtin, otherwise this is already handled by the binfmt_misc
initscript

Scott
--
Scott James Remnant
<email address hidden>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.