summaryrefslogtreecommitdiff
path: root/src/basic/mount-util.c
Commit message (Collapse)AuthorAge
* mount-setup: add a comment that the character/block device nodes are ↵Lennart Poettering2018-08-24
| | | | | | | | | | "optional" (#8893) if we lack privs to create device nodes that's fine, and creating /run/systemd/inaccessible/chr or /run/systemd/inaccessible/blk won't work then. Document this in longer comments. Fixes: #4484
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | 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.
* fs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()Lennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | This rearranges chase_symlinks() a bit: if no special flags are specified it will now revert to behaviour before b12d25a8d631af00b200e7aa9dbba6ba4a4a59ff. However, if the new CHASE_TRAIL_SLASH flag is specified it will follow the behaviour introduced by that commit. I wasn't sure which one to make the beaviour that requires specification of a flag to enable. I opted to make the "append trailing slash" behaviour the one to enable by a flag, following the thinking that the function should primarily be used to generate a normalized path, and I am pretty sure a path without trailing slash is the more "normalized" one, as the trailing slash is not really a part of it, but merely a "decorator" that tells various system calls to generate ENOTDIR if the path doesn't refer to a path. Or to say this differently: if the slash was part of normalization then we really should add it in all cases when the final path is a directory, not just when the user originally specified it. Fixes: #8544 Replaces: #8545
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/basic (1/6)
* mount-util: call mount_option_mangle() in mount_verbose()Yu Watanabe2018-05-30
|
* mount-util: add mount_option_mangle()Yu Watanabe2018-05-30
| | | | This is used in the later commits.
* tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-05-30
| | | | | | path Let's make use of our new hash_ops!
* tree-wide: make use of new STRLEN() macro everywhere (#7639)Lennart Poettering2018-05-30
| | | | | | Let's employ coccinelle to do this for us. Follow-up for #7625.
* basic: turn off stdio locking for a couple of helper callsLennart Poettering2018-05-30
| | | | | | These helper calls are potentially called often, and allocate FILE* objects internally for a very short period of time, let's turn off locking for them too.
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* mount-util: fix error propagation in fd_fdinfo_mnt_id()Lennart Poettering2017-11-23
|
* udevadm,basic: replace nulstr_contains with STR_IN_SET (#6965)Zbigniew Jędrzejewski-Szmek2017-10-04
| | | | | | | | | | | | | | | | | STR_IN_SET is a newer approach which is easier to write and read, and which seems to result in space savings too: before: 4949848 build/src/shared/libelogind-shared-234.so 350704 build/systemctl 4967184 build/elogind 826216 build/udevadm after: 4949848 build/src/shared/libelogind-shared-234.so 350704 build/systemctl 4966888 build/elogind 826168 build/udevadm
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-12-08
|
* Apply updates from upstreamSven Eden2017-12-07
|
* mount-util: add fusectl to list of API VFSLennart Poettering2017-09-29
|
* dissect: split list of discard-supporting fs out into mount-util.cLennart Poettering2017-11-22
| | | | | | | Let's manage the list of file systems that do a specific thing at one place, following similar naming. No functional changes.
* dissect: automatically mark partitions read-only that have a read-only file ↵Lennart Poettering2017-11-22
| | | | | | | system Specifically, squashfs and iso9660 are always read-only, hence make sure we never even think about mounting them writable.
* elogind-mount: allow to specify an arbitrary string for arg_mount_what when ↵Yu Watanabe2017-09-25
| | | | | | vfs is used Fixes #6591.
* Prep v235: Add missing includes and dependencies.Sven Eden2017-08-14
|
* core: open /proc/self/mountinfo early to allow mounts over /proc (#5985)Timothée Ravier2017-07-25
| | | | | | | | | | | Enable masking the /proc folder using the 'InaccessiblePaths' unit option. This also slightly simplify mounts setup as the bind_remount_recursive function will only open /proc/self/mountinfo once. This is based on the suggestion at: https://lists.freedesktop.org/archives/elogind-devel/2017-April/038634.html
* Prep v233.2: Mask unneeded functions and definitions in src/basicSven Eden2017-07-18
|
* Prep v233: Add missing includes in src/basicSven Eden2017-07-17
|
* mount-util: accept that name_to_handle_at() might fail with EPERM (#5499)Lennart Poettering2017-07-17
| | | | | | | | | | | | | Container managers frequently block name_to_handle_at(), returning EACCES or EPERM when this is issued. Accept that, and simply fall back to to fdinfo-based checks. Note that we accept either EACCES or EPERM here, as container managers can choose the error code and aren't very good on agreeing on just one. (note that this is a non-issue with nspawn, as we permit name_to_handle_at() there, only block open_by_handle_at(), which should be sufficiently safe).
* util-lib: make verbose_mount() grok MS_MOVELennart Poettering2017-07-17
| | | | Let's print a proper message if we see MS_MOVE.
* Modify mount_propagation_flags_from_string to return a normal int codeZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | This means that callers can distiguish an error from flags==0, and don't have to special-case the empty string.
* fs-util: add flags parameter to chase_symlinks()Lennart Poettering2017-07-17
| | | | | | Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of chase_symlinks_prefix().
* core: hook up MountFlags= to the transient unit logicLennart Poettering2017-07-17
| | | | | This makes "elogind-run -p MountFlags=shared -t /bin/sh" work, by making MountFlags= to the list of properties that may be accessed transiently.
* tree-wide: stop using canonicalize_file_name(), use chase_symlinks() insteadLennart Poettering2017-07-17
| | | | | | | | Let's use chase_symlinks() everywhere, and stop using GNU canonicalize_file_name() everywhere. For most cases this should not change behaviour, however increase exposure of our function to get better tested. Most importantly in a few cases (most notably nspawn) it can take the correct root directory into account when chasing symlinks.
* tree-wide: drop NULL sentinel from strjoinZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | | | | | | | | | This makes strjoin and strjoina more similar and avoids the useless final argument. spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/elogind -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libelogind/sd-bus -I ./src/libelogind/sd-event -I ./src/libelogind/sd-login -I ./src/libelogind/sd-netlink -I ./src/libelogind/sd-network -I ./src/libelogind/sd-hwdb -I ./src/libelogind/sd-device -I ./src/libelogind/sd-id128 -I ./src/libelogind-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c) git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/' This might have missed a few cases (spatch has a really hard time dealing with _cleanup_ macros), but that's no big issue, they can always be fixed later.
* Prep v232.2: Mask more unneeded functionsSven Eden2017-07-07
|
* Recognise Lustre as a remote file system (#4530)Brian J. Murrell2017-07-05
| | | | Lustre is also a remote file system that wants the network to be up before it is mounted.
* basic: fallback to the fstat if we don't have access to the /proc/self/fdinfoEvgeny Vereshchagin2017-07-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://github.com/elogind/elogind/pull/4372#discussion_r83354107: I get `open("/proc/self/fdinfo/13", O_RDONLY|O_CLOEXEC) = -1 EACCES (Permission denied)` 327 mkdir("/proc", 0755 <unfinished ...> 327 <... mkdir resumed> ) = -1 EEXIST (File exists) 327 stat("/proc", <unfinished ...> 327 <... stat resumed> {st_dev=makedev(8, 1), st_ino=28585, st_mode=S_IFDIR|0755, st_nlink=2, st_uid=0, st_gid=0, st_blksize=1024, st_blocks=4, st_size=1024, st_atime=2016/10/14-02:55:32, st_mtime=2016/ 327 mount("proc", "/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL <unfinished ...> 327 <... mount resumed> ) = 0 327 lstat("/proc", <unfinished ...> 327 <... lstat resumed> {st_dev=makedev(0, 34), st_ino=1, st_mode=S_IFDIR|0555, st_nlink=75, st_uid=65534, st_gid=65534, st_blksize=1024, st_blocks=0, st_size=0, st_atime=2016/10/14-03:13:35.971031263, 327 lstat("/proc/sys", {st_dev=makedev(0, 34), st_ino=4026531855, st_mode=S_IFDIR|0555, st_nlink=1, st_uid=65534, st_gid=65534, st_blksize=1024, st_blocks=0, st_size=0, st_atime=2016/10/14-03:13:39.1630 327 openat(AT_FDCWD, "/proc", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_PATH) = 11</proc> 327 name_to_handle_at(11</proc>, "sys", {handle_bytes=128}, 0x7ffe3a238604, AT_SYMLINK_FOLLOW) = -1 EOPNOTSUPP (Operation not supported) 327 name_to_handle_at(11</proc>, "", {handle_bytes=128}, 0x7ffe3a238608, AT_EMPTY_PATH) = -1 EOPNOTSUPP (Operation not supported) 327 openat(11</proc>, "sys", O_RDONLY|O_CLOEXEC|O_PATH) = 13</proc/sys> 327 open("/proc/self/fdinfo/13", O_RDONLY|O_CLOEXEC) = -1 EACCES (Permission denied) 327 close(13</proc/sys> <unfinished ...> 327 <... close resumed> ) = 0 327 close(11</proc> <unfinished ...> 327 <... close resumed> ) = 0 -bash-4.3# ls -ld /proc/ dr-xr-xr-x 76 65534 65534 0 Oct 14 02:57 /proc/ -bash-4.3# ls -ld /proc/1 dr-xr-xr-x 9 root root 0 Oct 14 02:57 /proc/1 -bash-4.3# ls -ld /proc/1/fdinfo dr-x------ 2 65534 65534 0 Oct 14 03:00 /proc/1/fdinfo
* nspawn,mount-util: add [u]mount_verbose and use it in nspawnZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | | | | | | | | | | | | | | | | This makes it easier to debug failed nspawn invocations: Mounting sysfs on /var/lib/machines/fedora-rawhide/sys (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV "")... Mounting tmpfs on /var/lib/machines/fedora-rawhide/dev (MS_NOSUID|MS_STRICTATIME "mode=755,uid=1450901504,gid=1450901504")... Mounting tmpfs on /var/lib/machines/fedora-rawhide/dev/shm (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=1777,uid=1450901504,gid=1450901504")... Mounting tmpfs on /var/lib/machines/fedora-rawhide/run (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=755,uid=1450901504,gid=1450901504")... Bind-mounting /sys/fs/selinux on /var/lib/machines/fedora-rawhide/sys/fs/selinux (MS_BIND "")... Remounting /var/lib/machines/fedora-rawhide/sys/fs/selinux (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")... Mounting proc on /proc (MS_NOSUID|MS_NOEXEC|MS_NODEV "")... Bind-mounting /proc/sys on /proc/sys (MS_BIND "")... Remounting /proc/sys (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")... Bind-mounting /proc/sysrq-trigger on /proc/sysrq-trigger (MS_BIND "")... Remounting /proc/sysrq-trigger (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")... Mounting tmpfs on /tmp (MS_STRICTATIME "mode=1777,uid=0,gid=0")... Mounting tmpfs on /sys/fs/cgroup (MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME "mode=755,uid=0,gid=0")... Mounting cgroup on /sys/fs/cgroup/elogind (MS_NOSUID|MS_NOEXEC|MS_NODEV "none,name=elogind,xattr")... Failed to mount cgroup on /sys/fs/cgroup/elogind (MS_NOSUID|MS_NOEXEC|MS_NODEV "none,name=elogind,xattr"): No such file or directory
* namespace: rework how ReadWritePaths= is appliedLennart Poettering2017-07-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, if ReadWritePaths= was nested inside a ReadOnlyPaths= specification, then we'd first recursively apply the ReadOnlyPaths= paths, and make everything below read-only, only in order to then flip the read-only bit again for the subdirs listed in ReadWritePaths= below it. This is not only ugly (as for the dirs in question we first turn on the RO bit, only to turn it off again immediately after), but also problematic in containers, where a container manager might have marked a set of dirs read-only and this code will undo this is ReadWritePaths= is set for any. With this patch behaviour in this regard is altered: ReadOnlyPaths= will not be applied to the children listed in ReadWritePaths= in the first place, so that we do not need to turn off the RO bit for those after all. This means that ReadWritePaths=/ReadOnlyPaths= may only be used to turn on the RO bit, but never to turn it off again. Or to say this differently: if some dirs are marked read-only via some external tool, then ReadWritePaths= will not undo it. This is not only the safer option, but also more in-line with what the man page currently claims: "Entries (files or directories) listed in ReadWritePaths= are accessible from within the namespace with the same access rights as from outside." To implement this change bind_remount_recursive() gained a new "blacklist" string list parameter, which when passed may contain subdirs that shall be excluded from the read-only mounting. A number of functions are updated to add more debug logging to make this more digestable.
* add a new tool for creating transient mount and automount unitsLennart Poettering2017-07-05
| | | | | | | | | | | | | | | | | | | | | | | This adds "elogind-mount" which is for transient mount and automount units what "elogind-run" is for transient service, scope and timer units. The tool allows establishing mounts and automounts during runtime. It is very similar to the usual /bin/mount commands, but can pull in additional dependenices on access (for example, it pulls in fsck automatically), an take benefit of the automount logic. This tool is particularly useful for mount removable file systems (such as USB sticks), as the automount logic (together with automatic unmount-on-idle), as well as automatic fsck on first access ensure that the removable file system has a high chance to remain in a fully clean state even when it is unplugged abruptly, and returns to a clean state on the next re-plug. This is a follow-up for #2471, as it adds a simple client-side for the transient automount logic added in that PR. In later work it might make sense to invoke this tool automatically from udev rules in order to implement a simpler and safer version of removable media management á la udisks.
* Prep v231: Apply missing fixes from upstream (1/6) src/basicSven Eden2017-06-16
|
* namespace: don't fail on masked mounts (#3794)Alban Crequy2017-06-16
| | | | | | | | Before this patch, a service file with ReadWriteDirectories=/file... could fail if the file exists but is not a mountpoint, despite being listed in /proc/self/mountinfo. It could happen with masked mounts. Fixes https://github.com/elogind/elogind/issues/3793
* basic/mount-util: recognize ocfs2 as network fs (#3713)Valentin Vidić2017-06-16
|
* treewide: fix typos and remove accidental repetition of wordsTorstein Husebø2017-06-16
|
* basic/mount-util: recognize pvfs2 as network fs (#3140)Zbigniew Jędrzejewski-Szmek2017-06-16
| | | | Added to kernel 4.6.
* tree-wide: no need to pass excess flags to open()/openat() if O_PATH is passedAlexander Kuleshov2017-06-16
| | | | | | | | | | As described in the documentation: When O_PATH is specified in flags, flag bits other than O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored. So, we can remove unnecessary flags in a case when O_PATH is passed to the open() or openat().
* Prep v229: Add missing fixes from upstream [1/6] src/basicSven Eden2017-05-17
|
* Prep v228: Condense elogind source masks (2/5)Sven Eden2017-04-26
|
* Prep v228: Add remaining updates from upstream (1/3)Sven Eden2017-04-26
The util.[hc] files have been stripped of a lot of functions, that got sorted into various new files representing the type of utility. This commit adds the missing files.