summaryrefslogtreecommitdiff
path: root/src/test/test-mount-util.c
Commit message (Collapse)AuthorAgeFilesLines
* mount-util: simplify mount_switch_root() a bitLennart Poettering2023-05-031-0/+43
| | | | | | | | | | | | | There's no need to fchdir() out of the rootfs and back into it around the umount2(), hence don't. This brings the logic closer to what the pivot_root() man page suggests. While we are at it, always operate based on fds, once we opened the original dir, and pass the path string along only for generating messages (i.e. as "decoration"). Add tests for both code paths: the pivot_root() one and the MS_MOUNT.
* mount-util: introduce remount_sysfs()Yu Watanabe2023-02-231-1/+146
| | | | | | | | | | This is useful when creating a new network namespace. Unlike procfs, we need to remount sysfs, otherwise properties of the network interfaces in the main network namespace are still accessible through the old sysfs, e.g. /sys/class/net/eth0. All sub-mounts previously mounted on the sysfs are moved onto the new sysfs mount. The function will be used in later commits.
* tree-wide: use mode=0nnn for mount optionZbigniew Jędrzejewski-Szmek2022-12-141-12/+12
| | | | | | This is an octal number. We used the 0 prefix in some places inconsistently. The kernel always interprets in base-8, so this has no effect, but I think it's nicer to use the 0 to remind the reader that this is not a decimal number.
* shared: add new safe_fork flag FORK_PRIVATE_TMPZbigniew Jędrzejewski-Szmek2022-12-141-0/+1
| | | | | | | | | | | | | If the flag is set, we mount /tmp/ in a way that is suitable for generators and other quick jobs. Unfortunately I had to move some code from shared/mount-util.c to basic/mountpoint-util.c. The functions that are moved are very thin wrappers around mount(2), so this doesn't actually change much in the code split between libbasic and libshared. Implications for the host would be weird if a private mount namespace is not used, so assert on FORK_NEW_MOUNTNS when the flag is used.
* strv: declare iterator of FOREACH_STRING() in the loopZbigniew Jędrzejewski-Szmek2022-03-231-1/+0
| | | | | | | | | | | Same idea as 03677889f0ef42cdc534bf3b31265a054b20a354. No functional change intended. The type of the iterator is generally changed to be 'const char*' instead of 'char*'. Despite the type commonly used, modifying the string was not allowed. I adjusted the naming of some short variables for clarity and reduced the scope of some variable declarations in code that was being touched anyway.
* test: Use TEST macroJan Janssen2021-11-251-26/+6
| | | | | | | | | This converts to TEST macro where it is trivial. Some additional notable changes: - simplify HAVE_LIBIDN #ifdef in test-dns-domain.c - use saved_argc/saved_argv in test-copy.c, test-path-util.c, test-tmpfiles.c and test-unit-file.c
* mount-util: port over bind_remount_recursive_with_mountinfo() to mount_setattr()Lennart Poettering2021-10-251-1/+1
|
* mount-util: use modern mount_setattr() syscall for ↵Lennart Poettering2021-10-251-0/+1
| | | | | | | bind_remount_one_with_mountinfo() New kernels have a nice syscall for changing bind mount flags. Let's use it. This makes the complex libmount based iteration logic unnecessary.
* basic,shared: move make_mount_point_inode_*() to shared/Zbigniew Jędrzejewski-Szmek2021-06-231-0/+49
| | | | Those pull in selinux for labelling, and we should avoid selinux in basic/.
* test-mount-util: add output test for mount_flags_to_string()Zbigniew Jędrzejewski-Szmek2021-06-221-0/+50
|
* test-mount-util: add usual print headersZbigniew Jędrzejewski-Szmek2021-06-221-0/+6
|
* mount-util: use EXTRACT_KEEP_QUOTE to handle mount optionsYu Watanabe2021-06-211-0/+5
| | | | Otherwise, the quotes which wrap SELinux options are dropped.
* test: tweak privilege tests for two more testsLennart Poettering2021-06-031-4/+5
| | | | | | | These tests require properly privileged root users, hence skip things when we don't have CAP_SYS_ADMIN. Fixes: #19746
* test: add explicit test for bind_remount_one_with_mountinfo()Lennart Poettering2021-03-261-0/+32
|
* test: add test for bind_remount_recursive()Lennart Poettering2021-03-261-0/+65
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Split out part of mount-util.c into mountpoint-util.cZbigniew Jędrzejewski-Szmek2018-11-291-244/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The idea is that anything which is related to actually manipulating mounts is in mount-util.c, but functions for mountpoint introspection are moved to the new file. Anything which requires libmount must be in mount-util.c. This was supposed to be a preparation for further changes, with no functional difference, but it results in a significant change in linkage: $ ldd build/libnss_*.so.2 (before) build/libnss_myhostname.so.2: linux-vdso.so.1 (0x00007fff77bf5000) librt.so.1 => /lib64/librt.so.1 (0x00007f4bbb7b2000) libmount.so.1 => /lib64/libmount.so.1 (0x00007f4bbb755000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4bbb734000) libc.so.6 => /lib64/libc.so.6 (0x00007f4bbb56e000) /lib64/ld-linux-x86-64.so.2 (0x00007f4bbb8c1000) libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f4bbb51b000) libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f4bbb512000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f4bbb4e3000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f4bbb45e000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f4bbb458000) build/libnss_mymachines.so.2: linux-vdso.so.1 (0x00007ffc19cc0000) librt.so.1 => /lib64/librt.so.1 (0x00007fdecb74b000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fdecb744000) libmount.so.1 => /lib64/libmount.so.1 (0x00007fdecb6e7000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdecb6c6000) libc.so.6 => /lib64/libc.so.6 (0x00007fdecb500000) /lib64/ld-linux-x86-64.so.2 (0x00007fdecb8a9000) libblkid.so.1 => /lib64/libblkid.so.1 (0x00007fdecb4ad000) libuuid.so.1 => /lib64/libuuid.so.1 (0x00007fdecb4a2000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fdecb475000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fdecb3f0000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fdecb3ea000) build/libnss_resolve.so.2: linux-vdso.so.1 (0x00007ffe8ef8e000) librt.so.1 => /lib64/librt.so.1 (0x00007fcf314bd000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fcf314b6000) libmount.so.1 => /lib64/libmount.so.1 (0x00007fcf31459000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fcf31438000) libc.so.6 => /lib64/libc.so.6 (0x00007fcf31272000) /lib64/ld-linux-x86-64.so.2 (0x00007fcf31615000) libblkid.so.1 => /lib64/libblkid.so.1 (0x00007fcf3121f000) libuuid.so.1 => /lib64/libuuid.so.1 (0x00007fcf31214000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fcf311e7000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007fcf31162000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fcf3115c000) build/libnss_systemd.so.2: linux-vdso.so.1 (0x00007ffda6d17000) librt.so.1 => /lib64/librt.so.1 (0x00007f610b83c000) libcap.so.2 => /lib64/libcap.so.2 (0x00007f610b835000) libmount.so.1 => /lib64/libmount.so.1 (0x00007f610b7d8000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f610b7b7000) libc.so.6 => /lib64/libc.so.6 (0x00007f610b5f1000) /lib64/ld-linux-x86-64.so.2 (0x00007f610b995000) libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f610b59e000) libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f610b593000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f610b566000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f610b4e1000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f610b4db000) (after) build/libnss_myhostname.so.2: linux-vdso.so.1 (0x00007fff0b5e2000) librt.so.1 => /lib64/librt.so.1 (0x00007fde0c328000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fde0c307000) libc.so.6 => /lib64/libc.so.6 (0x00007fde0c141000) /lib64/ld-linux-x86-64.so.2 (0x00007fde0c435000) build/libnss_mymachines.so.2: linux-vdso.so.1 (0x00007ffdc30a7000) librt.so.1 => /lib64/librt.so.1 (0x00007f06ecabb000) libcap.so.2 => /lib64/libcap.so.2 (0x00007f06ecab4000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f06eca93000) libc.so.6 => /lib64/libc.so.6 (0x00007f06ec8cd000) /lib64/ld-linux-x86-64.so.2 (0x00007f06ecc15000) build/libnss_resolve.so.2: linux-vdso.so.1 (0x00007ffe95747000) librt.so.1 => /lib64/librt.so.1 (0x00007fa56a80f000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fa56a808000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa56a7e7000) libc.so.6 => /lib64/libc.so.6 (0x00007fa56a621000) /lib64/ld-linux-x86-64.so.2 (0x00007fa56a964000) build/libnss_systemd.so.2: linux-vdso.so.1 (0x00007ffe67b51000) librt.so.1 => /lib64/librt.so.1 (0x00007ffb32113000) libcap.so.2 => /lib64/libcap.so.2 (0x00007ffb3210c000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ffb320eb000) libc.so.6 => /lib64/libc.so.6 (0x00007ffb31f25000) /lib64/ld-linux-x86-64.so.2 (0x00007ffb3226a000) I don't quite understand what is going on here, but let's not be too picky.
* tests: use a helper function to parse environment and open loggingZbigniew Jędrzejewski-Szmek2018-09-141-1/+2
| | | | | The advantages are that we save a few lines, and that we can override logging using environment variables in more test executables.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tests: skip the rest of test_mnt_id after getting any errorEvegeny Vereshchagin2018-03-091-6/+2
| | | | | | | | | This mainly gets around a kernel bug making it possible to have non-existent paths in /proc/self/mountinfo, but it should also prevent flaky failures that can happen if something changes immediately after or during reading /proc/self/mountinfo. Closes https://github.com/systemd/systemd/issues/8286.
* test: add tests for mount_option_mangle()Yu Watanabe2018-02-211-0/+55
|
* util-lib: use trailing slash in chase_symlinks, fd_is_mount_point, ↵Zbigniew Jędrzejewski-Szmek2017-11-301-1/+23
| | | | | | | | | | | | | | | | | | | | | | | path_is_mount_point The kernel will reply with -ENOTDIR when we try to access a non-directory under a name which ends with a slash. But our functions would strip the trailing slash under various circumstances. Keep the trailing slash, so that path_is_mount_point("/path/to/file/") return -ENOTDIR when /path/to/file/ is a file. Tests are added for this change in behaviour. Also, when called with a trailing slash, path_is_mount_point() would get "" from basename(), and call name_to_handle_at(3, "", ...), and always return -ENOENT. Now it'll return -ENOTDIR if the mount point is a file, and true if it is a directory and a mount point. v2: - use strip_trailing_chars() v3: - instead of stripping trailing chars(), do the opposite — preserve them.
* test-mount-util: move test_path_is_mount_point hereZbigniew Jędrzejewski-Szmek2017-11-301-0/+140
| | | | | | | path-util.c and mount-util.c are intertwined, but path_is_mount_point() is defined in mount-util.c. No functional difference.
* Use hashmap_free_free where appropriateZbigniew Jędrzejewski-Szmek2017-11-281-4/+1
|
* test: fix test-mount-util when handling duplicate mounts on the same locationLennart Poettering2017-11-231-21/+18
| | | | | | | | | | | | | | The test was written so far under the assumption that if two mounts are placed onto the same location the "upper" mount is listed later in /proc/self/mountinfo. This appears not to be guaranteed however, as running the tests in a normal nspawn shows. This patch fixes that: it reverses the hashmap of mounts we build: instead of keying by path, we key by mnt_id, and if we notice that path_get_mnt_id() doesn't match what a line in /proc/self/mountinfo says, we use the returned ID to check if maybe another line agrees. Fixes: #7431
* mount-util: add new path_get_mnt_id() call that queries the mnt ID of a pathLennart Poettering2017-11-211-0/+66
| | | | | | | | | | This is a simple wrapper around name_to_handle_at_loop() and fd_fdinfo_mnt_id() to query the mnt ID of a path. It uses name_to_handle_at() where it can, and falls back to to fd_fdinfo_mnt_id() where that doesn't work. This is a best-effort thing of course, since neither name_to_handle_at() nor the fdinfo logic work on all kernels.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* tree-wide: do not work in assert() (#7271)Yu Watanabe2017-11-071-1/+1
| | | Fixes #7270.
* Modify mount_propagation_flags_from_string to return a normal int codeZbigniew Jędrzejewski-Szmek2016-12-171-10/+22
| | | | | This means that callers can distiguish an error from flags==0, and don't have to special-case the empty string.
* core: hook up MountFlags= to the transient unit logicLennart Poettering2016-12-131-0/+45
This makes "systemd-run -p MountFlags=shared -t /bin/sh" work, by making MountFlags= to the list of properties that may be accessed transiently.