Skip to content

Commit 2d79a0b

Browse files
neilbrownpoettering
authored andcommitted
Allow TimeoutSec=0 to work as documented in mount units and elsewhere (systemd#6013)
Since commit 36c16a7 ("core: rework unit timeout handling, and add new setting RuntimeMaxSec=") TimeoutSec=0 in mount units has cause the mount to timeout immediately instead of never as documented. There is a similar problem with Socket.TimeoutSec and Swap.TimeoutSec. These are easily fixed using config_parse_sec_fix_0(). Automount.TimeoutIdleSec looks like it could have the same problem, but doesn't because the kernel treats '0' as 'no timeout'. It handle USEC_INFINITY correctly only because that constant has the value '-1', and when round up, it becomes zero. To avoid possible confusion, use config_parse_sec_fix_0() as well, and explicitly handle USEC_INFINITY.
1 parent e8a94ce commit 2d79a0b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/core/automount.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,11 @@ static int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, usec_t usec) {
415415
init_autofs_dev_ioctl(&param);
416416
param.ioctlfd = ioctl_fd;
417417

418-
/* Convert to seconds, rounding up. */
419-
param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
418+
if (usec == USEC_INFINITY)
419+
param.timeout.timeout = 0;
420+
else
421+
/* Convert to seconds, rounding up. */
422+
param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
420423

421424
if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, &param) < 0)
422425
return -errno;

src/core/load-fragment-gperf.gperf.m4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Socket.ExecStartPre, config_parse_exec, SOCKET_EXEC
299299
Socket.ExecStartPost, config_parse_exec, SOCKET_EXEC_START_POST, offsetof(Socket, exec_command)
300300
Socket.ExecStopPre, config_parse_exec, SOCKET_EXEC_STOP_PRE, offsetof(Socket, exec_command)
301301
Socket.ExecStopPost, config_parse_exec, SOCKET_EXEC_STOP_POST, offsetof(Socket, exec_command)
302-
Socket.TimeoutSec, config_parse_sec, 0, offsetof(Socket, timeout_usec)
302+
Socket.TimeoutSec, config_parse_sec_fix_0, 0, offsetof(Socket, timeout_usec)
303303
Socket.SocketUser, config_parse_user_group, 0, offsetof(Socket, user)
304304
Socket.SocketGroup, config_parse_user_group, 0, offsetof(Socket, group)
305305
Socket.SocketMode, config_parse_mode, 0, offsetof(Socket, socket_mode)
@@ -363,7 +363,7 @@ Mount.What, config_parse_unit_string_printf, 0,
363363
Mount.Where, config_parse_path, 0, offsetof(Mount, where)
364364
Mount.Options, config_parse_unit_string_printf, 0, offsetof(Mount, parameters_fragment.options)
365365
Mount.Type, config_parse_string, 0, offsetof(Mount, parameters_fragment.fstype)
366-
Mount.TimeoutSec, config_parse_sec, 0, offsetof(Mount, timeout_usec)
366+
Mount.TimeoutSec, config_parse_sec_fix_0, 0, offsetof(Mount, timeout_usec)
367367
Mount.DirectoryMode, config_parse_mode, 0, offsetof(Mount, directory_mode)
368368
Mount.SloppyOptions, config_parse_bool, 0, offsetof(Mount, sloppy_options)
369369
Mount.LazyUnmount, config_parse_bool, 0, offsetof(Mount, lazy_unmount)
@@ -374,12 +374,12 @@ KILL_CONTEXT_CONFIG_ITEMS(Mount)m4_dnl
374374
m4_dnl
375375
Automount.Where, config_parse_path, 0, offsetof(Automount, where)
376376
Automount.DirectoryMode, config_parse_mode, 0, offsetof(Automount, directory_mode)
377-
Automount.TimeoutIdleSec, config_parse_sec, 0, offsetof(Automount, timeout_idle_usec)
377+
Automount.TimeoutIdleSec, config_parse_sec_fix_0, 0, offsetof(Automount, timeout_idle_usec)
378378
m4_dnl
379379
Swap.What, config_parse_path, 0, offsetof(Swap, parameters_fragment.what)
380380
Swap.Priority, config_parse_int, 0, offsetof(Swap, parameters_fragment.priority)
381381
Swap.Options, config_parse_unit_string_printf, 0, offsetof(Swap, parameters_fragment.options)
382-
Swap.TimeoutSec, config_parse_sec, 0, offsetof(Swap, timeout_usec)
382+
Swap.TimeoutSec, config_parse_sec_fix_0, 0, offsetof(Swap, timeout_usec)
383383
EXEC_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl
384384
CGROUP_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl
385385
KILL_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl

0 commit comments

Comments
 (0)