]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mount: add hint about systemctl daemon-reload
authorKarel Zak <kzak@redhat.com>
Mon, 13 Dec 2021 12:22:56 +0000 (13:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Dec 2021 12:22:56 +0000 (13:22 +0100)
This commit implements an extra hint for systemd based distros to
inform users that units currently used by systemd are older than
fstab.  This situation is usually unwanted, and 'systemctl
daemon-reload' is recommended.

The message is printed only on terminal to avoid extra messages in
logs, etc.

Addresses: https://github.com/systemd/systemd/pull/20476
Signed-off-by: Karel Zak <kzak@redhat.com>
include/pathnames.h
sys-utils/mount.c

index 5fbb54ec343191e2af2a93c39549d946b75c17f6..d86d9d5feb94d98a6a21aab7de3ac95b5e27c3e2 100644 (file)
@@ -82,6 +82,8 @@
 #define _PATH_NUMLOCK_ON       _PATH_RUNSTATEDIR "/numlock-on"
 #define _PATH_LOGINDEFS                "/etc/login.defs"
 
+#define _PATH_SD_UNITSLOAD     _PATH_RUNSTATEDIR "/systemd/systemd-units-load"
+
 /* misc paths */
 #define _PATH_WORDS             "/usr/share/dict/words"
 #define _PATH_WORDS_ALT         "/usr/share/dict/web2"
index ac7af42cb187f630de00c67a20faf86f24b9ff93..ba4c78e3b01df5b1915846836a56deb73989f0ed 100644 (file)
@@ -38,6 +38,7 @@
 #include "strutils.h"
 #include "closestream.h"
 #include "canonicalize.h"
+#include "pathnames.h"
 
 #define XALLOC_EXIT_CODE MNT_EX_SYSERR
 #include "xalloc.h"
@@ -336,6 +337,31 @@ static void selinux_warning(struct libmnt_context *cxt, const char *tgt)
 # define selinux_warning(_x, _y)
 #endif
 
+
+#ifdef USE_SYSTEMD
+static void systemd_hint(void)
+{
+       static int fstab_check_done = 0;
+
+       if (fstab_check_done == 0) {
+               struct stat a, b;
+
+               if (isatty(STDERR_FILENO) &&
+                   stat(_PATH_SD_UNITSLOAD, &a) == 0 &&
+                   stat(_PATH_MNTTAB, &b) == 0 &&
+                   cmp_stat_mtime(&a, &b, <))
+                       printf(_(
+       "mount: (hint) your fstab has been modified, but systemd still uses\n"
+       "       the old version; use 'systemctl daemon-reload' to reload.\n"));
+
+               fstab_check_done = 1;
+       }
+}
+#else
+# define systemd_hint()
+#endif
+
+
 /*
  * Returns exit status (MNT_EX_*) and/or prints error message.
  */
@@ -363,6 +389,9 @@ static int mk_exit_code(struct libmnt_context *cxt, int rc)
        if (rc == MNT_EX_SUCCESS && mnt_context_get_status(cxt) == 1) {
                selinux_warning(cxt, tgt);
        }
+
+       systemd_hint();
+
        return rc;
 }