From: Mike Yuan Date: Sun, 8 Dec 2024 19:47:41 +0000 (+0100) Subject: fstab-generator: move write_(mount_)timeout() to shared/generator X-Git-Tag: v258-rc1~1885^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=149e05c7e98738c5c29b4a0db71b42d56283e861;p=thirdparty%2Fsystemd.git fstab-generator: move write_(mount_)timeout() to shared/generator --- diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 6a7cf57ba34..4dfe9fea897 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -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; diff --git a/src/shared/generator.c b/src/shared/generator.c index 5397ad15694..738f1892797 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -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, diff --git a/src/shared/generator.h b/src/shared/generator.h index ff8e8d1c6bf..5879e34ea25 100644 --- a/src/shared/generator.h +++ b/src/shared/generator.h @@ -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(