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