Commit Graph

629 Commits

Author SHA1 Message Date
Karel Zak 2c37ca7c4b libmount: cleanup licenses sections in the files
* add SPDX-License-Identifier (see https://spdx.org/licenses/)
* add "This file part of libmount from util-linux project."
* use proper text for LGPL-2.1-or-later
* use the same texts everywhere

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 15:43:53 +02:00
Karel Zak 4189907e6c docs: use SPDX license names
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/

Note, this commit does not change any license or so...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 14:47:21 +02:00
Karel Zak 51d5109782 libmount: report context paths on debug
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-14 21:03:42 +02:00
Karel Zak 9c566fce79 libmount: (utils) fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:58:57 +02:00
Karel Zak b00dd55ac8 libmount: fix compiler warning [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:33:13 +02:00
Karel Zak 78c66fc61d lib/mangle: const quialifier cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:31:42 +02:00
Karel Zak ea927bde6b libmount: cleanup const in umount code
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 14:15:42 +02:00
Karel Zak a679b0823f libmount: add missing const
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:51:52 +02:00
Karel Zak 0d1e744c20 libmount: use const char in swaps parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:49:08 +02:00
Karel Zak 4e4c9629e6 libmount: use const char in mountinfo parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:48:09 +02:00
Karel Zak 4ccc64c4ca libmount: use const char in fstab parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:44:53 +02:00
Karel Zak fae8328928 libmount: add since tag for new functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-19 11:38:48 +02:00
Karel Zak 4f9d999a97 build-sys: add -Wno-cast-function-type for python
libmount/python/pylibmount.c:158:19: warning: cast between incompatible function types
   from ‘PyObject * (*)(PyObject *)’ {aka ‘struct _object * (*)(struct _object *)’}
     to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’}
   [-Wcast-function-type]

This is generic problem in all Python C code and gcc v8. The another
possible (and probably more correct) way is to add unused argument to
all API functions. Unfortunately, this solution is pretty invasive. The
question is if gcc is not too paranoid in this case.

For more details see https://bugs.python.org/issue33012. It seems
Python guys also prefer CFLAGS modification for now.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-18 10:23:51 +02:00
Frank Schaefer 8a12ab5775 * break up large strings for PySys_WriteStdout() 2018-07-10 20:21:02 -05:00
Alban Crequy 18a52a5094 libmount: (mountinfo) parse empty strings in source
The source of a mount in /proc/self/mountinfo can unfortunately be an
empty string. Before this patch, 'mount' and 'mountpoint' fail as
following:

  $ sudo mount -t tmpfs "" /tmp/bb
  $ mount
  mount: /proc/self/mountinfo: parse error at line 64 -- ignored
  $ mountpoint /tmp/bb
  /tmp/bb is not a mountpoint

This patch fixes the parsing. It is unfortunately more complex because
sscanf() does not handle fields with empty strings easily.

Other projects have their own parser for mountinfo and have similar
issues. I know of runc and runtime-tools (I'll send a patch for those
two) but there are probably others.

Signed-off-by: Alban Crequy <alban@kinvolk.io>
2018-07-10 13:48:38 +02:00
Vaclav Dolezal cddd2eaa27 libmount: switch namespace when appropriate
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 16:12:55 +02:00
Vaclav Dolezal 65ca7b5a9b libmount: support for namespaces for helpers
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 16:08:44 +02:00
Karel Zak de7ccabdfd libmount: make errno usable after mnt_context_set_target_ns()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-11 16:06:17 +02:00
Vaclav Dolezal 8342e5840d libmount: added error MNT_ERR_NAMESPACE
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 15:51:17 +02:00
Vaclav Dolezal 5cbf01b75d libmount: note namespaces in mnt_reset_context() docs
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 15:50:29 +02:00
Vaclav Dolezal 4917d842ea libmount: add support for switching namespaces
[kzak@redhat.com: - cosmetic changes, add some comments]

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-11 15:49:48 +02:00
Karel Zak 6691d53797 mount: keep MS_MOVE as flag
The previous commit 4ebea84bb1 replaced
all operations by strings, but it does not work for MS_MOVE as this
operation is not supported in fstab by libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 14:07:53 +02:00
Karel Zak 8d6de22499 libmount: don't use MS_MGC_VAL magic in mount(2) syscall
Specifying MS_MGC_VAL was required in kernel versions prior to 2.4,
but since Linux 2.4 is no longer required and is ignored if specified

The minimal kernel requirement for util-linux is Linux v2.6.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 12:29:14 +02:00
Karel Zak 816773b475 libmount: improve MS_REC usage
libmount allows to split one library (mount(8)) call to multiple mount(2)
syscalls, for example

   --rbind --make-rslave

in this case we have to be careful with MS_REC because the flag is
applied to multiple operations.

 # strace -e mount mount --rbind --make-rslave /mnt/A /mnt/B

Old version:

 mount("/mnt/A", "/mnt/B", 0x13ecac0, MS_MGC_VAL|MS_BIND, NULL) = 0
 mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0

Fixed version:

 mount("/mnt/A", "/mnt/B", 0x1f22ac0, MS_MGC_VAL|MS_BIND|MS_REC, NULL) = 0
 mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1584443
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 12:16:19 +02:00
Karel Zak c0bdff9997 libmount: include sys/mount.h on Linux only
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=891812
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-29 10:06:00 +02:00
Karel Zak e82b77e969 libmount: accept another flags on MS_REMOUNT|MS_BIND
The current libmount MS_REMOUNT|MS_BIND support is restricted to
MS_RDONLY (read-only bind mount). This is too restrictive as Linux
kernel supports bind-remount for arbitrary VFS flags.

After this update you can use

 # mount /dev/sdc1 /mnt/A
 # mount --bind -onosuid,noexec /mnt/A /mnt/B

 # findmnt /dev/sdc1 -oTARGET,SOURCE,FS-OPTIONS,VFS-OPTIONS
 TARGET SOURCE    FS-OPTIONS                 VFS-OPTIONS
 /mnt/A /dev/sdc1 rw,stripe=512,data=ordered rw,relatime
 /mnt/B /dev/sdc1 rw,stripe=512,data=ordered rw,nosuid,noexec,relatime

The "mount --bind" is composed from two syscalls of course (1st is
bind, 2nd is bind,remount,nosuid,noexec).

Addresses: https://github.com/karelzak/util-linux/issues/637
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-28 16:15:30 +02:00
Karel Zak af8ed53ee1 libmount: fix compiler warning [-Wunused-parameter]
Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-03 10:35:42 +02:00
Karel Zak f4375df0fd libmount: improve docs about mnt_context_mount() return codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-26 11:04:07 +02:00
NeilBrown 7966cbba53 libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
When you bind-mount a subdirectory of a local filesystem, the
path to that subdirectory appears as the fourth field in mountinfo.

For nfs mounts, the fourth field is always "/", and the subdirectory
part is appended to the "special" (aka "device") field.  This is
consistent with historical NFS usage which always includes a path in
the fs_spec field.

libmount needs to know about this when "mount -a" checks to see if
a filesystem is already mounted.

Without this fix, fstab lines like:

 server::/path /dir nfs defaults 0 0
 /dir/subdir /mnt/test none bind 0 0

result in a new mount at /mnt/test every time "mount -a" is run.

[kzak@redhat.com: - use strappend() rather than asprintf()]

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-18 10:17:26 +02:00
Richard Fuchs f958101d2e bugfix: fix possible segfault during umount -a
mnt_context_get_mtab() doesn't set its return **tb argument on error,
and so in mnt_context_next_umount() mtab will remain uninitialized on
error, later resulting in cxt->mtab containing garbage, possibly
resulting in segfault on exit.
2018-04-17 09:52:37 -04:00
Karel Zak 061d1a5109 libmount: include sys/mount.h only if necessary
Addresses: https://github.com/systemd/systemd/issues/8507
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-22 14:05:17 +01:00
Karel Zak 1b692a26f7 libmount: (docs) update year
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 18:56:06 +01:00
Karel Zak 83212eb3df libmount: fix example in docs
Addresses: https://github.com/karelzak/util-linux/issues/599
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 13:31:19 +01:00
Karel Zak b25f3c15c2 libmount: deallocate on /proc/swaps parse error
Addresses: https://github.com/karelzak/util-linux/issues/596
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 12:52:16 +01:00
Karel Zak 4c9e4ce83c libmount: make sure we deallocate on parse error
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 12:20:05 +01:00
Karel Zak b1813c59c0 libmount: make libmount.h more robust
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.

Addresses: https://github.com/systemd/systemd/pull/8452
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 10:59:56 +01:00
Karel Zak 76de2157cf libmount: fix fs pattern usage in mount --all
The command "mount -a -t <pattern>" uses the -t as pattern to filter
fstab entries. And "mount -t <type>" is used to specify FS type.

Unfortunately libmount does not care about this difference when it
calls standard mount functionality. The original pattern is still in
the library control struct and mnt_do_mount() tries to use it as FS
type.

This patch is just bugfix. Maybe the long term solution would be to
differentiate between the pattern and type in the library API. Now the
library follows mount(8) command line and it's little bit messy.

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-06 14:44:23 +01:00
Karel Zak ebb079266d libmount: add missing macro to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 11:43:21 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
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