Commit Graph

590 Commits

Author SHA1 Message Date
Karel Zak 8d31f146ed libmount: fix debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 16:52:14 +01:00
Karel Zak 63c9c05d35 misc: remove %p from debug messages
From libs where suid program may be executed by non-root user.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 13:18:57 +01:00
Ruediger Meier af1bc027db build-sys: remove redundant EXTRA_DIST files
The sources of AC_CONFIG_FILES (*.in) are automatically
distributed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 4beacf105e build-sys: avoid using prog_DEPENDENCIES
Use EXTRA_prog_DEPENDENCIES to have the benefit
of automake's automatic prog_DEPENDENCIES.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 0da03d4490 build-sys: remove unneeded dependencies on bla.h.in
We have already automakes's automatic dependencies like
  bla.h.in -> bla.h -> foo.o -> bar.la

An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier a459f2ec33 build-sys: automake is able to find headers in builddir ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 1d667d8849 build-sys: remove generated headers from dist tar ball
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.

Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.

Also see automake docs 9.4.1 Built Sources Example:
  case "Build bindir.h from configure"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak b5cc232362 libmount: fix mnt_table_is_fs_mounted() for rbind
There is no difference between "bind" and "rbind" if we want to FS
root to search for the FS in mountinfo file.

fstab:

 /dev/sdc1       /mnt/foo        xfs     defaults        0 0
 /mnt/foo        /mnt/test       none    rw,rbind        0 0

use -a more than once:

  mount -a
  mount -a

/proc/mounts (the current result):

 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0

expected (fixed version) result:

 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1528959
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-03 14:02:27 +01:00
Karel Zak ae6fd6802c libmount: add nsfs between pseudo filesystems
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-21 12:11:56 +01:00
Karel Zak 42ee788268 libmount: minimize utimensat() write test usage
utimensat() is pretty expensive when mounting parallel filesystems from
the same source. It's possible to ignore all this if mtab is not
writable.

Note that this change is irrelevant for default util-linux builds
where all around mtab is already disabled since v2.30 (commit
89958178f6).

This change is relevant only for users who still use --enable-libmount-support-mtab.

Reported-by: Douglas Jacobsen <dmjacobsen@lbl.gov>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 12:16:09 +01:00
Karel Zak 06ff935ec3 libmount: fix access() utab write test
The commit c08396c769 replaces
open(O_CREATE) with ecaccess(). Unfortunately, another code depends on
the original behavior.

* let's make utab when really necessary rather than in the try_write() test

* __mnt_new_table_from_file() returns NULL if tab-file does not
 exists. This is incorrect for tab_update.c stuff. We need empty table
 in this case.

* we can check /run/mount/ directory for write access if
  eaccess(filename) return ENOENT (because file does not exist)

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-08 17:03:59 +01:00
Joshua Watt 5d9c796660 libmount: Allow MNT_FORCE and MNT_DETACH at umount
MNT_FORCE and MNT_DETACH are orthogonal in the Linux kernel, so both may
be specified without any problems. Even if there were a problem with
this combination, it should be up to the kernel to take the correct
action or report an error.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
2017-11-08 12:31:43 +01:00
Karel Zak fb7e447486 libmount: check waitpid() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-06 13:22:07 +01:00
Vratislav Podzimek 7440665f9b libmount: Use waitpid() when waiting for mount helper child process
Using wait() in a library may be problematic as it may reap some
totally unrelated child process instead of the just forked
one. That can result in the library call doing weird things and
returning bad return values, but also in a breakage of an
arbitrary other thing in the program using the library.

