]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/sysv-generator/sysv-generator.c
util-lib: split out allocation calls into alloc-util.[ch]
[thirdparty/systemd.git] / src / sysv-generator / sysv-generator.c
index 0d246b1835a0f4c23871240c424cb74eaeea99b8..0a0b9269b3f91c59af82b9657eda50bb8203def2 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-#include "util.h"
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "hashmap.h"
+#include "hexdecoct.h"
+#include "install.h"
+#include "log.h"
 #include "mkdir.h"
-#include "strv.h"
-#include "path-util.h"
 #include "path-lookup.h"
-#include "log.h"
-#include "unit-name.h"
-#include "special.h"
-#include "hashmap.h"
+#include "path-util.h"
 #include "set.h"
-#include "install.h"
+#include "special.h"
+#include "stat-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "unit-name.h"
+#include "util.h"
 
 typedef enum RunlevelType {
         RUNLEVEL_UP,
@@ -240,22 +245,21 @@ static bool usage_contains_reload(const char *line) {
 }
 
 static char *sysv_translate_name(const char *name) {
-        char *r;
-        _cleanup_free_ char *c;
+        _cleanup_free_ char *c = NULL;
+        char *res;
 
         c = strdup(name);
         if (!c)
-            return NULL;
+                return NULL;
 
-        r = endswith(c, ".sh");
-        if (r) {
-            *r = '\0';
-        }
+        res = endswith(c, ".sh");
+        if (res)
+                *res = 0;
 
-        if (unit_name_mangle(c, UNIT_NAME_NOGLOB, &r) >= 0)
-            return r;
-        else
-            return NULL;
+        if (unit_name_mangle(c, UNIT_NAME_NOGLOB, &res) < 0)
+                return NULL;
+
+        return res;
 }
 
 static int sysv_translate_facility(const char *name, const char *filename, char **_r) {
@@ -377,8 +381,7 @@ static int handle_provides(SysvStub *s, unsigned line, const char *full_text, co
                                 if (r < 0)
                                         return log_oom();
                         }
-                }
-                else if (t == _UNIT_TYPE_INVALID)
+                } else if (t == _UNIT_TYPE_INVALID)
                         log_warning("Unit name '%s' is invalid", m);
                 else
                         log_warning("Unknown unit type for unit '%s'", m);
@@ -741,7 +744,7 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
                         if (hidden_file(de->d_name))
                                 continue;
 
-                        if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
+                        if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
                                 log_warning_errno(errno, "stat() failed on %s/%s: %m", *path, de->d_name);
                                 continue;
                         }
@@ -808,8 +811,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
                         if (!path)
                                 return -ENOMEM;
 
-                        if (d)
-                                closedir(d);
+                        safe_closedir(d);
 
                         d = opendir(path);
                         if (!d) {