summaryrefslogtreecommitdiff
path: root/src/basic/stat-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-08 17:19:27 +0100
committerSven Eden <yamakuzure@gmx.net>2017-07-17 17:58:35 +0200
commitb9a2add4c257e40e60e49eb4edaf7925ba569c78 (patch)
treeebd5d0cc8f8ecd034d8cf7e6bd1a1f528ce3cd53 /src/basic/stat-util.c
parentc7a64b3cac7ac3db89bbe0b9b1e826cd65e44b5d (diff)
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).
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r--src/basic/stat-util.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c
index 81c13ec59..2a6e89b75 100644
--- a/src/basic/stat-util.c
+++ b/src/basic/stat-util.c
@@ -150,22 +150,29 @@ int path_is_read_only_fs(const char *path) {
#if 0 /// UNNEEDED by elogind
int path_is_os_tree(const char *path) {
- char *p;
int r;
assert(path);
- /* We use /usr/lib/os-release as flag file if something is an OS */
- p = strjoina(path, "/usr/lib/os-release");
- r = access(p, F_OK);
- if (r >= 0)
- return 1;
+ /* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir
+ * always results in -ENOENT, and we can properly distuingish the case where the whole root doesn't exist from
+ * the case where just the os-release file is missing. */
+ if (laccess(path, F_OK) < 0)
+ return -errno;
- /* Also check for the old location in /etc, just in case. */
- p = strjoina(path, "/etc/os-release");
- r = access(p, F_OK);
+ /* We use /usr/lib/os-release as flag file if something is an OS */
+ r = chase_symlinks("/usr/lib/os-release", path, CHASE_PREFIX_ROOT, NULL);
+ if (r == -ENOENT) {
+
+ /* Also check for the old location in /etc, just in case. */
+ r = chase_symlinks("/etc/os-release", path, CHASE_PREFIX_ROOT, NULL);
+ if (r == -ENOENT)
+ return 0; /* We got nothing */
+ }
+ if (r < 0)
+ return r;
- return r >= 0;
+ return 1;
}
#endif // 0