aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-02 13:21:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-02 13:21:24 +0000
commit32dcc53b7162406148203b8222c3f5c5056f70f2 (patch)
treedcae696c5a80b3f5b51e4926d2e985a2dfcdb21c
parent6da9b00f4fb54b3deba1c2636d69950fdbcc0d67 (diff)
downloadbusybox-w32-32dcc53b7162406148203b8222c3f5c5056f70f2.tar.gz
busybox-w32-32dcc53b7162406148203b8222c3f5c5056f70f2.tar.bz2
busybox-w32-32dcc53b7162406148203b8222c3f5c5056f70f2.zip
mdev: fix a bug where we were eating argv[0] of helper
-rwxr-xr-xtestsuite/mdev.tests16
-rw-r--r--util-linux/mdev.c62
2 files changed, 48 insertions, 30 deletions
diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests
index 81c440d1f..572609e11 100755
--- a/testsuite/mdev.tests
+++ b/testsuite/mdev.tests
@@ -18,6 +18,8 @@ mkdir mdev.testdir
18# We need mdev executable to be in chroot jail! 18# We need mdev executable to be in chroot jail!
19# (will still fail with dynamically linked one, though...) 19# (will still fail with dynamically linked one, though...)
20cp ../busybox mdev.testdir/mdev 20cp ../busybox mdev.testdir/mdev
21mkdir mdev.testdir/bin
22cp ../busybox mdev.testdir/bin/sh 2>/dev/null # for testing cmd feature
21mkdir mdev.testdir/etc 23mkdir mdev.testdir/etc
22mkdir mdev.testdir/dev 24mkdir mdev.testdir/dev
23mkdir -p mdev.testdir/sys/block/sda 25mkdir -p mdev.testdir/sys/block/sda
@@ -93,6 +95,20 @@ brw-r--r-- 1 0 0 a_sda
93" \ 95" \
94 "" "" 96 "" ""
95 97
98# continuing to use directory structure from prev test
99rm -rf mdev.testdir/dev/*
100# here we complicate things by having non-matching group 1 and using %0
101echo "sda 0:0 644 @echo @echo TEST" >mdev.testdir/etc/mdev.conf
102testing "mdev command" \
103 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
104 ls -lnR mdev.testdir/dev | $FILTER_LS" \
105"\
106@echo TEST
107mdev.testdir/dev:
108brw-r--r-- 1 0 0 8,0 sda
109" \
110 "" ""
111
96# clean up 112# clean up
97rm -rf mdev.testdir 113rm -rf mdev.testdir
98 114
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 9d37b6c90..5e1cd36bb 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -156,43 +156,45 @@ static void make_device(char *path, int delete)
156 mode = strtoul(val, NULL, 8); 156 mode = strtoul(val, NULL, 8);
157 157
158 /* 4th field (opt): >alias */ 158 /* 4th field (opt): >alias */
159 if (ENABLE_FEATURE_MDEV_RENAME) { 159#if ENABLE_FEATURE_MDEV_RENAME
160 if (!next) 160 if (!next)
161 break; 161 break;
162 if (*next == '>') {
163#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
164 char *s, *p;
165 unsigned i, n;
166
162 val = next; 167 val = next;
163 next = next_field(val); 168 next = next_field(val);
164 if (*val == '>') { 169 /* substitute %1..9 with off[1..9], if any */
165#if ENABLE_FEATURE_MDEV_RENAME_REGEXP 170 n = 0;
166 /* substitute %1..9 with off[1..9], if any */ 171 s = val;
167 char *s, *p; 172 while (*s && *s++ == '%')
168 unsigned i, n; 173 n++;
169 174
170 n = 0; 175 p = alias = xzalloc(strlen(val) + n * strlen(device_name));
171 s = val; 176 s = val + 1;
172 while (*s && *s++ == '%') 177 while (*s) {
173 n++; 178 *p = *s;
174 179 if ('%' == *s) {
175 p = alias = xzalloc(strlen(val) + n * strlen(device_name)); 180 i = (s[1] - '0');
176 s = val + 1; 181 if (i <= 9 && off[i].rm_so >= 0) {
177 while (*s) { 182 n = off[i].rm_eo - off[i].rm_so;
178 *p = *s; 183 strncpy(p, device_name + off[i].rm_so, n);
179 if ('%' == *s) { 184 p += n - 1;
180 i = (s[1] - '0'); 185 s++;
181 if (i <= 9 && off[i].rm_so >= 0) {
182 n = off[i].rm_eo - off[i].rm_so;
183 strncpy(p, device_name + off[i].rm_so, n);
184 p += n - 1;
185 s++;
186 }
187 } 186 }
188 p++;
189 s++;
190 } 187 }
188 p++;
189 s++;
190 }
191#else 191#else
192 alias = xstrdup(val + 1); 192 val = next;
193 next = next_field(val);
194 alias = xstrdup(val + 1);
193#endif 195#endif
194 }
195 } 196 }
197#endif /* ENABLE_FEATURE_MDEV_RENAME */
196 198
197 /* The rest (opt): command to run */ 199 /* The rest (opt): command to run */
198 if (!next) 200 if (!next)