Commit Graph

44 Commits

Author SHA1 Message Date
Lennart Poettering 15308e5083 stat-util: don't try to open path on path_is_temporary_fs()
I mean, the old code at least used O_PATH, but still, we shouldn't
allocate/close an fd if we don't have to.
2021-01-06 23:26:08 +00:00
Zbigniew Jędrzejewski-Szmek b8aac5014c
Merge pull request #17431 from msekletar/udev-link-update-race
udev: make algorithm that selects highest priority devlink less susceptible to race conditions
2020-11-10 09:41:57 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Michal Sekletár a59b0a9f76 basic/stat-util: make mtime check stricter and use entire timestamp
Note that st_mtime member of struct stat is defined as follows,

 #define st_mtime st_mtim.tv_sec

Hence we omitted checking nanosecond part of the timestamp (struct
timespec) and possibly would miss modifications that happened within the
same second.
2020-11-06 12:28:40 +01:00
Lennart Poettering ca194a2a0c stat-util: provide single fallback implementation of statx()
This simplifies things quite a bit, and is reusable wherever we want to
use statx() later on. Not sure why I didn't do it like this right from
the beginning...
2020-09-03 15:02:34 +02:00
Lennart Poettering 29da419305 stat-util: trivial empty_or_null() tweaks
To small tweaks: /dev/null is definitely a char device. And if we have
the path, to a string base comparison first.
2020-05-29 21:23:43 +02:00
Lennart Poettering fee5c52ac2 stat-util: add stat_inode_unmodified() helper that checks if an inode was modified 2020-05-13 16:57:44 +02:00
Lennart Poettering 883fff25f4 stat-util: add simpler helper for checking if /proc/ is mounted 2020-04-23 14:51:08 +02:00
Lennart Poettering 6d965610bd stat-util: no need to open a file to check fs type 2020-04-23 14:50:53 +02:00
Vito Caputo 9f81a592c1 *: convert amenable fdopendir() calls to take_fdopendir()
Some fdopendir() calls remain where safe_close() is manually
performed, those could be simplified as well by converting to
use the _cleanup_close_ machinery, but makes things less trivial
to review so left for a future cleanup.
2020-03-31 06:48:03 -07:00
Yu Watanabe 0fb81b8abe tree-wide: drop magic.h when missing_magic.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe e30e8b5073 tree-wide: drop stat.h or statfs.h when stat-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 996f7e1cd0 tree-wide: drop dirent.h when dirent-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Lennart Poettering 0cb8e3d118 util: split out namespace related stuff into a new namespace-util.[ch] pair
Just some minor reorganiztion.
2019-03-13 12:16:38 +01:00
Zbigniew Jędrzejewski-Szmek 477fd8e886
Merge pull request #11345 from kirbyfan64/tmpfiles-c-empty
tmpfiles: Make C still copy if the destination directory is empty
2019-01-15 16:54:19 +01:00
Ryan Gonzalez d7c1a15edf stat-util: Add dir_is_empty_at 2019-01-08 10:23:17 -06:00
Lennart Poettering aebfc8f090 stat-util: remove spurious newline 2019-01-07 17:50:39 +01:00
Lennart Poettering 846b3bd61e stat-util: add new APIs device_path_make_{major_minor|canonical}() and device_path_parse_major_minor()
device_path_make_{major_minor|canonical)  generate device node paths
given a mode_t and a dev_t. We have similar code all over the place,
let's unify this in one place. The former will generate a "/dev/char/"
or "/dev/block" path, and never go to disk. The latter then goes to disk
and resolves that path to the actual path of the device node.

device_path_parse_major_minor() reverses device_path_make_major_minor(),
also withozut going to disk.

