chiark / gitweb /
tmpfiles: replace readdir_r with readdir
[elogind.git] / src / tmpfiles / tmpfiles.c
index e23847bbea65e1180598720c92ab30c178d41d8e..e83a73e2793c3ffc014644d82415ea3349ecadba 100644 (file)
@@ -52,6 +52,7 @@
 #include "conf-files.h"
 #include "capability.h"
 #include "specifier.h"
+#include "build.h"
 
 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
  * them in the file system. This is intended to be used to create
@@ -465,8 +466,10 @@ static int item_set_perms(Item *i, const char *path) {
 }
 
 static int write_one_file(Item *i, const char *path) {
-        int r, e, fd, flags;
+        int e, flags;
+        int fd = -1;
         struct stat st;
+        int r = 0;
 
         flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND :
                 i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
@@ -540,15 +543,15 @@ static int recursive_relabel_children(Item *i, const char *path) {
 
         for (;;) {
                 struct dirent *de;
-                union dirent_storage buf;
                 bool is_dir;
                 int r;
                 _cleanup_free_ char *entry_path = NULL;
 
-                r = readdir_r(d, &buf.de, &de);
-                if (r != 0) {
+                errno = 0;
+                de = readdir(d);
+                if (!de && errno != 0) {
                         if (ret == 0)
-                                ret = -r;
+                                ret = -errno;
                         break;
                 }
 
@@ -638,8 +641,9 @@ static int glob_item(Item *i, int (*action)(Item *, const char *)) {
 }
 
 static int create_item(Item *i) {
-        int r, e;
+        int e;
         struct stat st;
+        int r = 0;
 
         assert(i);
 
@@ -1263,6 +1267,7 @@ static int help(void) {
         printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
                "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
                "  -h --help                 Show this help\n"
+               "     --version              Show package version\n"
                "     --create               Create marked files/directories\n"
                "     --clean                Clean up marked directories\n"
                "     --remove               Remove marked files/directories\n"
@@ -1276,6 +1281,7 @@ static int help(void) {
 static int parse_argv(int argc, char *argv[]) {
 
         enum {
+                ARG_VERSION = 0x100,
                 ARG_CREATE,
                 ARG_CLEAN,
                 ARG_REMOVE,
@@ -1285,12 +1291,13 @@ static int parse_argv(int argc, char *argv[]) {
 
         static const struct option options[] = {
                 { "help",           no_argument,         NULL, 'h'                },
+                { "version",        no_argument,         NULL, ARG_VERSION        },
                 { "create",         no_argument,         NULL, ARG_CREATE         },
                 { "clean",          no_argument,         NULL, ARG_CLEAN          },
                 { "remove",         no_argument,         NULL, ARG_REMOVE         },
                 { "prefix",         required_argument,   NULL, ARG_PREFIX         },
                 { "exclude-prefix", required_argument,   NULL, ARG_EXCLUDE_PREFIX },
-                { NULL,             0,                   NULL, 0                  }
+                {}
         };
 
         int c;
@@ -1303,7 +1310,11 @@ static int parse_argv(int argc, char *argv[]) {
                 switch (c) {
 
                 case 'h':
-                        help();
+                        return help();
+
+                case ARG_VERSION:
+                        puts(PACKAGE_STRING);
+                        puts(SYSTEMD_FEATURES);
                         return 0;
 
                 case ARG_CREATE:
@@ -1332,8 +1343,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return -EINVAL;
 
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        assert_not_reached("Unhandled option");
                 }
         }