chiark / gitweb /
core: rework unit name validation and manipulation logic
[elogind.git] / src / shared / generator.c
index c348ca2e04ed8189369a40ffaaaa531ce9d6bd37..8f48ac4fee23d23c7997cf725cc7fd3bcecdeccc 100644 (file)
@@ -37,23 +37,19 @@ int generator_write_fsck_deps(
                 const char *where,
                 const char *fstype) {
 
+        int r;
+
         assert(f);
         assert(dest);
         assert(what);
         assert(where);
 
-        if (fstype_is_deviceless(fstype)) {
-                log_debug("Not checking deviceless filesystem \"%s\".", fstype);
-                return 0;
-        }
-
         if (!is_device_path(what)) {
                 log_warning("Checking was requested for \"%s\", but it is not a device.", what);
                 return 0;
         }
 
         if (!isempty(fstype) && !streq(fstype, "auto")) {
-                int r;
                 r = fsck_exists(fstype);
                 if (r == -ENOENT) {
                         /* treat missing check as essentially OK */
@@ -75,9 +71,9 @@ int generator_write_fsck_deps(
         } else {
                 _cleanup_free_ char *fsck = NULL;
 
-                fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
-                if (!fsck)
-                        return log_oom();
+                r = unit_name_from_path_instance("systemd-fsck", what, ".service", &fsck);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to create fsck service name: %m");
 
                 fprintf(f,
                         "RequiresOverridable=%s\n"
@@ -108,8 +104,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
 
         r = parse_sec(timeout, &u);
         if (r < 0) {
-                log_warning("Failed to parse timeout for %s, ignoring: %s",
-                            where, timeout);
+                log_warning("Failed to parse timeout for %s, ignoring: %s", where, timeout);
                 return 0;
         }
 
@@ -117,9 +112,9 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
         if (!node)
                 return log_oom();
 
-        unit = unit_name_from_path(node, ".device");
-        if (!unit)
-                return log_oom();
+        r = unit_name_from_path(node, ".device", &unit);
+        if (r < 0)
+                return log_error_errno(r, "Failed to make unit name from path: %m");
 
         return write_drop_in_format(dir, unit, 50, "device-timeout",
                                     "# Automatically generated by %s\n\n"