Zbigniew Jędrzejewski-Szmek d743bb
From a28e8d4e77d1bbca7f0b13c6a2eebc4883ba1123 Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek d743bb
From: NeilBrown <neil@brown.name>
Zbigniew Jędrzejewski-Szmek d743bb
Date: Tue, 23 May 2017 17:42:26 +1000
Zbigniew Jędrzejewski-Szmek d743bb
Subject: [PATCH] Allow TimeoutSec=0 to work as documented in mount units and
Zbigniew Jędrzejewski-Szmek d743bb
 elsewhere (#6013)
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
Since commit 36c16a7cdd6c ("core: rework unit timeout handling, and add
Zbigniew Jędrzejewski-Szmek d743bb
new setting RuntimeMaxSec=") TimeoutSec=0 in mount units has
Zbigniew Jędrzejewski-Szmek d743bb
cause the mount to timeout immediately instead of never as documented.
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
There is a similar problem with Socket.TimeoutSec and Swap.TimeoutSec.
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
These are easily fixed using config_parse_sec_fix_0().
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
Automount.TimeoutIdleSec looks like it could have the same problem,
Zbigniew Jędrzejewski-Szmek d743bb
but doesn't because the kernel treats '0' as 'no timeout'.
Zbigniew Jędrzejewski-Szmek d743bb
It handle USEC_INFINITY correctly only because that constant has
Zbigniew Jędrzejewski-Szmek d743bb
the value '-1', and when round up, it becomes zero.
Zbigniew Jędrzejewski-Szmek d743bb
To avoid possible confusion, use config_parse_sec_fix_0() as well, and
Zbigniew Jędrzejewski-Szmek d743bb
explicitly handle USEC_INFINITY.
Zbigniew Jędrzejewski-Szmek d743bb
(cherry picked from commit 2d79a0bbb9f651656384a0a86ed814e6306fb5dd)
Zbigniew Jędrzejewski-Szmek d743bb
---
Zbigniew Jędrzejewski-Szmek d743bb
 src/core/automount.c                  | 7 +++++--
Zbigniew Jędrzejewski-Szmek d743bb
 src/core/load-fragment-gperf.gperf.m4 | 8 ++++----
Zbigniew Jędrzejewski-Szmek d743bb
 2 files changed, 9 insertions(+), 6 deletions(-)
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
diff --git a/src/core/automount.c b/src/core/automount.c
Zbigniew Jędrzejewski-Szmek d743bb
index 99e8047620..ccc113b598 100644
Zbigniew Jędrzejewski-Szmek d743bb
--- a/src/core/automount.c
Zbigniew Jędrzejewski-Szmek d743bb
+++ b/src/core/automount.c
Zbigniew Jędrzejewski-Szmek d743bb
@@ -415,8 +415,11 @@ static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, usec_t usec) {
Zbigniew Jędrzejewski-Szmek d743bb
         init_autofs_dev_ioctl(¶m;;
Zbigniew Jędrzejewski-Szmek d743bb
         param.ioctlfd = ioctl_fd;
Zbigniew Jędrzejewski-Szmek d743bb
 
Zbigniew Jędrzejewski-Szmek d743bb
-        /* Convert to seconds, rounding up. */
Zbigniew Jędrzejewski-Szmek d743bb
-        param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
Zbigniew Jędrzejewski-Szmek d743bb
+        if (usec == USEC_INFINITY)
Zbigniew Jędrzejewski-Szmek d743bb
+                param.timeout.timeout = 0;
Zbigniew Jędrzejewski-Szmek d743bb
+        else
Zbigniew Jędrzejewski-Szmek d743bb
+                /* Convert to seconds, rounding up. */
Zbigniew Jędrzejewski-Szmek d743bb
+                param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
Zbigniew Jędrzejewski-Szmek d743bb
 
Zbigniew Jędrzejewski-Szmek d743bb
         if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
Zbigniew Jędrzejewski-Szmek d743bb
                 return -errno;
Zbigniew Jędrzejewski-Szmek d743bb
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
Zbigniew Jędrzejewski-Szmek d743bb
index cb9e6fea27..3f7cbaa0d0 100644
Zbigniew Jędrzejewski-Szmek d743bb
--- a/src/core/load-fragment-gperf.gperf.m4
Zbigniew Jędrzejewski-Szmek d743bb
+++ b/src/core/load-fragment-gperf.gperf.m4
Zbigniew Jędrzejewski-Szmek d743bb
@@ -298,7 +298,7 @@ Socket.ExecStartPre,             config_parse_exec,                  SOCKET_EXEC
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.ExecStartPost,            config_parse_exec,                  SOCKET_EXEC_START_POST,        offsetof(Socket, exec_command)
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.ExecStopPre,              config_parse_exec,                  SOCKET_EXEC_STOP_PRE,          offsetof(Socket, exec_command)
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.ExecStopPost,             config_parse_exec,                  SOCKET_EXEC_STOP_POST,         offsetof(Socket, exec_command)
Zbigniew Jędrzejewski-Szmek d743bb
-Socket.TimeoutSec,               config_parse_sec,                   0,                             offsetof(Socket, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
+Socket.TimeoutSec,               config_parse_sec_fix_0,             0,                             offsetof(Socket, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.SocketUser,               config_parse_user_group,            0,                             offsetof(Socket, user)
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.SocketGroup,              config_parse_user_group,            0,                             offsetof(Socket, group)
Zbigniew Jędrzejewski-Szmek d743bb
 Socket.SocketMode,               config_parse_mode,                  0,                             offsetof(Socket, socket_mode)
Zbigniew Jędrzejewski-Szmek d743bb
@@ -362,7 +362,7 @@ Mount.What,                      config_parse_unit_string_printf,    0,
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.Where,                     config_parse_path,                  0,                             offsetof(Mount, where)
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.Options,                   config_parse_unit_string_printf,    0,                             offsetof(Mount, parameters_fragment.options)
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.Type,                      config_parse_string,                0,                             offsetof(Mount, parameters_fragment.fstype)
Zbigniew Jędrzejewski-Szmek d743bb
-Mount.TimeoutSec,                config_parse_sec,                   0,                             offsetof(Mount, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
+Mount.TimeoutSec,                config_parse_sec_fix_0,             0,                             offsetof(Mount, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.DirectoryMode,             config_parse_mode,                  0,                             offsetof(Mount, directory_mode)
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.SloppyOptions,             config_parse_bool,                  0,                             offsetof(Mount, sloppy_options)
Zbigniew Jędrzejewski-Szmek d743bb
 Mount.LazyUnmount,               config_parse_bool,                  0,                             offsetof(Mount, lazy_unmount)
Zbigniew Jędrzejewski-Szmek d743bb
@@ -373,12 +373,12 @@ KILL_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
Zbigniew Jędrzejewski-Szmek d743bb
 m4_dnl
Zbigniew Jędrzejewski-Szmek d743bb
 Automount.Where,                 config_parse_path,                  0,                             offsetof(Automount, where)
Zbigniew Jędrzejewski-Szmek d743bb
 Automount.DirectoryMode,         config_parse_mode,                  0,                             offsetof(Automount, directory_mode)
Zbigniew Jędrzejewski-Szmek d743bb
-Automount.TimeoutIdleSec,        config_parse_sec,                   0,                             offsetof(Automount, timeout_idle_usec)
Zbigniew Jędrzejewski-Szmek d743bb
+Automount.TimeoutIdleSec,        config_parse_sec_fix_0,             0,                             offsetof(Automount, timeout_idle_usec)
Zbigniew Jędrzejewski-Szmek d743bb
 m4_dnl
Zbigniew Jędrzejewski-Szmek d743bb
 Swap.What,                       config_parse_path,                  0,                             offsetof(Swap, parameters_fragment.what)
Zbigniew Jędrzejewski-Szmek d743bb
 Swap.Priority,                   config_parse_int,                   0,                             offsetof(Swap, parameters_fragment.priority)
Zbigniew Jędrzejewski-Szmek d743bb
 Swap.Options,                    config_parse_unit_string_printf,    0,                             offsetof(Swap, parameters_fragment.options)
Zbigniew Jędrzejewski-Szmek d743bb
-Swap.TimeoutSec,                 config_parse_sec,                   0,                             offsetof(Swap, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
+Swap.TimeoutSec,                 config_parse_sec_fix_0,             0,                             offsetof(Swap, timeout_usec)
Zbigniew Jędrzejewski-Szmek d743bb
 EXEC_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl
Zbigniew Jędrzejewski-Szmek d743bb
 CGROUP_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl
Zbigniew Jędrzejewski-Szmek d743bb
 KILL_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl