1 diff -urN -x .svn hotplug2-0.9/AUTHORS hotplug2/AUTHORS
2 --- hotplug2-0.9/AUTHORS 2006-10-08 18:13:50.000000000 +0200
3 +++ hotplug2/AUTHORS 2007-06-25 10:51:14.688225416 +0200
7 iSteve <isteve@bofh.cz>
8 -Tomas Janousek <tomi@nomi.cz>
12 +nbd (rules override patch)
13 +Tomas Janousek <tomi@nomi.cz> (Makefiles, SVN hosting)
18 Randy Dunlap (help with isapnpmap)
19 Igor2 (provided testing machines)
20 yanek (provided testing machines)
21 +Zdenek Styblik (provided testing OpenWRT device)
22 +OpenWRT team (for trusting this project)
23 +mtu (debugging, testing, ideas)
24 +mnemoc (trivial sanity changes on makefiles, linux24 compat patches)
26 -...anyone taking more than a short peek at the software.
27 \ No newline at end of file
28 +...anyone taking more than a short peek at the software.
29 diff -urN -x .svn hotplug2-0.9/Changelog hotplug2/Changelog
30 --- hotplug2-0.9/Changelog 2006-10-08 15:32:31.000000000 +0200
31 +++ hotplug2/Changelog 2007-06-25 10:51:14.689225264 +0200
34 +* Add --set-rules-file.
36 +* Add 'printdebug' rule.
37 +* Fix chmod, chown, chgrp.
38 +* Use octal for chmod and makedev.
41 * Use signals to handle children.
42 * Separate info and debugging output.
45 * Significant cleanup of rules handling.
46 * Better error reporting.
48 \ No newline at end of file
50 diff -urN -x .svn hotplug2-0.9/docs/hotplug2.8 hotplug2/docs/hotplug2.8
51 --- hotplug2-0.9/docs/hotplug2.8 2006-09-26 09:23:36.000000000 +0200
52 +++ hotplug2/docs/hotplug2.8 2007-06-25 10:51:14.540247912 +0200
55 \fB\-\-set\-modprobe\-cmd <cmd>\fR
56 Sets the application used to perform modprobe. It only gets used in dumb mode. Default is to autodetect: if '/bin/modprobe' is from module\-init\-tools, use '/sbin/modprobe', otherwise use '/sbin/hotplug2\-modwrap'.
57 +\fB\-\-set\-rules\-file <file>\fR
58 +Sets the path to the file containing hotplug2 rules.
62 diff -urN -x .svn hotplug2-0.9/docs/hotplug2.rules.doc hotplug2/docs/hotplug2.rules.doc
63 --- hotplug2-0.9/docs/hotplug2.rules.doc 2006-09-26 10:19:46.000000000 +0200
64 +++ hotplug2/docs/hotplug2.rules.doc 2007-06-25 10:51:14.537248368 +0200
69 -Comments are allowed, they are prefixed with '#', treating the whole rest of the
70 -line as comment. Please note that comments in place of action parameters are not
72 +Comments are allowed, they are prefixed with '#', treating the whole rest of
73 +the line as comment. Please note that comments in place of action parameters
76 -The <key> is one of the environmental variables that have been obtained by the
78 +The <key> is one of the environmental variables that have been obtained by
87 - Execute an application using system();, takes one parameter. Note that
88 - the application has set all environmental variables read by uevent
90 + Execute an application using system();, takes one parameter. Note
91 + that the application has set all environmental variables read by
95 Break the processing of the current block of actions.
98 * exec <application [parameter [parameter [...]]]> ;
99 Execute an application. Takes variable number of parameters, but the
100 - last parameter must be terminated with semicolon. Again, all variables
101 - are set as environmental.
102 + last parameter must be terminated with semicolon. Again, all
103 + variables are set as environmental.
105 - If you need to escape the ';', use '\\;'. Only applies for actions with
106 - variable number of parameters.
107 + If you need to escape the ';', use '\\;'. Only applies for actions
108 + with variable number of parameters.
110 * makedev <path> <mode>
111 - Create a device with given mode. The mode is not in octal unless it
112 - starts with '0', eg. "0644" != "644".
113 + Create a device with given mode. Mode is interpreted as octal.
115 Major, minor and devpath must be set for makedev to be able to work.
116 Tests for these variables are also performed internally in makedev
119 * symlink <target> <linkname>
120 - Create a symbolic link (symlink, also known as soft link) pointing at
121 - target with name linkname.
122 + Create a symbolic link (symlink, also known as soft link) pointing
123 + at target with name linkname.
125 * chown <path> <owner name>
126 Change owner of path to owner name.
127 @@ -111,12 +110,14 @@
128 Change group of path to group name.
130 * chmod <path> <mode>
131 - Change mode of path to given mode. Like with makedev, heading '0' is
132 - necessary for the mode to be interpreted as octal.
133 + Change mode of path to given mode. Mode is interpreted as octal.
135 * setenv <key> <value>
136 Sets environmental variable key to the given value. If an env var
137 of the given name already exists, it gets overwritten.
140 + Prints all variables read from kernel.
148 -Below is a sample hotplug2.rules file. It loads modules to all available devices
149 -quietly and creates device nodes for block devices.
150 +Below is a sample hotplug2.rules file. It loads modules to all available
151 +devices quietly and creates device nodes for block devices. Note that this
152 +sample is not very viable for real life usage.
153 ---------------------------------------------------------------------------------
155 exec modprobe -q %MODALIAS% ;
157 SUBSYSTEM == block, DEVPATH is set, MAJOR is set, MINOR is set {
158 makedev /dev/%DEVICENAME% 0644
162 +Please find also the more complex set of rules, dedicated to handling most
164 +---------------------------------------------------------------------------------
170 +# Load modules (what old hotplug did)
172 + exec modprobe -q %MODALIAS% ;
175 +# Create device nodes
176 +DEVPATH is set, MAJOR is set, MINOR is set {
177 + makedev /dev/%DEVICENAME% 0644
180 +# Mount a USB flashdisk
181 +ACTION == add, PHYSDEVPATH ~~ "/usb[0-9]*/", DEVICENAME ~~ "^sd[a-z][0-9]+$", DEVPATH is set, MAJOR is set, MINOR is set {
182 + makedev /dev/%DEVICENAME% 0644
183 + exec mount /dev/%DEVICENAME% /mnt/%DEVICENAME%
186 +# Unmount a USB flashdisk
187 +ACTION == remove, PHYSDEVPATH ~~ "/usb[0-9]*/", DEVICENAME ~~ "^sd[a-z][0-9]+$", MAJOR is set, MINOR is set {
188 + exec umount /mnt/%DEVICENAME%
190 diff -urN -x .svn hotplug2-0.9/docs/Makefile hotplug2/docs/Makefile
191 --- hotplug2-0.9/docs/Makefile 2006-09-26 00:27:02.000000000 +0200
192 +++ hotplug2/docs/Makefile 2007-06-25 10:51:14.540247912 +0200
199 +MANDIR=/usr/share/man
204 - $(INSTALL) $(wildcard *.8) /usr/share/man/man8/
205 + $(INSTALL) $(wildcard *.8) $(DESTDIR)$(MANDIR)/man8/
208 include ../common.mak
209 diff -urN -x .svn hotplug2-0.9/examples/Makefile hotplug2/examples/Makefile
210 --- hotplug2-0.9/examples/Makefile 2006-09-26 01:03:08.000000000 +0200
211 +++ hotplug2/examples/Makefile 2007-06-25 10:51:14.685225872 +0200
217 +KERNELVER=`uname -r`
223 - case "`uname -r`" in \
225 - $(INSTALL) hotplug2.rules-2.6kernel /etc/hotplug2.rules \
228 - $(INSTALL) hotplug2.rules-2.4kernel /etc/hotplug2.rules \
231 + if ! [ -e "/etc/hotplug2.rules" ]; then \
232 + case "$(KERNELVER)" in \
234 + $(INSTALL) hotplug2.rules-2.6kernel $(DESTDIR)/etc/hotplug2.rules \
237 + $(INSTALL) hotplug2.rules-2.4kernel $(DESTDIR)/etc/hotplug2.rules \
243 include ../common.mak
244 diff -urN -x .svn hotplug2-0.9/hotplug2.c hotplug2/hotplug2.c
245 --- hotplug2-0.9/hotplug2.c 2006-10-08 15:18:23.000000000 +0200
246 +++ hotplug2/hotplug2.c 2007-06-25 10:51:14.688225416 +0200
250 char *coldplug_command = NULL;
251 + char *rules_file = HOTPLUG2_RULE_PATH;
254 struct rules_t *rules = NULL;
255 @@ -435,15 +436,31 @@
258 modprobe_command = *argv;
259 + } else if (!strcmp(*argv, "--set-rules-file")) {
265 + rules_file = *argv;
274 + * We don't use rules, so we use dumb mode only.
279 + * We're not in dumb mode, parse the rules. If we fail,
280 + * faillback to dumb mode.
283 filemap = MAP_FAILED;
284 - rule_fd = open(HOTPLUG2_RULE_PATH, O_RDONLY | O_NOATIME);
285 + rule_fd = open(rules_file, O_RDONLY | O_NOATIME);
288 ERROR("rules parse","Unable to open rules file: %s.", strerror(errno));
289 @@ -477,10 +494,12 @@
292 ERROR("rules parse","Parsing rules failed, switching to dumb mode.");
293 - } else if (!modprobe_command)
295 - if (dumb && !modprobe_command)
299 + * No modprobe command specified, let's autodetect it.
301 + if (!modprobe_command)
303 if (get_modprobe_command()) {
304 ERROR("modprobe_command","Unable to autodetect modprobe command.");
307 modalias = get_hotplug2_value_by_key(tmpevent, "MODALIAS");
308 seqnum = get_hotplug2_value_by_key(tmpevent, "SEQNUM");
311 if (seqnum == NULL) {
312 free_hotplug2_event(tmpevent);
313 ERROR("reading events", "Malformed event read (missing SEQNUM).");
315 if (cur_seqnum > highest_seqnum)
316 highest_seqnum = cur_seqnum;
318 - if (tmpevent->action == ACTION_ADD && (!dumb || modalias != NULL)) {
319 + if ((dumb && tmpevent->action == ACTION_ADD && modalias != NULL) || (!dumb)) {
321 * We have more children than we want. Wait until SIGCHLD handler reduces
324 sigprocmask(SIG_UNBLOCK, &block_mask, 0);
325 signal(SIGCHLD, SIG_DFL);
326 signal(SIGUSR1, SIG_DFL);
329 perform_action(dup_hotplug2_event(tmpevent), rules);
332 perform_dumb_action(dup_hotplug2_event(tmpevent), modalias);
335 @@ -593,12 +610,10 @@
336 signal(SIGINT, SIG_DFL);
337 signal(SIGCHLD, SIG_DFL);
348 diff -urN -x .svn hotplug2-0.9/linux24_compat/hotplug2-modwrap.c hotplug2/linux24_compat/hotplug2-modwrap.c
349 --- hotplug2-0.9/linux24_compat/hotplug2-modwrap.c 2006-09-25 22:23:07.000000000 +0200
350 +++ hotplug2/linux24_compat/hotplug2-modwrap.c 2007-06-25 10:51:14.601238640 +0200
356 + if (strcmp(argv[argc - 1], match_alias) == 0) {
357 + if (execute(argv)) {
358 + ERROR("execute", "Unable to execute: `%s'.", argv[0]);
364 diff -urN -x .svn hotplug2-0.9/linux24_compat/Makefile hotplug2/linux24_compat/Makefile
365 --- hotplug2-0.9/linux24_compat/Makefile 2006-09-26 00:26:46.000000000 +0200
366 +++ hotplug2/linux24_compat/Makefile 2007-06-25 10:51:14.601238640 +0200
369 BINS=generate_alias hotplug2-coldplug-2.4 hotplug2-modwrap
377 - $(INSTALL_BIN) hotplug2-coldplug-2.4 hotplug2-modwrap /sbin/
378 - $(INSTALL_BIN) generate_alias /usr/sbin/
379 + $(INSTALL_BIN) hotplug2-coldplug-2.4 hotplug2-modwrap $(DESTDIR)/sbin/
380 + $(INSTALL_BIN) generate_alias $(DESTDIR)/usr/sbin/
383 hotplug2-coldplug-2.4: hotplug2-coldplug-2.4.o ../parser_utils.o ../filemap_utils.o ../mem_utils.o
384 diff -urN -x .svn hotplug2-0.9/Makefile hotplug2/Makefile
385 --- hotplug2-0.9/Makefile 2006-09-26 01:03:08.000000000 +0200
386 +++ hotplug2/Makefile 2007-06-25 10:51:14.693224656 +0200
389 BINS=hotplug2 hotplug2-dnode
390 SUBDIRS=linux24_compat docs examples
397 - $(INSTALL_BIN) $(BINS) /sbin/
398 + $(INSTALL_BIN) $(BINS) $(DESTDIR)/sbin/
401 hotplug2: hotplug2.o childlist.o mem_utils.o rules.o
402 diff -urN -x .svn hotplug2-0.9/rules.c hotplug2/rules.c
403 --- hotplug2-0.9/rules.c 2006-09-29 22:19:31.000000000 +0200
404 +++ hotplug2/rules.c 2007-06-25 10:51:14.692224808 +0200
409 +static void rmdir_p(char *path) {
412 + path = strdup(path);
414 + while (ptr != NULL) {
415 + ptr = strrchr(path, '/');
427 static char *replace_str(char *hay, char *needle, char *replacement) {
428 char *ptr, *start, *bptr, *buf;
430 @@ -250,11 +268,30 @@
434 -static int chown_chgrp(int action, char *file, char *param) {
435 +static int chmod_file(struct hotplug2_event_t *event, char *file, char *value) {
438 + file = replace_key_by_value(strdup(file), event);
439 + value = replace_key_by_value(strdup(value), event);
441 + rv = chmod(file, strtoul(value, 0, 8));
449 +static int chown_chgrp(struct hotplug2_event_t *event, int action, char *file, char *param) {
455 + file = replace_key_by_value(strdup(file), event);
456 + param = replace_key_by_value(strdup(param), event);
462 pwd = getpwnam(param);
464 rv = chown(file, -1, grp->gr_gid);
475 +static int print_debug(struct hotplug2_event_t *event) {
478 + for (i = 0; i < event->env_vars_c; i++)
479 + printf("%s=%s\n", event->env_vars[i].key, event->env_vars[i].value);
484 static int rule_condition_eval(struct hotplug2_event_t *event, struct condition_t *condition) {
485 @@ -347,11 +396,11 @@
486 last_rv = make_dev_from_event(event, rule->actions[i].parameter[0], strtoul(rule->actions[i].parameter[1], NULL, 0));
489 - last_rv = chmod(rule->actions[i].parameter[0], strtoul(rule->actions[i].parameter[1], NULL, 0));
490 + last_rv = chmod_file(event, rule->actions[i].parameter[0], rule->actions[i].parameter[1]);
494 - last_rv = chown_chgrp(rule->actions[i].type, rule->actions[i].parameter[0], rule->actions[i].parameter[1]);
495 + last_rv = chown_chgrp(event, rule->actions[i].type, rule->actions[i].parameter[0], rule->actions[i].parameter[1]);
498 last_rv = make_symlink(event, rule->actions[i].parameter[0], rule->actions[i].parameter[1]);
501 last_rv = setenv(rule->actions[i].parameter[0], rule->actions[i].parameter[1], 1);
504 + last_rv = unlink(rule->actions[i].parameter[0]);
505 + rmdir_p(rule->actions[i].parameter[0]);
508 + last_rv = print_debug(event);
514 {"chmod", 2, ACT_CHMOD},
515 {"chgrp", 2, ACT_CHGRP},
516 {"setenv", 2, ACT_SETENV},
517 + {"remove", 1, ACT_REMOVE},
518 + {"printdebug", 0, ACT_DEBUG},
520 {"symlink", 2, ACT_SYMLINK},
521 {"softlink", 2, ACT_SYMLINK},
522 diff -urN -x .svn hotplug2-0.9/rules.h hotplug2/rules.h
523 --- hotplug2-0.9/rules.h 2006-09-25 13:42:22.000000000 +0200
524 +++ hotplug2/rules.h 2007-06-25 10:51:14.687225568 +0200
526 #define ACT_CHGRP 6 /* chgrp <...> */
527 #define ACT_CHOWN 7 /* chown <...> */
528 #define ACT_SYMLINK 8 /* symlink <...> */
529 -#define ACT_NEXT_EVENT 9 /* next */
530 +#define ACT_NEXT_EVENT 9 /* next */
531 #define ACT_NEXT_IF_FAILED 10 /* next_if_failed */
532 #define ACT_SETENV 11 /* setenv <...> */
533 +#define ACT_REMOVE 12 /* remove <...> */
534 +#define ACT_DEBUG 13 /* debug */
537 #define EVAL_NOT_MATCH 0
538 diff -urN -x .svn hotplug2-0.9/TODO hotplug2/TODO
539 --- hotplug2-0.9/TODO 1970-01-01 01:00:00.000000000 +0100
540 +++ hotplug2/TODO 2007-06-25 10:51:14.691224960 +0200
542 + - live rules update (via inotify)