teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0057-Allow-TimeoutSec-0-to-work-as-documented-in-mount-un.patch

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