chiark / gitweb /
shared: add ring buffer
[elogind.git] / src / test / test-unit-file.c
index 1b4133b5d34004ba999d02b6cffc027541f52bd2..63a8a7d076a397b98213a28c62ec2583e46c0947 100644 (file)
@@ -25,6 +25,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "install.h"
 #include "install-printf.h"
@@ -221,7 +222,9 @@ static void test_load_env_file_1(void) {
         int r;
 
         char name[] = "/tmp/test-load-env-file.XXXXXX";
-        _cleanup_close_ int fd = mkstemp(name);
+        _cleanup_close_ int fd;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
         assert(fd >= 0);
         assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
 
@@ -242,7 +245,9 @@ static void test_load_env_file_2(void) {
         int r;
 
         char name[] = "/tmp/test-load-env-file.XXXXXX";
-        _cleanup_close_ int fd = mkstemp(name);
+        _cleanup_close_ int fd;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
         assert(fd >= 0);
         assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
 
@@ -258,7 +263,9 @@ static void test_load_env_file_3(void) {
         int r;
 
         char name[] = "/tmp/test-load-env-file.XXXXXX";
-        _cleanup_close_ int fd = mkstemp(name);
+        _cleanup_close_ int fd;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
         assert(fd >= 0);
         assert_se(write(fd, env_file_3, sizeof(env_file_3)) == sizeof(env_file_3));
 
@@ -270,10 +277,11 @@ static void test_load_env_file_3(void) {
 
 static void test_load_env_file_4(void) {
         _cleanup_strv_free_ char **data = NULL;
+        char name[] = "/tmp/test-load-env-file.XXXXXX";
+        _cleanup_close_ int fd;
         int r;
 
-        char name[] = "/tmp/test-load-env-file.XXXXXX";
-        _cleanup_close_ int fd = mkstemp(name);
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
         assert(fd >= 0);
         assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));
 
@@ -287,9 +295,6 @@ static void test_load_env_file_4(void) {
 }
 
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wnonnull"
-
 static void test_install_printf(void) {
         char    name[] = "name.service",
                 path[] = "/run/systemd/system/name.service",
@@ -335,7 +340,11 @@ static void test_install_printf(void) {
         expect(i, "%p", "name");
         expect(i, "%i", "");
         expect(i, "%u", "xxxx-no-such-user");
+
+        DISABLE_WARNING_NONNULL;
         expect(i, "%U", NULL);
+        REENABLE_WARNING;
+
         expect(i, "%m", mid);
         expect(i, "%b", bid);
         expect(i, "%H", host);
@@ -347,7 +356,11 @@ static void test_install_printf(void) {
         expect(i3, "%N", "name@inst");
         expect(i3, "%p", "name");
         expect(i3, "%u", "xxxx-no-such-user");
+
+        DISABLE_WARNING_NONNULL;
         expect(i3, "%U", NULL);
+        REENABLE_WARNING;
+
         expect(i3, "%m", mid);
         expect(i3, "%b", bid);
         expect(i3, "%H", host);
@@ -355,7 +368,6 @@ static void test_install_printf(void) {
         expect(i4, "%u", "root");
         expect(i4, "%U", "0");
 }
-#pragma GCC diagnostic pop
 
 int main(int argc, char *argv[]) {
         int r;