chiark / gitweb /
service: timeout for oneshot services
authorLukas Nykryn <lnykryn@redhat.com>
Thu, 14 Jun 2012 15:07:07 +0000 (17:07 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Fri, 15 Jun 2012 14:04:06 +0000 (16:04 +0200)
Add possibility to specify timeout for oneshot services.

[ https://bugzilla.redhat.com/show_bug.cgi?id=761656
  Added minor fixups. -- michich ]

man/systemd.service.xml
src/core/load-fragment-gperf.gperf.m4
src/core/load-fragment.c
src/core/load-fragment.h
src/core/service.c
src/core/service.h

index 12d0b8a12b98a91d7e388c32ecc47e5d7722dcd5..233807d2b3313f6dc2a027051d96a964350a32b6 100644 (file)
                                 time span value such as "5min
                                 20s". Pass 0 to disable the timeout
                                 logic. Defaults to
-                                90s.</para></listitem>
+                                90s, except when <varname>Type=oneshot</varname> is
+                                used in which case the timeout
+                                is disabled by default.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index 0e21e8165fb32b2dda49339fedb775d03355c10a..d51c7ac5e2bee942fc2aa09a4c66ce7199347df2 100644 (file)
@@ -138,7 +138,7 @@ Service.ExecReload,              config_parse_exec,                  SERVICE_EXE
 Service.ExecStop,                config_parse_exec,                  SERVICE_EXEC_STOP,             offsetof(Service, exec_command)
 Service.ExecStopPost,            config_parse_exec,                  SERVICE_EXEC_STOP_POST,        offsetof(Service, exec_command)
 Service.RestartSec,              config_parse_usec,                  0,                             offsetof(Service, restart_usec)
-Service.TimeoutSec,              config_parse_usec,                  0,                             offsetof(Service, timeout_usec)
+Service.TimeoutSec,              config_parse_service_timeout,       0,                             offsetof(Service, timeout_usec)
 Service.WatchdogSec,             config_parse_usec,                  0,                             offsetof(Service, watchdog_usec)
 Service.StartLimitInterval,      config_parse_usec,                  0,                             offsetof(Service, start_limit.interval)
 Service.StartLimitBurst,         config_parse_unsigned,              0,                             offsetof(Service, start_limit.burst)
index 5494d7bce41008b1fd6ab11286106f49a25180fe..22da6c1197e70e95d42c4ae7db61990be2f01a83 100644 (file)
@@ -1398,6 +1398,32 @@ int config_parse_service_sockets(
         return 0;
 }
 
+int config_parse_service_timeout(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        Service *s = userdata;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(s);
+
+        r = config_parse_usec(filename, line, section, lvalue, ltype, rvalue, data, userdata);
+
+        if (!r)
+                s->timeout_defined = true;
+
+        return r;
+}
+
 int config_parse_unit_env_file(
                 const char *filename,
                 unsigned line,
index aa48ebdd3c3fdf181a7ad761df08b05b39bd65a2..9a3465a166f4c9c4857fecaa77223d8adbdfb7c4 100644 (file)
@@ -42,6 +42,7 @@ int config_parse_socket_bind(const char *filename, unsigned line, const char *se
 int config_parse_exec_nice(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_exec_oom_score_adjust(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_exec(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_service_timeout(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_service_type(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_service_restart(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_socket_bindtodevice(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
index 936fee2636320f98705d1d42e1fa34698c228186..8941271679adde950d7471d5b854cc46b254b614 100644 (file)
@@ -1249,6 +1249,10 @@ static int service_load(Unit *u) {
                 if (s->type == _SERVICE_TYPE_INVALID)
                         s->type = s->bus_name ? SERVICE_DBUS : SERVICE_SIMPLE;
 
+                /* Oneshot services have disabled timeout by default */
+                if (s->type == SERVICE_ONESHOT && !s->timeout_defined)
+                        s->timeout_usec = 0;
+
                 service_fix_output(s);
 
                 if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
@@ -2157,7 +2161,7 @@ static void service_enter_start(Service *s) {
 
         r = service_spawn(s,
                           c,
-                          s->type == SERVICE_FORKING || s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY,
+                          s->type == SERVICE_FORKING || s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY || s->type == SERVICE_ONESHOT,
                           true,
                           true,
                           true,
@@ -2372,7 +2376,7 @@ static void service_run_next_main(Service *s) {
 
         r = service_spawn(s,
                           s->main_command,
-                          false,
+                          true,
                           true,
                           true,
                           true,
index f4ccc2b5a0454d39118eb0ec7a1ef2d62c47c44d..4a7287d82701e12648f4b3f7aa9af9e912cff7cd 100644 (file)
@@ -164,6 +164,7 @@ struct Service {
         bool bus_name_good:1;
         bool forbid_restart:1;
         bool got_socket_fd:1;
+        bool timeout_defined:1;
 #ifdef HAVE_SYSV_COMPAT
         bool is_sysv:1;
         bool sysv_has_lsb:1;