]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
user-runtime-dir: error out immediately if mkdir fails
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 24 Jan 2022 09:53:00 +0000 (10:53 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 24 Jan 2022 13:06:45 +0000 (13:06 +0000)
We try to create two directories: /run/user and /run/user/<UID>. For the
first we check the return value and error out if creation fails. But for
the second one we continued based on the assumption that the subsequent
mount will immediately fail anyway. But this has the disadvantage that we
get a somewhat confusing error message:

janv. 23 22:04:31 nsfw systemd-user-runtime-dir[1660]: Failed to mount per-user tmpfs directory /run/user/1000: No such file or directory

Let's instead fail immediately with a precise error message.

For https://bugzilla.redhat.com/show_bug.cgi?id=2044100.

src/login/user-runtime-dir.c

index 5ce5b35e178681801cce0c7394be84857ce7060f..f96a2d8662350cd9c95a61146c97457555283b9f 100644 (file)
@@ -80,7 +80,9 @@ static int user_mkdir_runtime_path(
                          uid, gid, runtime_dir_size, runtime_dir_inodes,
                          mac_smack_use() ? ",smackfsroot=*" : "");
 
-                (void) mkdir_label(runtime_path, 0700);
+                r = mkdir_label(runtime_path, 0700);
+                if (r < 0 && r != -EEXIST)
+                        return log_error_errno(r, "Failed to create %s: %m", runtime_path);
 
                 r = mount_nofollow_verbose(LOG_DEBUG, "tmpfs", runtime_path, "tmpfs", MS_NODEV|MS_NOSUID, options);
                 if (r < 0) {