Jean Wolter <[email protected]> writes: > So to me it looks like mdev should try to do the renaming before > actually creating the device node (or deleting it for a remove hotplug > event). The attached patch against git (head?) tries to fix this. It > is adapted from a patch against 1.14.1 and did not get much testing so > far.
Hmm, I used git send-email to send the patch, but it looks like the actual patch was lost. So here it is like prepared by git:
>From 46cdb4752753bf85bf16d97af15d739724bb2389 Mon Sep 17 00:00:00 2001 From: Jean Wolter <[email protected]> Date: Wed, 17 Jun 2009 15:25:56 +0200 Subject: [PATCH] mdev: lookup alias names before creating or deleting nodes, otherwise mdev might accidently delete already existing nodes Example: capi 0:0 0660 =capi20 capi([0-9]) 0:0 0660 =capi20.0%1 capi([0-9]*) 0:0 0660 =capi20.%1 Hotplug event "add capi /class/capi/capi" creates /dev/capi20 Hotplug event "add tty /class/tty/capi20" - deletes /dev/capi20, - creates node /dev/capi20 - renames it to /dev/capi20.20 afterwards After that /dev/capi20 is gone. --- util-linux/mdev.c | 40 +++++++++++++++++++--------------------- 1 files changed, 19 insertions(+), 21 deletions(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 7508930..10bb5ee 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -319,23 +319,21 @@ static void make_device(char *path, int delete) /* "Execute" the line we found */ if (!delete && major >= 0) { - if (ENABLE_FEATURE_MDEV_RENAME) - unlink(device_name); - if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST) - bb_perror_msg_and_die("mknod %s", device_name); + char * node_name = (char *)device_name; + if (ENABLE_FEATURE_MDEV_RENAME && alias) + alias = node_name = build_alias(alias, device_name); + if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST) + bb_perror_msg_and_die("mknod %s", node_name); if (major == root_major && minor == root_minor) - symlink(device_name, "root"); + symlink(node_name, "root"); if (ENABLE_FEATURE_MDEV_CONF) { - chmod(device_name, mode); - chown(device_name, ugid.uid, ugid.gid); + chmod(node_name, mode); + chown(node_name, ugid.uid, ugid.gid); } if (ENABLE_FEATURE_MDEV_RENAME && alias) { - alias = build_alias(alias, device_name); - /* move the device, and optionally - * make a symlink to moved device node */ - if (rename(device_name, alias) == 0 && aliaslink == '>') - symlink(alias, device_name); - free(alias); + if (aliaslink == '>') + symlink(node_name, device_name); + free(alias); } } @@ -355,15 +353,15 @@ static void make_device(char *path, int delete) } if (delete) { - unlink(device_name); - /* At creation time, device might have been moved - * and a symlink might have been created. Undo that. */ - - if (ENABLE_FEATURE_MDEV_RENAME && alias) { - alias = build_alias(alias, device_name); - unlink(alias); + char * node_name = (char *)device_name; + if (ENABLE_FEATURE_MDEV_RENAME && alias) { + alias = node_name = build_alias(alias, device_name); + if (aliaslink == '>') + unlink(device_name); + } + unlink(node_name); + if (ENABLE_FEATURE_MDEV_RENAME) free(alias); - } } /* We found matching line. -- 1.5.6.5
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
