6a312f
From 7cc9fe69d3f35038b7b3329fef0cccdbe38ffef6 Mon Sep 17 00:00:00 2001
6a312f
From: Karel Zak <kzak@redhat.com>
6a312f
Date: Mon, 13 Dec 2021 13:22:56 +0100
6a312f
Subject: mount: add hint about systemctl daemon-reload
6a312f
6a312f
This commit implements an extra hint for systemd based distros to
6a312f
inform users that units currently used by systemd are older than
6a312f
fstab.  This situation is usually unwanted, and 'systemctl
6a312f
daemon-reload' is recommended.
6a312f
6a312f
The message is printed only on terminal to avoid extra messages in
6a312f
logs, etc.
6a312f
6a312f
Addresses: https://github.com/systemd/systemd/pull/20476
6a312f
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180413
6a312f
Upstream: http://github.com/util-linux/util-linux/commit/1db0715169954a8f3898f7ca9d3902cd6c27084d
6a312f
Signed-off-by: Karel Zak <kzak@redhat.com>
6a312f
---
6a312f
 include/pathnames.h |  2 ++
6a312f
 sys-utils/mount.c   | 23 +++++++++++++++++++++++
6a312f
 2 files changed, 25 insertions(+)
6a312f
6a312f
diff --git a/include/pathnames.h b/include/pathnames.h
6a312f
index 77f8b6e85..19b117cb9 100644
6a312f
--- a/include/pathnames.h
6a312f
+++ b/include/pathnames.h
6a312f
@@ -76,6 +76,8 @@
6a312f
 #define _PATH_NUMLOCK_ON	_PATH_RUNSTATEDIR "/numlock-on"
6a312f
 #define _PATH_LOGINDEFS		"/etc/login.defs"
6a312f
 
6a312f
+#define _PATH_SD_UNITSLOAD	_PATH_RUNSTATEDIR "/systemd/systemd-units-load"
6a312f
+
6a312f
 /* misc paths */
6a312f
 #define _PATH_WORDS             "/usr/share/dict/words"
6a312f
 #define _PATH_WORDS_ALT         "/usr/share/dict/web2"
6a312f
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
6a312f
index 83cccf63e..108b55001 100644
6a312f
--- a/sys-utils/mount.c
6a312f
+++ b/sys-utils/mount.c
6a312f
@@ -38,6 +38,7 @@
6a312f
 #include "strutils.h"
6a312f
 #include "closestream.h"
6a312f
 #include "canonicalize.h"
6a312f
+#include "pathnames.h"
6a312f
 
6a312f
 #define XALLOC_EXIT_CODE MNT_EX_SYSERR
6a312f
 #include "xalloc.h"
6a312f
@@ -287,6 +288,25 @@ static void selinux_warning(struct libmnt_context *cxt, const char *tgt)
6a312f
 # define selinux_warning(_x, _y)
6a312f
 #endif
6a312f
 
6a312f
+static void systemd_hint(void)
6a312f
+{
6a312f
+	static int fstab_check_done = 0;
6a312f
+
6a312f
+	if (fstab_check_done == 0) {
6a312f
+		struct stat a, b;
6a312f
+
6a312f
+		if (isatty(STDERR_FILENO) &&
6a312f
+		    stat(_PATH_SD_UNITSLOAD, &a) == 0 &&
6a312f
+		    stat(_PATH_MNTTAB, &b) == 0 &&
6a312f
+		    cmp_stat_mtime(&a, &b, <))
6a312f
+			printf(_(
6a312f
+	"mount: (hint) your fstab has been modified, but systemd still uses\n"
6a312f
+	"       the old version; use 'systemctl daemon-reload' to reload.\n"));
6a312f
+
6a312f
+		fstab_check_done = 1;
6a312f
+	}
6a312f
+}
6a312f
+
6a312f
 /*
6a312f
  * Returns exit status (MNT_EX_*) and/or prints error message.
6a312f
  */
6a312f
@@ -310,6 +330,9 @@ static int mk_exit_code(struct libmnt_context *cxt, int rc)
6a312f
 	if (rc == MNT_EX_SUCCESS && mnt_context_get_status(cxt) == 1) {
6a312f
 		selinux_warning(cxt, tgt);
6a312f
 	}
6a312f
+
6a312f
+	systemd_hint();
6a312f
+
6a312f
 	return rc;
6a312f
 }
6a312f
 
6a312f
-- 
6a312f
2.39.2
6a312f