aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--docs/mdev.txt16
-rw-r--r--util-linux/mdev.c51
2 files changed, 43 insertions, 24 deletions
diff --git a/docs/mdev.txt b/docs/mdev.txt
index 7bd00fe1b..2d03bd8b2 100644
--- a/docs/mdev.txt
+++ b/docs/mdev.txt
@@ -51,8 +51,8 @@ device nodes if your system needs something more than the default root/root
51660 permissions. 51660 permissions.
52 52
53The file has the format: 53The file has the format:
54 <device regex> <uid>:<gid> <octal permissions> 54 <device regex> <uid>:<gid> <permissions>
55 or @<maj[,min1[-min2]]> <uid>:<gid> <octal permissions> 55 or @<maj[,min1[-min2]]> <uid>:<gid> <permissions>
56 56
57For example: 57For example:
58 hd[a-z][0-9]* 0:3 660 58 hd[a-z][0-9]* 0:3 660
@@ -63,7 +63,7 @@ create your own total match like so:
63 .* 1:1 777 63 .* 1:1 777
64 64
65You can rename/move device nodes by using the next optional field. 65You can rename/move device nodes by using the next optional field.
66 <device regex> <uid>:<gid> <octal permissions> [=path] 66 <device regex> <uid>:<gid> <permissions> [=path]
67So if you want to place the device node into a subdirectory, make sure the path 67So if you want to place the device node into a subdirectory, make sure the path
68has a trailing /. If you want to rename the device node, just place the name. 68has a trailing /. If you want to rename the device node, just place the name.
69 hda 0:3 660 =drives/ 69 hda 0:3 660 =drives/
@@ -74,11 +74,17 @@ This will rename "hdb" to "cdrom".
74Similarly, ">path" renames/moves the device but it also creates 74Similarly, ">path" renames/moves the device but it also creates
75a direct symlink /dev/DEVNAME to the renamed/moved device. 75a direct symlink /dev/DEVNAME to the renamed/moved device.
76 76
77You can also prevent creation of device nodes with the 4th field as "!":
78 tty[a-z]. 0:0 660 !
79 pty[a-z]. 0:0 660 !
80
77If you also enable support for executing your own commands, then the file has 81If you also enable support for executing your own commands, then the file has
78the format: 82the format:
79 <device regex> <uid>:<gid> <octal permissions> [=path] [@|$|*<command>] 83 <device regex> <uid>:<gid> <permissions> [=path] [@|$|*<command>]
84 or
85 <device regex> <uid>:<gid> <permissions> [>path] [@|$|*<command>]
80 or 86 or
81 <device regex> <uid>:<gid> <octal permissions> [>path] [@|$|*<command>] 87 <device regex> <uid>:<gid> <permissions> [!] [@|$|*<command>]
82 88
83For example: 89For example:
84---8<--- 90---8<---
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);