summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-08-18 23:09:29 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-08-18 23:09:29 -0400
commit986a34a6834795f1a2d25bcffbe67debf9bbd6b2 (patch)
tree65ca72c212db3dda331814713f52fc45a84728f7 /src/core
parent6e32c03ed87e5dfd3857013e909e48b5e61564c1 (diff)
core/dynamic-users: warn when creation of symlinks for dynamic users fails
Also return the first error, since it's most likely to be interesting. If unlink fails, symlink will usually return EEXIST.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/dynamic-user.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c
index 185d0e5f00..53c1699b92 100644
--- a/src/core/dynamic-user.c
+++ b/src/core/dynamic-user.c
@@ -154,7 +154,7 @@ static int make_uid_symlinks(uid_t uid, const char *name, bool b) {
char path1[strlen("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1];
const char *path2;
- int r = 0;
+ int r = 0, k;
/* Add direct additional symlinks for direct lookups of dynamic UIDs and their names by userspace code. The
* only reason we have this is because dbus-daemon cannot use D-Bus for resolving users and groups (since it
@@ -164,23 +164,26 @@ static int make_uid_symlinks(uid_t uid, const char *name, bool b) {
* on them and as those may be taken by any user with read access we can't make them world-readable. */
xsprintf(path1, "/run/systemd/dynamic-uid/direct:" UID_FMT, uid);
- if (unlink(path1) < 0) {
- if (errno != ENOENT)
- r = -errno;
- }
- if (b) {
- if (symlink(name, path1) < 0)
- r = -errno;
+ if (unlink(path1) < 0 && errno != ENOENT)
+ r = -errno;
+
+ if (b && symlink(name, path1) < 0) {
+ k = log_warning_errno(errno, "Failed to symlink \"%s\": %m", path1);
+ if (r == 0)
+ r = k;
}
path2 = strjoina("/run/systemd/dynamic-uid/direct:", name);
- if (unlink(path2) < 0) {
- if (errno != ENOENT)
- r = -errno;
+ if (unlink(path2) < 0 && errno != ENOENT) {
+ k = -errno;
+ if (r == 0)
+ r = k;
}
- if (b) {
- if (symlink(path1 + strlen("/run/systemd/dynamic-uid/direct:"), path2) < 0)
- r = -errno;
+
+ if (b && symlink(path1 + strlen("/run/systemd/dynamic-uid/direct:"), path2) < 0) {
+ k = log_warning_errno(errno, "Failed to symlink \"%s\": %m", path2);
+ if (r == 0)
+ r = k;
}
return r;