[[kzak@redhat.com: - use waitpid() for umount too
                   - keep the current codding style]

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-06 13:05:04 +01:00
Karel Zak c08396c769 libmount: use eacess() rather than open() to check mtab/utab
The open() syscall is probably the most strong way how to check write
accessibility in all situations, but it's overkill and on some
paranoid systems with enabled audit/selinux. It fills logs with
"Permission denied" entries. Let's use eaccess() if available.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-20 12:37:04 +02:00
Karel Zak 78c57214ad libmount: make sure we call stat() propely [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-11 14:59:16 +02:00
Karel Zak e8365fc1c6 libmount: add human compatible message for EBADMSG errno
mount: /media/sdb5: mount(2) system call failed: Bad message.

is really ugly for end users. It seems XFS, extN (etc) use EBADMSG for
bad checksums. For network or pseudo filesystems continue to use "Bad
message" error...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1496764
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-02 13:44:29 +02:00
Giuseppe Scrivano f218d8d2f5 libmount: fix Python get_propagation
The current implementation would return always 0, as it is the return
code of mnt_fs_get_propagation.  Change the implementation to raise an
exception on an error and return the propagation flags otherwise.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-09-21 23:18:32 +02:00
Karel Zak d369dc42cb libmount: export locking errors as MNT_EX_FILEIO
The mount man page assumes locking errors mapped to MNT_EX_FILEIO (16)
return code. Unfortunately, this is internally not exported as a
special error code, so it's returned as a generic (errno based)
stuff. This patch fixes this issue.

Note that we still use locking for example for utab or when enabled
/etc/mtab (disabled by default).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 14:30:06 +02:00
Ruediger Meier 21be08ac8c build-sys: don't use non-existing UUID_LIBS
We've added UUID_LIBS in f77a4d1087 but I don't see what it
was good for.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Ivan Delalande b9a5e23fa8 libmount: make mnt_context_is_fs_mounted work for /proc
Assume that /proc is not mounted instead of returning an error when we
are unable to open the mounts and mountinfo files in /proc. Also set
cxt->mtab back to NULL so that it gets properly parsed when we check if
the next filesystem is mounted.

The goal is to have mount -a work when /proc is not mounted, typically
with /proc on the first line of fstab.

Signed-off-by: Ivan Delalande <colona@arista.com>
2017-07-18 09:45:26 +02:00
Karel Zak 41d758f82d libmount: use _exit() in <type> handlers
The originally used exit() is bad idea for the shared library.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 12:58:57 +02:00
Karel Zak 9b76b0e98b libmount: ignore "bind" from fstab on command line "remount"
The current code always apply all flags from /etc/fstab on remount.
Unfortunately remount+bind has special semantic and it's impossible
from command line to avoid interaction with the "bind" from fstab.

Example, fstab:

	/dev/sda1 /bar ext4 defaults 0 1
	/bar /foo none bind 0 0

Command line:

    # mount /foo -o remount,rw

produces:

    mount(... MS_REMOUNT|MS_BIND ) syscall

This changes the per-mountpoint (VFS) ro flag to rw, but doesn't
change the filesystem itself.

This patch forces libmount to ignore "bind" from fstab when "-o
remount" specified on command line. If you need remount+bind semantic
you have to specify the "bind" flag on command line. This allow to
differentiate between

    # mount /foo -o remount,bind,rw  --> mount(MS_REMOUNT|MS_BIND)
and

    # mount /foo -o remount,rw       --> mount(MS_REMOUNT)

Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-20 12:46:02 +02:00
Ruediger Meier 0b5f75e412 libmount: fix warning "set but not used"
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-15 08:56:01 +02:00
Sami Kerola f4d3783867 misc: remove stray semicolons
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:21:29 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier b68d953e62 libmount: btrfs, remove unused setter functions
We have never used them since introduced in 2cd28fc8.
clang compiler warned about it.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Karel Zak 26cd36a636 Merge branch 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux
* 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux:
  pylibmount: NULL terminate kwlist in Context_init
2017-06-12 15:39:59 +02:00
Zac Medico 29b721bc9d pylibmount: NULL terminate kwlist in Context_init
Fixes a segfault observed with python3.6.
2017-06-07 17:25:12 -07:00
Karel Zak 11573ac0c8 libmount: (umount) use mount table filter on -c only
The path canonicalization is the worst use-case, it's better to read
all mount table than try canonicalize.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-07 12:40:17 +02:00
Karel Zak f8416301c1 libmount: use mount table filter on --no-canonicalize
The umount command option --no-canonicalize means that the path is
already canonical. So, we can use mount table filter in this case too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-07 11:35:26 +02:00
NeilBrown ce6e269447 umount: never 'stat' the path when "-c" is given.
It is currently not possible to reliably and automatically
unmount an NFS filesystem. If the server is not available, the
umount command will hang.

The hang can be avoided by using "-l" or "-f", but neither
of these are appropriate for automatic use such as by an
automounter (e.g automountd or systemd).

"-l" will unmount even if the filesystem is in use, which
an automounter generally doesn't want.  If the filesystem
is in use, then the umount should fail.

"-f" can cause the filesystem to abort pending transactions
which might break filesystem semantics.  This can be useful
in the hands of a sysadmin, but not when used by an
automatic tool.

umount has another option, "-c" aka "--no-canonicalize"
which avoids some "stat" calls.
Currently this doesn't avoid all calls to
canonicalize_path()
as
  mnt_context_prepare_umount() ->
    lookup_umount_fs() ->
      mnt_context_find_umount_fs() ->
        mnt_context_get_mtab_for_target() ->
	  mnt_resolve_path() ->
	    canonicalize_path_and_cache() ->
	      canonicalize_path()

leads to that function being called.

The "-c" option could be taken to mean "I know what I'm
doing, this really is the path to a mount point, I just want
you to unmount it".  Given that, it seems suitable to
extend this to avoid all 'stat' calls on the mountpoint.

It is already appropriate for any automount program to pass
"-c" to "umount", so they can be changed to do so at any
time.
With the patch below, "-c" will result in the mountpoint
never being "stat"ed, so umount won't hang on an
inaccessible server.

This isn't quite sufficient, for NFS at least, as the usage
of libmount in umount.nfs still calls 'stat' on the mount
point.
"-c" isn't passed to the umount helper, but it is reasonable
for such helpers to assume "-c" because "umount" will have
canonicalized the path when that is appropriate.

So, this patch treats "-c" much like "-l" and "-f" when
deciding whether it is safe to 'stat' the path.

Signed-off-by: NeilBrown <neilb@suse.com>
2017-06-06 11:41:05 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:

./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 03:16:48 +02:00
Karel Zak a81b1946a1 libmount: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 13:32:45 +02:00
Karel Zak 7a5dbd2258 libmount: don't pass -1 to close() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:45:30 +02:00
Karel Zak fdaba3eb62 libmount: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:38:16 +02:00
Karel Zak 799d9e845f tests: (libmount) parse version from command line
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:28:19 +02:00
Karel Zak 8503c0ed30 libmount: (docs) remove unwanted tag
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 12:39:21 +02:00
Karel Zak 0361cb6f9b libmount: add read-only warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 11:03:24 +02:00
Karel Zak 7b53418bf0 libmount: (docs) add unused declarations
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:17:50 +02:00
Karel Zak ea848180dd libmount: add mnt_context_get_excode()
It's pretty complex task to make mount(8) and umount(8) return code
and generate error message. It seems better to do that in the libmount
rather than force all library users to duplicate mount(8) mk_exit_code()
functions. It also means that all the messages will be translated only
once. Changes:

* all error messages are printed by warn()
* no more multi-line messages
* all messages prefixed by mount target (mountpoint)
* library provides mount(8) compatible MNT_EX_* codes

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1429531
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:10:23 +02:00
Karel Zak 6dede2f2f7 libmount: support MS_RDONLY on write-protected devices
This feature is supported by mount(8) only. It seems better move
this code to libmount. The results is more simple mount(8) and the
feature is accessible for all libmount users.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-26 17:27:02 +02:00
Stanislav Brabec ecfeae90a2 libmount: Ensure utab.lock mode 644
If utab.lock is created by a process with a restricted umask, utab.lock is
created with restricted permissions. It breaks userspace monitor.

Ensure that the mode is always 644.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-04-18 11:13:32 +02:00
Sami Kerola a0a32456c8 libmount: fix file descriptor leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-10 15:40:40 +02:00
Sami Kerola 41427f97d9
tests: add static keyword where needed [smatch scan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Sami Kerola 08cce2e1cc libmount: fix use of preprocessor identifier
libmount/src/context_mount.c:990:5: warning: undefined preprocessor
identifier 'USE_LIBMOUNT_SUPPORT_MTAB'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:07 +01:00
Karel Zak 7bb9ee99da libmount: cosmetic change to mnt_table_find_srcpath()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-28 14:47:02 +01:00
Petr Vorel 443be11396 libmount: return tab entry for default node
This is useful for lsblk.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2017-02-28 14:41:42 +01:00