chiark / gitweb /
fstab-generator: add comma when removed option is in the middle
[elogind.git] / src / shared / generator.c
index 1db5f8fb626802a2a7b9e75d7411abb41763e38d..2f9e5954c20d363bb2f29024b95cf6efd9b9e1dd 100644 (file)
@@ -108,7 +108,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
                 timeout = start + 25;
         else {
                 if (filtered) {
-                        *filtered = strdup(opts);
+                        *filtered = strdup(opts ?: "");
                         if (!*filtered)
                                 return log_oom();
                 }
@@ -125,7 +125,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
                 char *prefix, *postfix;
 
                 prefix = strndupa(opts, start - opts - (start != opts));
-                postfix = timeout + len + (timeout[len] != '\0');
+                postfix = timeout + len + (start == opts && timeout[len] != '\0');
                 *filtered = strjoin(prefix, *postfix ? postfix : NULL, NULL);
                 if (!*filtered)
                         return log_oom();
@@ -146,6 +146,9 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
         if (!unit)
                 return -ENOMEM;
 
-        return write_drop_in_format(dir, unit, "device-timeout",
-                                    "[Unit]\nJobTimeoutSec=%u", u / USEC_PER_SEC);
+        return write_drop_in_format(dir, unit, 50, "device-timeout",
+                                    "# Automatically generated by %s\n\n"
+                                    "[Unit]\nJobTimeoutSec=%u",
+                                    program_invocation_short_name,
+                                    u / USEC_PER_SEC);
 }