]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: move write_(mount_)timeout() to shared/generator
authorMike Yuan <me@yhndnzj.com>
Sun, 8 Dec 2024 19:47:41 +0000 (20:47 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 9 Dec 2024 18:25:59 +0000 (19:25 +0100)
src/fstab-generator/fstab-generator.c
src/shared/generator.c
src/shared/generator.h

index 6a7cf57ba349fd7ed82947fc5e94167cc99cd7a5..4dfe9fea89785a9a76ef1dcc034cb0f4d0a21220 100644 (file)
@@ -325,47 +325,9 @@ static bool mount_in_initrd(const char *where, const char *options, bool accept_
                 (where && PATH_IN_SET(where, "/usr", accept_root ? "/" : NULL));
 }
 
-static int write_timeout(
-                FILE *f,
-                const char *where,
-                const char *opts,
-                const char *filter,
-                const char *unit_setting) {
-
-        _cleanup_free_ char *timeout = NULL;
-        usec_t u;
-        int r;
-
-        assert(f);
-        assert(where);
-        assert(filter);
-        assert(unit_setting);
-
-        r = fstab_filter_options(opts, filter, NULL, &timeout, NULL, NULL);
-        if (r < 0)
-                return log_error_errno(r, "Failed to parse options for '%s': %m", where);
-        if (r == 0)
-                return 0;
-
-        r = parse_sec_fix_0(timeout, &u);
-        if (r < 0) {
-                log_warning_errno(r, "Failed to parse timeout '%s' for '%s', ignoring: %m", timeout, where);
-                return 0;
-        }
-
-        fprintf(f, "%s=%s\n", unit_setting, FORMAT_TIMESPAN(u, 0));
-
-        return 0;
-}
-
 static int write_idle_timeout(FILE *f, const char *where, const char *opts) {
-        return write_timeout(f, where, opts,
-                             "x-systemd.idle-timeout\0", "TimeoutIdleSec");
-}
-
-static int write_mount_timeout(FILE *f, const char *where, const char *opts) {
-        return write_timeout(f, where, opts,
-                             "x-systemd.mount-timeout\0", "TimeoutSec");
+        return generator_write_unit_timeout(f, where, opts,
+                                            "x-systemd.idle-timeout\0", "TimeoutIdleSec");
 }
 
 static int write_dependency(
@@ -684,7 +646,7 @@ static int add_mount(
                         return r;
         }
 
-        r = write_mount_timeout(f, where, opts);
+        r = generator_write_mount_timeout(f, where, opts);
         if (r < 0)
                 return r;
 
index 5397ad1569481afab80ff7cad460cf798d4da346..738f18927979e8daff8f0762dae2dcb7d95c34fd 100644 (file)
@@ -427,6 +427,39 @@ int generator_write_device_timeout(
         return 1;
 }
 
+int generator_write_unit_timeout(
+                FILE *f,
+                const char *where,
+                const char *opts,
+                const char *filter,
+                const char *unit_setting) {
+
+        _cleanup_free_ char *timeout = NULL;
+        usec_t u;
+        int r;
+
+        assert(f);
+        assert(where);
+        assert(filter);
+        assert(unit_setting);
+
+        r = fstab_filter_options(opts, filter, NULL, &timeout, NULL, NULL);
+        if (r < 0)
+                return log_error_errno(r, "Failed to parse options for '%s': %m", where);
+        if (r == 0)
+                return 0;
+
+        r = parse_sec_fix_0(timeout, &u);
+        if (r < 0) {
+                log_warning_errno(r, "Failed to parse timeout '%s' for '%s', ignoring: %m", timeout, where);
+                return 0;
+        }
+
+        fprintf(f, "%s=%s\n", unit_setting, FORMAT_TIMESPAN(u, 0));
+
+        return 0;
+}
+
 int generator_write_network_device_deps(
                 const char *dir,
                 const char *what,
index ff8e8d1c6bf9b863c26f9fc66636e5d9ce8330a6..5879e34ea25dbf8bfee69695cbbaf9b5b9769f5b 100644 (file)
@@ -29,6 +29,17 @@ int generator_write_device_timeout(
         const char *opts,
         char **filtered);
 
+int generator_write_unit_timeout(
+                FILE *f,
+                const char *where,
+                const char *opts,
+                const char *filter,
+                const char *unit_setting);
+static inline int generator_write_mount_timeout(FILE *f, const char *where, const char *opts) {
+        return generator_write_unit_timeout(f, where, opts,
+                                            "x-systemd.mount-timeout\0", "TimeoutSec");
+}
+
 int generator_write_blockdev_dependency(FILE *f, const char *what);
 
 int generator_write_network_device_deps(