nixpkgs/pkgs/os-specific/linux/mdadm/no-self-references.patch
2022-08-14 11:41:19 +02:00

124 lines
3.9 KiB
Diff

diff --git a/Makefile b/Makefile
index 2a51d813..a31ac48a 100644
--- a/Makefile
+++ b/Makefile
@@ -63,6 +63,9 @@ endif
ifdef DEBIAN
CPPFLAGS += -DDEBIAN
endif
+ifdef NIXOS
+CPPFLAGS += -DNIXOS
+endif
ifdef DEFAULT_OLD_METADATA
CPPFLAGS += -DDEFAULT_OLD_METADATA
DEFAULT_METADATA=0.90
@@ -129,6 +132,7 @@ endif
INSTALL = /usr/bin/install
DESTDIR =
BINDIR = /sbin
+INSTALL_BINDIR = ${BINDIR}
MANDIR = /usr/share/man
MAN4DIR = $(MANDIR)/man4
MAN5DIR = $(MANDIR)/man5
@@ -253,16 +257,16 @@ sha1.o : sha1.c sha1.h md5.h
install : install-bin install-man install-udev
install-static : mdadm.static install-man
- $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
+ $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(INSTALL_BINDIR)/mdadm
install-tcc : mdadm.tcc install-man
- $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
+ $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
install-uclibc : mdadm.uclibc install-man
- $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
+ $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
install-klibc : mdadm.klibc install-man
- $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
+ $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
$(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
@@ -305,7 +309,7 @@ install-bin: mdadm mdmon
$(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
uninstall:
- rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
+ rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(INSTALL_BINDIR)/mdadm
test: mdadm mdmon test_stripe swap_super raid6check
@echo "Please run './test' as root"
diff --git a/policy.c b/policy.c
index eee9ef63..9f916e9d 100644
--- a/policy.c
+++ b/policy.c
@@ -817,12 +817,39 @@ char *find_rule(struct rule *rule, char *rule_type)
#define UDEV_RULE_FORMAT \
"ACTION==\"add\", SUBSYSTEM==\"block\", " \
"ENV{DEVTYPE}==\"%s\", ENV{ID_PATH}==\"%s\", " \
-"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
+"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
#define UDEV_RULE_FORMAT_NOTYPE \
"ACTION==\"add\", SUBSYSTEM==\"block\", " \
"ENV{ID_PATH}==\"%s\", " \
-"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
+"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
+
+#ifdef NIXOS
+const char *get_mdadm_bindir(void)
+{
+ static char *bindir = NULL;
+ if (bindir != NULL) {
+ return bindir;
+ } else {
+ int len;
+ bindir = xmalloc(1025);
+ len = readlink("/proc/self/exe", bindir, 1024);
+ if (len > 0) {
+ char *basename;
+ if ((basename = strrchr(bindir, '/')) != NULL)
+ *basename = '\0';
+ else
+ *(bindir + len) = '\0';
+ } else {
+ *bindir = '\0';
+ }
+ return bindir;
+ }
+}
+#define SELF get_mdadm_bindir()
+#else
+#define SELF BINDIR
+#endif
/* Write rule in the rule file. Use format from UDEV_RULE_FORMAT */
int write_rule(struct rule *rule, int fd, int force_part)
@@ -836,9 +863,9 @@ int write_rule(struct rule *rule, int fd, int force_part)
if (force_part)
typ = type_part;
if (typ)
- snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth);
+ snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth, SELF);
else
- snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth);
+ snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth, SELF);
return write(fd, line, strlen(line)) == (int)strlen(line);
}
diff --git a/util.c b/util.c
index 3d05d074..e004a798 100644
--- a/util.c
+++ b/util.c
@@ -1913,7 +1913,9 @@ int start_mdmon(char *devnm)
char pathbuf[1024];
char *paths[4] = {
pathbuf,
+#ifndef NIXOS
BINDIR "/mdmon",
+#endif
"./mdmon",
NULL
};