Now that mdmon responds fairly well to SIGTERM, stop lying to
systemd about being started on the initrd.
Note that if mdmon is rerun (--takeover) for some reason, and systemd
chooses to kill processes before remounting / readonly, then the
unmount will hang.
If systemd ever lets us tell it that we don't want to be killed until
root is readonly, then we should do that.
Signed-off-by: NeilBrown <neilb@suse.de>
extern char *stat2devnm(struct stat *st);
extern char *fd2devnm(int fd);
+extern int in_initrd(void);
+
#define _ROUND_UP(val, base) (((val) + (base) - 1) & ~(base - 1))
#define ROUND_UP(val, base) _ROUND_UP(val, (typeof(val))(base))
#define ROUND_UP_PTR(ptr, base) ((typeof(ptr)) \
{NULL, 0, NULL, 0}
};
- /*
- * Always change process name to @dmon to avoid systemd killing it
- */
- argv[0][0] = '@';
+ if (in_initrd()) {
+ /*
+ * set first char of argv[0] to @. This is used by
+ * systemd to signal that the task was launched from
+ * initrd/initramfs and should be preserved during shutdown
+ */
+ argv[0][0] = '@';
+ }
while ((opt = getopt_long(argc, argv, "thaF", options, NULL)) != -1) {
switch (opt) {
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/resource.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
#include <ctype.h>
#include <dirent.h>
#include <signal.h>
lim.rlim_cur = fds;
setrlimit(RLIMIT_NOFILE, &lim);
}
+
+int in_initrd(void)
+{
+ /* This is based on similar function in systemd. */
+ struct statfs s;
+ return statfs("/", &s) >= 0 &&
+ (s.f_type == TMPFS_MAGIC ||
+ s.f_type == RAMFS_MAGIC);
+}