aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-04-02 06:47:14 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-04-02 06:47:14 +0200
commitb38af7bd31d98dd6e849354ee94ebafe580e7cc1 (patch)
tree1bb84dbd4fdf6ba917b7a13ca436aba165856a2f /util-linux
parent5342c3f3106b4afa2a76d3173f4827c4b8236da8 (diff)
downloadbusybox-w32-b38af7bd31d98dd6e849354ee94ebafe580e7cc1.tar.gz
busybox-w32-b38af7bd31d98dd6e849354ee94ebafe580e7cc1.tar.bz2
busybox-w32-b38af7bd31d98dd6e849354ee94ebafe580e7cc1.zip
mdev: add "!" syntax support
Based on the patch by Steve Bennett <steveb@workware.net.au> function old new delta make_device 1640 1673 +33 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/mdev.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index b0efd98b5..217075660 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -204,7 +204,8 @@ static void make_device(char *path, int delete)
204 if (major < 0) 204 if (major < 0)
205 continue; /* no dev, no match */ 205 continue; /* no dev, no match */
206 sc = sscanf(val, "@%u,%u-%u", &cmaj, &cmin0, &cmin1); 206 sc = sscanf(val, "@%u,%u-%u", &cmaj, &cmin0, &cmin1);
207 if (sc < 1 || major != cmaj 207 if (sc < 1
208 || major != cmaj
208 || (sc == 2 && minor != cmin0) 209 || (sc == 2 && minor != cmin0)
209 || (sc == 3 && (minor < cmin0 || minor > cmin1)) 210 || (sc == 3 && (minor < cmin0 || minor > cmin1))
210 ) { 211 ) {
@@ -243,7 +244,8 @@ static void make_device(char *path, int delete)
243 244
244 /* If no match, skip rest of line */ 245 /* If no match, skip rest of line */
245 /* (regexec returns whole pattern as "range" 0) */ 246 /* (regexec returns whole pattern as "range" 0) */
246 if (result || off[0].rm_so 247 if (result
248 || off[0].rm_so
247 || ((int)off[0].rm_eo != (int)strlen(str_to_match)) 249 || ((int)off[0].rm_eo != (int)strlen(str_to_match))
248 ) { 250 ) {
249 continue; /* this line doesn't match */ 251 continue; /* this line doesn't match */
@@ -258,28 +260,34 @@ static void make_device(char *path, int delete)
258 bb_error_msg("unknown user/group %s on line %d", tokens[1], parser->lineno); 260 bb_error_msg("unknown user/group %s on line %d", tokens[1], parser->lineno);
259 261
260 /* 3rd field: mode - device permissions */ 262 /* 3rd field: mode - device permissions */
261 /* mode = strtoul(tokens[2], NULL, 8); */
262 bb_parse_mode(tokens[2], &mode); 263 bb_parse_mode(tokens[2], &mode);
263 264
264 val = tokens[3]; 265 val = tokens[3];
265 /* 4th field (opt): >|=alias */ 266 /* 4th field (opt): ">|=alias" or "!" to not create the node */
266 267
267 if (ENABLE_FEATURE_MDEV_RENAME && val) { 268 if (ENABLE_FEATURE_MDEV_RENAME && val) {
268 aliaslink = val[0]; 269 char *a, *s, *st;
269 if (aliaslink == '>' || aliaslink == '=') { 270
270 char *a, *s, *st; 271 a = val;
271 char *p; 272 s = strchrnul(val, ' ');
272 unsigned i, n; 273 st = strchrnul(val, '\t');
273 274 if (st < s)
274 a = val; 275 s = st;
275 s = strchrnul(val, ' '); 276 st = (s[0] && s[1]) ? s+1 : NULL;
276 st = strchrnul(val, '\t'); 277
277 if (st < s) 278 aliaslink = a[0];
278 s = st; 279 if (aliaslink == '!' && s == a+1) {
279 val = (s[0] && s[1]) ? s+1 : NULL; 280 val = st;
281 /* "!": suppress node creation/deletion */
282 major = -1;
283 }
284 else if (aliaslink == '>' || aliaslink == '=') {
285 val = st;
280 s[0] = '\0'; 286 s[0] = '\0';
281
282 if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) { 287 if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) {
288 char *p;
289 unsigned i, n;
290
283 /* substitute %1..9 with off[1..9], if any */ 291 /* substitute %1..9 with off[1..9], if any */
284 n = 0; 292 n = 0;
285 s = a; 293 s = a;
@@ -323,8 +331,13 @@ static void make_device(char *path, int delete)
323 /* Are we running this command now? 331 /* Are we running this command now?
324 * Run $cmd on delete, @cmd on create, *cmd on both 332 * Run $cmd on delete, @cmd on create, *cmd on both
325 */ 333 */
326 if (s2-s != delete) 334 if (s2 - s != delete) {
335 /* We are here if: '*',
336 * or: '@' and delete = 0,
337 * or: '$' and delete = 1
338 */
327 command = xstrdup(val + 1); 339 command = xstrdup(val + 1);
340 }
328 } 341 }
329 } 342 }
330 343
@@ -368,7 +381,7 @@ static void make_device(char *path, int delete)
368 free(command); 381 free(command);
369 } 382 }
370 383
371 if (delete) { 384 if (delete && major >= 0) {
372 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 385 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
373 if (aliaslink == '>') 386 if (aliaslink == '>')
374 unlink(device_name); 387 unlink(device_name);