diff options
author | Denis Vlasenko | 2008-07-15 22:33:13 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-07-15 22:33:13 +0000 |
commit | 018bee6afb0a7b9e09616a52f2f24f65fcf07322 (patch) | |
tree | 8c86e74a094c12686adac6bb4cec56ba52347bda /util-linux | |
parent | 97faf531c81be075ecafb2ac83b17eae78cd2afb (diff) | |
download | busybox-018bee6afb0a7b9e09616a52f2f24f65fcf07322.zip busybox-018bee6afb0a7b9e09616a52f2f24f65fcf07322.tar.gz |
mdev: support for serializing hotplug
function old new delta
mdev_main 503 647 +144
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/mdev.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index c61521c..8968e45 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -374,8 +374,6 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa int mdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mdev_main(int argc UNUSED_PARAM, char **argv) { - char *action; - char *env_path; RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE); /* We can be called as hotplug helper */ @@ -417,8 +415,14 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) ACTION_RECURSE | ACTION_FOLLOWLINKS, fileAction, dirAction, temp, 0); } else { + char *seq; + char *action; + char *env_path; + char seqbuf[sizeof(int)*3 + 2]; + int seqlen = seqlen; /* for compiler */ + /* Hotplug: - * env ACTION=... DEVPATH=... mdev + * env ACTION=... DEVPATH=... [SEQNUM=...] mdev * ACTION can be "add" or "remove" * DEVPATH is like "/block/sda" or "/class/input/mice" */ @@ -427,6 +431,23 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) if (!action || !env_path) bb_show_usage(); + seq = getenv("SEQNUM"); + if (seq) { + int timeout = 2000 / 32; + do { + seqlen = open_read_close("mdev.seq", seqbuf, sizeof(seqbuf-1)); + if (seqlen < 0) + break; + seqbuf[seqlen] = '\0'; + if (seqbuf[0] == '\n' /* seed file? */ + || strcmp(seq, seqbuf) == 0 /* correct idx? */ + ) { + break; + } + usleep(32*1000); + } while (--timeout); + } + snprintf(temp, PATH_MAX, "/sys%s", env_path); if (!strcmp(action, "remove")) make_device(temp, 1); @@ -439,6 +460,10 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) load_firmware(fw, temp); } } + + if (seq && seqlen >= 0) { + xopen_xwrite_close("mdev.seq", utoa(xatou(seq) + 1)); + } } if (ENABLE_FEATURE_CLEAN_UP) |