We have similar code doing something like this at various places, let's
unify this in a single set of functions. This also allows us to teach
them special tricks, for example handling of the
/run/systemd/inaccessible/{blk|chr} device nodes, which we use for
masking device nodes, and which do not exist in /dev/char/* and
/dev/block/*
2018-11-29 20:21:39 +01:00
Lennart Poettering 844416b64c stat-util: add fd_verify_directory(), similar to fd_verify_regular() 2018-11-26 18:09:01 +01:00
Lennart Poettering 6619ad889d nspawn: beef up netns checking a bit, for compat with old kernels
Fixes: #10544
2018-10-31 21:42:45 +03:00
Yu Watanabe 898ce5e8b8 util: do not assign return value if it is not used (#10552) 2018-10-28 18:41:35 -07:00
Franck Bui a12e4ade1b basic/stat-util: introduce is_dir_fd() 2018-07-30 15:54:03 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
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.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
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.
2018-06-14 10:20:20 +02:00
Lennart Poettering d58ad743f9 os-util: add helpers for finding /etc/os-release
Place this new helpers in a new source file os-util.[ch], and move the
existing and related call path_is_os_tree() to it as well.
2018-05-24 17:01:57 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
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.
2018-04-06 18:58:55 +02:00
Lennart Poettering 29f74559d4 stat-util: fix fd_is_network_ns()
This was broken in 77f9fa3b8e. My fault.

Fixes: #8543
2018-03-23 15:29:35 +01:00
Lennart Poettering 3cc4411403 stat-util: unify code that checks whether something is a regular file
Let's add a common implementation for regular file checks, that are
careful to return the right error code (EISDIR/EISLNK/EBADFD) when we
are encountering a wrong file node.
2018-02-20 15:39:31 +01:00
Lennart Poettering 77f9fa3b8e journal: move code that checks for network fs to stat-util.[ch]
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.
2018-02-12 11:07:55 +01:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Dongsu Park d7bea6b629 nspawn: introduce an option for specifying network namespace path
Add a new option `--network-namespace-path` to systemd-nspawn to allow
users to specify an arbitrary network namespace, e.g. `/run/netns/foo`.
Then systemd-nspawn will open the netns file, pass the fd to
outer_child, and enter the namespace represented by the fd before
running inner_child.

```
$ sudo ip netns add foo
$ mount | grep /run/netns/foo
nsfs on /run/netns/foo type nsfs (rw)
...
$ sudo systemd-nspawn -D /srv/fc27 --network-namespace-path=/run/netns/foo \
  /bin/readlink -f /proc/self/ns/net
/proc/1/ns/net:[4026532009]
```

Note that the option `--network-namespace-path=` cannot be used together
with other network-related options such as `--private-network` so that
the options do not conflict with each other.

Fixes https://github.com/systemd/systemd/issues/7361
2017-12-13 10:21:06 +00:00
Zbigniew Jędrzejewski-Szmek 40fd52f28d util-lib: rename path_check_fstype to path_is_fs_type 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek a66fee2e97 util-lib: rename fd_check_fstype to fd_is_fs_type
Let's use "is" and "fs_type" for consistency with "is_fs_type".
"check" is also more ambiguous than "is".
2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek e3f791a2b3 basic/path-util: allow flags for path_equal_or_files_same
No functional change, just a new parameters and the tests that
AT_SYMLINK_NOFOLLOW works as expected.
2017-06-17 12:37:16 -04:00
Lennart Poettering 436e916eae util-lib: rework path_check_fstype() and path_is_temporary_fs() to use O_PATH
Also, add tests to make sure this actually works as intended.
2016-12-21 19:09:32 +01:00
Lennart Poettering ffeb828596 util-lib: add new path_is_temporary_fs() API
As simple wrapper around fd_is_temporary_fs().
2016-12-20 20:00:09 +01:00
Lennart Poettering 08cea7dfc0 util-lib: make sure fd_check_fstype() opens files with O_CLOEXEC
Also, O_NOCTTY is a safer bet, let's add that too.
2016-12-20 20:00:09 +01:00
Lennart Poettering 7dcdb24e19 util-lib: beef path_is_os_tree() up a bit
Let's use chase_symlinks() when looking for /etc/os-release and
/usr/lib/os-release as these files might be symlinks (and actually are IRL on
some distros).
2016-12-20 20:00:08 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Lennart Poettering 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +01:00