]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/exec-credential: remove no longer needed per-cred atomic update logic
authorMike Yuan <me@yhndnzj.com>
Sat, 8 Nov 2025 02:20:13 +0000 (03:20 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 10 Nov 2025 22:06:14 +0000 (23:06 +0100)
Now that we guarantee at higher level that we work on unique
credential dir, this becomes unnecessary.

src/core/exec-credential.c

index d2b83073694d45485d631bec5e17647b2c0b0b68..7321868d5d5716bf6e0c3869c8f4209a350ca0f5 100644 (file)
@@ -29,7 +29,6 @@
 #include "siphash24.h"
 #include "stat-util.h"
 #include "strv.h"
-#include "tmpfile-util.h"
 #include "user-util.h"
 
 ExecSetCredential* exec_set_credential_free(ExecSetCredential *sc) {
@@ -320,7 +319,6 @@ static int write_credential(
                 gid_t gid,
                 bool ownership_ok) {
 
-        _cleanup_free_ char *tmp = NULL;
         _cleanup_close_ int fd = -EBADF;
         int r;
 
@@ -328,16 +326,10 @@ static int write_credential(
         assert(id);
         assert(data || size == 0);
 
-        r = tempfn_random_child("", "cred", &tmp);
-        if (r < 0)
-                return r;
-
-        fd = openat(dfd, tmp, O_CREAT|O_RDWR|O_CLOEXEC|O_EXCL|O_NOFOLLOW|O_NOCTTY, 0600);
+        fd = openat(dfd, id, O_CREAT|O_EXCL|O_WRONLY|O_CLOEXEC, 0600);
         if (fd < 0)
                 return -errno;
 
-        CLEANUP_TMPFILE_AT(dfd, tmp);
-
         r = loop_write(fd, data, size);
         if (r < 0)
                 return r;
@@ -359,11 +351,6 @@ static int write_credential(
                         return r;
         }
 
-        r = RET_NERRNO(renameat(dfd, tmp, dfd, id));
-        if (r < 0)
-                return r;
-
-        tmp = mfree(tmp); /* disarm CLEANUP_TMPFILE_AT() */
         return 0;
 }