]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use mkdtemp_open()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Feb 2023 02:12:13 +0000 (11:12 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Feb 2023 02:18:49 +0000 (11:18 +0900)
src/test/test-xattr-util.c

index 04d23ef09b267f2fd76b4c9dec58009e2e9fcd47..2d2d464eccb9cb56693c3f0faeb601d7ace9e15e 100644 (file)
 #include "fd-util.h"
 #include "fs-util.h"
 #include "macro.h"
+#include "rm-rf.h"
 #include "string-util.h"
 #include "tests.h"
 #include "tmpfile-util.h"
 #include "xattr-util.h"
 
 TEST(getxattr_at_malloc) {
-        char t[] = "/var/tmp/xattrtestXXXXXX";
+        _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
         _cleanup_free_ char *value = NULL;
         _cleanup_close_ int fd = -EBADF;
         const char *x;
         int r;
 
-        assert_se(mkdtemp(t));
+        fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_RDONLY|O_NOCTTY, &t);
+        assert_se(fd >= 0);
         x = strjoina(t, "/test");
         assert_se(touch(x) >= 0);
 
         r = setxattr(x, "user.foo", "bar", 3, 0);
-        if (r < 0 && ERRNO_IS_NOT_SUPPORTED(errno)) /* no xattrs supported on /var/tmp... */
-                goto cleanup;
+        if (r < 0 && ERRNO_IS_NOT_SUPPORTED(errno))
+                return (void) log_tests_skipped_errno(errno, "no xattrs supported on /var/tmp");
         assert_se(r >= 0);
 
-        fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
-        assert_se(fd >= 0);
-
         assert_se(getxattr_at_malloc(fd, "test", "user.foo", 0, &value) == 3);
         assert_se(memcmp(value, "bar", 3) == 0);
         value = mfree(value);
@@ -53,21 +52,15 @@ TEST(getxattr_at_malloc) {
         assert_se(fd >= 0);
         assert_se(getxattr_at_malloc(fd, NULL, "user.foo", 0, &value) == 3);
         assert_se(streq(value, "bar"));
-
-cleanup:
-        assert_se(unlink(x) >= 0);
-        assert_se(rmdir(t) >= 0);
 }
 
 TEST(getcrtime) {
+        _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
         _cleanup_close_ int fd = -EBADF;
-        const char *vt;
         usec_t usec, k;
         int r;
 
-        assert_se(var_tmp_dir(&vt) >= 0);
-
-        fd = open_tmpfile_unlinkable(vt, O_RDWR);
+        fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", 0, &t);
         assert_se(fd >= 0);
 
         r = fd_getcrtime(fd, &usec);