python312Packages.vdf: avoid using pname for src.repo
[NixPkgs.git] / pkgs / os-specific / linux / mdadm / no-self-references.patch
blob3b3dc4d8460958c6ebcce51e5dffd0208042b838
1 diff --git a/Makefile b/Makefile
2 index 2a51d813..a31ac48a 100644
3 --- a/Makefile
4 +++ b/Makefile
5 @@ -63,6 +63,9 @@ endif
6 ifdef DEBIAN
7 CPPFLAGS += -DDEBIAN
8 endif
9 +ifdef NIXOS
10 +CPPFLAGS += -DNIXOS
11 +endif
12 ifdef DEFAULT_OLD_METADATA
13 CPPFLAGS += -DDEFAULT_OLD_METADATA
14 DEFAULT_METADATA=0.90
15 @@ -129,6 +132,7 @@ endif
16 INSTALL = /usr/bin/install
17 DESTDIR =
18 BINDIR = /sbin
19 +INSTALL_BINDIR = ${BINDIR}
20 MANDIR = /usr/share/man
21 MAN4DIR = $(MANDIR)/man4
22 MAN5DIR = $(MANDIR)/man5
23 @@ -253,16 +257,16 @@ sha1.o : sha1.c sha1.h md5.h
24 install : install-bin install-man install-udev
26 install-static : mdadm.static install-man
27 - $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
28 + $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(INSTALL_BINDIR)/mdadm
30 install-tcc : mdadm.tcc install-man
31 - $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
32 + $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
34 install-uclibc : mdadm.uclibc install-man
35 - $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
36 + $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
38 install-klibc : mdadm.klibc install-man
39 - $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
40 + $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
42 install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
43 $(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
44 @@ -305,7 +309,7 @@ install-bin: mdadm mdmon
45 $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
47 uninstall:
48 - rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
49 + rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(INSTALL_BINDIR)/mdadm
51 test: mdadm mdmon test_stripe swap_super raid6check
52 @echo "Please run './test' as root"
53 diff --git a/policy.c b/policy.c
54 index eee9ef63..9f916e9d 100644
55 --- a/policy.c
56 +++ b/policy.c
57 @@ -817,12 +817,39 @@ char *find_rule(struct rule *rule, char *rule_type)
58 #define UDEV_RULE_FORMAT \
59 "ACTION==\"add\", SUBSYSTEM==\"block\", " \
60 "ENV{DEVTYPE}==\"%s\", ENV{ID_PATH}==\"%s\", " \
61 -"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
62 +"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
64 #define UDEV_RULE_FORMAT_NOTYPE \
65 "ACTION==\"add\", SUBSYSTEM==\"block\", " \
66 "ENV{ID_PATH}==\"%s\", " \
67 -"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
68 +"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
70 +#ifdef NIXOS
71 +const char *get_mdadm_bindir(void)
73 + static char *bindir = NULL;
74 + if (bindir != NULL) {
75 + return bindir;
76 + } else {
77 + int len;
78 + bindir = xmalloc(1025);
79 + len = readlink("/proc/self/exe", bindir, 1024);
80 + if (len > 0) {
81 + char *basename;
82 + if ((basename = strrchr(bindir, '/')) != NULL)
83 + *basename = '\0';
84 + else
85 + *(bindir + len) = '\0';
86 + } else {
87 + *bindir = '\0';
88 + }
89 + return bindir;
90 + }
92 +#define SELF get_mdadm_bindir()
93 +#else
94 +#define SELF BINDIR
95 +#endif
97 /* Write rule in the rule file. Use format from UDEV_RULE_FORMAT */
98 int write_rule(struct rule *rule, int fd, int force_part)
99 @@ -836,9 +863,9 @@ int write_rule(struct rule *rule, int fd, int force_part)
100 if (force_part)
101 typ = type_part;
102 if (typ)
103 - snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth);
104 + snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth, SELF);
105 else
106 - snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth);
107 + snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth, SELF);
108 return write(fd, line, strlen(line)) == (int)strlen(line);
111 diff --git a/util.c b/util.c
112 index 3d05d074..e004a798 100644
113 --- a/util.c
114 +++ b/util.c
115 @@ -1913,7 +1913,9 @@ int start_mdmon(char *devnm)
116 char pathbuf[1024];
117 char *paths[4] = {
118 pathbuf,
119 +#ifndef NIXOS
120 BINDIR "/mdmon",
121 +#endif
122 "./mdmon",
123 NULL