b7dd4d
From 207f51115c18c668982ef8bdb8a024fccaeb87f0 Mon Sep 17 00:00:00 2001
b7dd4d
From: David Tardon <dtardon@redhat.com>
b7dd4d
Date: Sat, 16 Jul 2022 09:49:12 +0200
b7dd4d
Subject: [PATCH] core: allow to set default timeout for devices
b7dd4d
b7dd4d
Fixes: #19879
b7dd4d
(cherry picked from commit a0fe19f9f791c05af236265954b1d73e8fcf5468)
b7dd4d
b7dd4d
Resolves: #1967245
b7dd4d
---
b7dd4d
 src/core/dbus-manager.c | 1 +
b7dd4d
 src/core/device.c       | 2 +-
b7dd4d
 src/core/main.c         | 4 ++++
b7dd4d
 src/core/manager.c      | 1 +
b7dd4d
 src/core/manager.h      | 1 +
b7dd4d
 src/core/system.conf.in | 1 +
b7dd4d
 6 files changed, 9 insertions(+), 1 deletion(-)
b7dd4d
b7dd4d
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
b7dd4d
index 7488f22116..5b1ed3646e 100644
b7dd4d
--- a/src/core/dbus-manager.c
b7dd4d
+++ b/src/core/dbus-manager.c
b7dd4d
@@ -2509,6 +2509,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
b7dd4d
         SD_BUS_PROPERTY("DefaultTimerAccuracyUSec", "t", bus_property_get_usec, offsetof(Manager, default_timer_accuracy_usec), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
         SD_BUS_PROPERTY("DefaultTimeoutStartUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_start_usec), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
         SD_BUS_PROPERTY("DefaultTimeoutStopUSec", "t", bus_property_get_usec, offsetof(Manager, default_timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
+        SD_BUS_PROPERTY("DefaultDeviceTimeoutUSec", "t", bus_property_get_usec, offsetof(Manager, default_device_timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
         SD_BUS_PROPERTY("DefaultRestartUSec", "t", bus_property_get_usec, offsetof(Manager, default_restart_usec), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
         SD_BUS_PROPERTY("DefaultStartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Manager, default_start_limit_interval), SD_BUS_VTABLE_PROPERTY_CONST),
b7dd4d
         /* The following two items are obsolete alias */
b7dd4d
diff --git a/src/core/device.c b/src/core/device.c
b7dd4d
index cb8b66dfc5..71b7c1ef81 100644
b7dd4d
--- a/src/core/device.c
b7dd4d
+++ b/src/core/device.c
b7dd4d
@@ -97,7 +97,7 @@ static void device_init(Unit *u) {
b7dd4d
          * indefinitely for plugged in devices, something which cannot
b7dd4d
          * happen for the other units since their operations time out
b7dd4d
          * anyway. */
b7dd4d
-        u->job_running_timeout = u->manager->default_timeout_start_usec;
b7dd4d
+        u->job_running_timeout = u->manager->default_device_timeout_usec;
b7dd4d
 
b7dd4d
         u->ignore_on_isolate = true;
b7dd4d
 
b7dd4d
diff --git a/src/core/main.c b/src/core/main.c
b7dd4d
index 08a4df3c97..bfd4c531a7 100644
b7dd4d
--- a/src/core/main.c
b7dd4d
+++ b/src/core/main.c
b7dd4d
@@ -109,6 +109,7 @@ static usec_t arg_default_restart_usec;
b7dd4d
 static usec_t arg_default_timeout_start_usec;
b7dd4d
 static usec_t arg_default_timeout_stop_usec;
b7dd4d
 static usec_t arg_default_timeout_abort_usec;
b7dd4d
+static usec_t arg_default_device_timeout_usec;
b7dd4d
 static bool arg_default_timeout_abort_set;
b7dd4d
 static usec_t arg_default_start_limit_interval;
b7dd4d
 static unsigned arg_default_start_limit_burst;
b7dd4d
@@ -687,6 +688,7 @@ static int parse_config_file(void) {
b7dd4d
                 { "Manager", "DefaultStandardError",      config_parse_output_restricted,0, &arg_default_std_error                 },
b7dd4d
                 { "Manager", "DefaultTimeoutStartSec",    config_parse_sec,              0, &arg_default_timeout_start_usec        },
b7dd4d
                 { "Manager", "DefaultTimeoutStopSec",     config_parse_sec,              0, &arg_default_timeout_stop_usec         },
b7dd4d
+                { "Manager", "DefaultDeviceTimeoutSec",   config_parse_sec,              0, &arg_default_device_timeout_usec       },
b7dd4d
                 { "Manager", "DefaultRestartSec",         config_parse_sec,              0, &arg_default_restart_usec              },
b7dd4d
                 { "Manager", "DefaultStartLimitInterval", config_parse_sec,              0, &arg_default_start_limit_interval      }, /* obsolete alias */
b7dd4d
                 { "Manager", "DefaultStartLimitIntervalSec",config_parse_sec,            0, &arg_default_start_limit_interval      },
b7dd4d
@@ -754,6 +756,7 @@ static void set_manager_defaults(Manager *m) {
b7dd4d
         m->default_std_error = arg_default_std_error;
b7dd4d
         m->default_timeout_start_usec = arg_default_timeout_start_usec;
b7dd4d
         m->default_timeout_stop_usec = arg_default_timeout_stop_usec;
b7dd4d
+        m->default_device_timeout_usec = arg_default_device_timeout_usec;
b7dd4d
         m->default_restart_usec = arg_default_restart_usec;
b7dd4d
         m->default_start_limit_interval = arg_default_start_limit_interval;
b7dd4d
         m->default_start_limit_burst = arg_default_start_limit_burst;
b7dd4d
@@ -2077,6 +2080,7 @@ static void reset_arguments(void) {
b7dd4d
         arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
b7dd4d
         arg_default_timeout_abort_usec = DEFAULT_TIMEOUT_USEC;
b7dd4d
         arg_default_timeout_abort_set = false;
b7dd4d
+        arg_default_device_timeout_usec = DEFAULT_TIMEOUT_USEC;
b7dd4d
         arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
b7dd4d
         arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
b7dd4d
         arg_runtime_watchdog = 0;
b7dd4d
diff --git a/src/core/manager.c b/src/core/manager.c
b7dd4d
index 5873e5b6d7..f4611e6f8f 100644
b7dd4d
--- a/src/core/manager.c
b7dd4d
+++ b/src/core/manager.c
b7dd4d
@@ -731,6 +731,7 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) {
b7dd4d
         m->default_tasks_max = UINT64_MAX;
b7dd4d
         m->default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
b7dd4d
         m->default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
b7dd4d
+        m->default_device_timeout_usec = DEFAULT_TIMEOUT_USEC,
b7dd4d
         m->default_restart_usec = DEFAULT_RESTART_USEC;
b7dd4d
         m->original_log_level = -1;
b7dd4d
         m->original_log_target = _LOG_TARGET_INVALID;
b7dd4d
diff --git a/src/core/manager.h b/src/core/manager.h
b7dd4d
index 7b572c8dfd..3f2cfc5e2e 100644
b7dd4d
--- a/src/core/manager.h
b7dd4d
+++ b/src/core/manager.h
b7dd4d
@@ -285,6 +285,7 @@ struct Manager {
b7dd4d
         ExecOutput default_std_output, default_std_error;
b7dd4d
 
b7dd4d
         usec_t default_restart_usec, default_timeout_start_usec, default_timeout_stop_usec;
b7dd4d
+        usec_t default_device_timeout_usec;
b7dd4d
 
b7dd4d
         usec_t default_start_limit_interval;
b7dd4d
         unsigned default_start_limit_burst;
b7dd4d
diff --git a/src/core/system.conf.in b/src/core/system.conf.in
b7dd4d
index 84246c0e36..2f6852a89f 100644
b7dd4d
--- a/src/core/system.conf.in
b7dd4d
+++ b/src/core/system.conf.in
b7dd4d
@@ -37,6 +37,7 @@
b7dd4d
 #DefaultStandardError=inherit
b7dd4d
 #DefaultTimeoutStartSec=90s
b7dd4d
 #DefaultTimeoutStopSec=90s
b7dd4d
+#DefaultDeviceTimeoutSec=90s
b7dd4d
 #DefaultRestartSec=100ms
b7dd4d
 #DefaultStartLimitIntervalSec=10s
b7dd4d
 #DefaultStartLimitBurst=5