ab6bbc2423b2023defa271ba4eae4cadf96e68cf
[openwrt/svn-archive/archive.git] / package / hotplug2 / patches / 100-svn_update.patch
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
4 @@ -1,7 +1,11 @@
5 Authors:
6 ----------
7 iSteve <isteve@bofh.cz>
8 -Tomas Janousek <tomi@nomi.cz>
9 +
10 + Contributions:
11 +----------------
12 +nbd (rules override patch)
13 +Tomas Janousek <tomi@nomi.cz> (Makefiles, SVN hosting)
14
15 Thanks to:
16 ------------
17 @@ -10,5 +14,9 @@
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)
25
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
32 @@ -1,3 +1,10 @@
33 +0.9 - 1.0:
34 +* Add --set-rules-file.
35 +* Allow any ACTION.
36 +* Add 'printdebug' rule.
37 +* Fix chmod, chown, chgrp.
38 +* Use octal for chmod and makedev.
39 +
40 0.8 - 0.9:
41 * Use signals to handle children.
42 * Separate info and debugging output.
43 @@ -44,4 +51,4 @@
44 * Add more actions.
45 * Significant cleanup of rules handling.
46 * Better error reporting.
47 -
48 \ No newline at end of file
49 +
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
53 @@ -31,6 +31,8 @@
54 .TP
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.
59 .SH "SIGNALS"
60 .TP
61 \fBSIGUSR1\fR
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
65 @@ -11,12 +11,12 @@
66 [... [...]]
67 }
68
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
71 -supported.
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
74 +are not supported.
75
76 -The <key> is one of the environmental variables that have been obtained by the
77 -uevent netlink.
78 +The <key> is one of the environmental variables that have been obtained by
79 +the uevent netlink.
80
81 COMMON KEYS
82 -----------
83 @@ -66,9 +66,9 @@
84 -------
85
86 * run <...>
87 - Execute an application using system();, takes one parameter. Note that
88 - the application has set all environmental variables read by uevent
89 - netlink.
90 + Execute an application using system();, takes one parameter. Note
91 + that the application has set all environmental variables read by
92 + uevent netlink.
93
94 * break
95 Break the processing of the current block of actions.
96 @@ -86,23 +86,22 @@
97
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.
104
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.
109
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.
114
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
117 function.
118
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.
124
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.
129
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.
134
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.
138 +
139 + * printdebug
140 + Prints all variables read from kernel.
141
142 ESCAPING
143 --------
144 @@ -136,8 +137,9 @@
145 SAMPLE CONFIG
146 -------------
147
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 ---------------------------------------------------------------------------------
154 MODALIAS is set {
155 exec modprobe -q %MODALIAS% ;
156 @@ -146,3 +148,33 @@
157 SUBSYSTEM == block, DEVPATH is set, MAJOR is set, MINOR is set {
158 makedev /dev/%DEVICENAME% 0644
159 }
160 +
161 +
162 +Please find also the more complex set of rules, dedicated to handling most
163 +common needs.
164 +---------------------------------------------------------------------------------
165 +#For debugging
166 +#ACTION is set {
167 +# printdebug
168 +#}
169 +
170 +# Load modules (what old hotplug did)
171 +MODALIAS is set {
172 + exec modprobe -q %MODALIAS% ;
173 +}
174 +
175 +# Create device nodes
176 +DEVPATH is set, MAJOR is set, MINOR is set {
177 + makedev /dev/%DEVICENAME% 0644
178 +}
179 +
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%
184 +}
185 +
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%
189 +}
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
193 @@ -2,12 +2,13 @@
194
195 BINS=
196 SUBDIRS=
197 -
198 +DESTDIR=
199 +MANDIR=/usr/share/man
200
201 all:
202
203 install:
204 - $(INSTALL) $(wildcard *.8) /usr/share/man/man8/
205 + $(INSTALL) $(wildcard *.8) $(DESTDIR)$(MANDIR)/man8/
206
207
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
212 @@ -2,19 +2,23 @@
213
214 BINS=
215 SUBDIRS=
216 +DESTDIR=
217 +KERNELVER=`uname -r`
218
219
220 all:
221
222 install:
223 - case "`uname -r`" in \
224 - 2.6.*) \
225 - $(INSTALL) hotplug2.rules-2.6kernel /etc/hotplug2.rules \
226 - ;; \
227 - *) \
228 - $(INSTALL) hotplug2.rules-2.4kernel /etc/hotplug2.rules \
229 - ;; \
230 - esac
231 + if ! [ -e "/etc/hotplug2.rules" ]; then \
232 + case "$(KERNELVER)" in \
233 + 2.6.*) \
234 + $(INSTALL) hotplug2.rules-2.6kernel $(DESTDIR)/etc/hotplug2.rules \
235 + ;; \
236 + *) \
237 + $(INSTALL) hotplug2.rules-2.4kernel $(DESTDIR)/etc/hotplug2.rules \
238 + ;; \
239 + esac; \
240 + fi;
241
242
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
247 @@ -391,6 +391,7 @@
248 int rv = 0;
249 int i;
250 char *coldplug_command = NULL;
251 + char *rules_file = HOTPLUG2_RULE_PATH;
252 sigset_t block_mask;
253
254 struct rules_t *rules = NULL;
255 @@ -435,15 +436,31 @@
256 break;
257
258 modprobe_command = *argv;
259 + } else if (!strcmp(*argv, "--set-rules-file")) {
260 + argv++;
261 + argc--;
262 + if (argc <= 0)
263 + break;
264 +
265 + rules_file = *argv;
266 }
267 }
268 }
269 }
270
271 -#ifdef HAVE_RULES
272 +#ifndef HAVE_RULES
273 + /*
274 + * We don't use rules, so we use dumb mode only.
275 + */
276 + dumb = 1;
277 +#else
278 + /*
279 + * We're not in dumb mode, parse the rules. If we fail,
280 + * faillback to dumb mode.
281 + */
282 if (!dumb) {
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);
286 if (rule_fd == -1) {
287 dumb = 1;
288 ERROR("rules parse","Unable to open rules file: %s.", strerror(errno));
289 @@ -477,10 +494,12 @@
290
291 if (dumb == 1)
292 ERROR("rules parse","Parsing rules failed, switching to dumb mode.");
293 - } else if (!modprobe_command)
294 -#else
295 - if (dumb && !modprobe_command)
296 + } else
297 #endif
298 + /*
299 + * No modprobe command specified, let's autodetect it.
300 + */
301 + if (!modprobe_command)
302 {
303 if (get_modprobe_command()) {
304 ERROR("modprobe_command","Unable to autodetect modprobe command.");
305 @@ -536,7 +555,7 @@
306
307 modalias = get_hotplug2_value_by_key(tmpevent, "MODALIAS");
308 seqnum = get_hotplug2_value_by_key(tmpevent, "SEQNUM");
309 -
310 +
311 if (seqnum == NULL) {
312 free_hotplug2_event(tmpevent);
313 ERROR("reading events", "Malformed event read (missing SEQNUM).");
314 @@ -547,7 +566,7 @@
315 if (cur_seqnum > highest_seqnum)
316 highest_seqnum = cur_seqnum;
317
318 - if (tmpevent->action == ACTION_ADD && (!dumb || modalias != NULL)) {
319 + if ((dumb && tmpevent->action == ACTION_ADD && modalias != NULL) || (!dumb)) {
320 /*
321 * We have more children than we want. Wait until SIGCHLD handler reduces
322 * their numbers.
323 @@ -568,11 +587,9 @@
324 sigprocmask(SIG_UNBLOCK, &block_mask, 0);
325 signal(SIGCHLD, SIG_DFL);
326 signal(SIGUSR1, SIG_DFL);
327 -#ifdef HAVE_RULES
328 if (!dumb)
329 perform_action(dup_hotplug2_event(tmpevent), rules);
330 else
331 -#endif
332 perform_dumb_action(dup_hotplug2_event(tmpevent), modalias);
333 exit(0);
334 break;
335 @@ -593,12 +610,10 @@
336 signal(SIGINT, SIG_DFL);
337 signal(SIGCHLD, SIG_DFL);
338
339 -#ifdef HAVE_RULES
340 if (!dumb) {
341 rules_free(rules);
342 free(rules);
343 }
344 -#endif
345
346 cleanup();
347
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
351 @@ -122,6 +122,12 @@
352 free(module);
353 free(line);
354 }
355 +
356 + if (strcmp(argv[argc - 1], match_alias) == 0) {
357 + if (execute(argv)) {
358 + ERROR("execute", "Unable to execute: `%s'.", argv[0]);
359 + }
360 + }
361
362 free(filename);
363 free(match_alias);
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
367 @@ -2,13 +2,14 @@
368
369 BINS=generate_alias hotplug2-coldplug-2.4 hotplug2-modwrap
370 SUBDIRS=
371 +DESTDIR=
372
373
374 all: $(BINS)
375
376 install:
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/
381
382
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
387 @@ -2,12 +2,13 @@
388
389 BINS=hotplug2 hotplug2-dnode
390 SUBDIRS=linux24_compat docs examples
391 +DESTDIR=
392
393
394 all: $(BINS)
395
396 install:
397 - $(INSTALL_BIN) $(BINS) /sbin/
398 + $(INSTALL_BIN) $(BINS) $(DESTDIR)/sbin/
399
400
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
405 @@ -59,6 +59,24 @@
406 free(path);
407 }
408
409 +static void rmdir_p(char *path) {
410 + char *ptr;
411 +
412 + path = strdup(path);
413 + ptr = path;
414 + while (ptr != NULL) {
415 + ptr = strrchr(path, '/');
416 + if (ptr == NULL)
417 + break;
418 +
419 + *ptr = '\0';
420 +
421 + if (rmdir(path))
422 + break;
423 + }
424 + free(path);
425 +}
426 +
427 static char *replace_str(char *hay, char *needle, char *replacement) {
428 char *ptr, *start, *bptr, *buf;
429 int occurences, j;
430 @@ -250,11 +268,30 @@
431 return rv;
432 }
433
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) {
436 + int rv;
437 +
438 + file = replace_key_by_value(strdup(file), event);
439 + value = replace_key_by_value(strdup(value), event);
440 +
441 + rv = chmod(file, strtoul(value, 0, 8));
442 +
443 + free(file);
444 + free(value);
445 +
446 + return rv;
447 +}
448 +
449 +static int chown_chgrp(struct hotplug2_event_t *event, int action, char *file, char *param) {
450 struct group *grp;
451 struct passwd *pwd;
452 int rv;
453 -
454 +
455 + file = replace_key_by_value(strdup(file), event);
456 + param = replace_key_by_value(strdup(param), event);
457 +
458 + rv = -1;
459 +
460 switch (action) {
461 case ACT_CHOWN:
462 pwd = getpwnam(param);
463 @@ -265,8 +302,20 @@
464 rv = chown(file, -1, grp->gr_gid);
465 break;
466 }
467 +
468 + free(file);
469 + free(param);
470
471 - return -1;
472 + return rv;
473 +}
474 +
475 +static int print_debug(struct hotplug2_event_t *event) {
476 + int i;
477 +
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);
480 +
481 + return 0;
482 }
483
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));
487 break;
488 case ACT_CHMOD:
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]);
491 break;
492 case ACT_CHOWN:
493 case ACT_CHGRP:
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]);
496 break;
497 case ACT_SYMLINK:
498 last_rv = make_symlink(event, rule->actions[i].parameter[0], rule->actions[i].parameter[1]);
499 @@ -365,6 +414,13 @@
500 case ACT_SETENV:
501 last_rv = setenv(rule->actions[i].parameter[0], rule->actions[i].parameter[1], 1);
502 break;
503 + case ACT_REMOVE:
504 + last_rv = unlink(rule->actions[i].parameter[0]);
505 + rmdir_p(rule->actions[i].parameter[0]);
506 + break;
507 + case ACT_DEBUG:
508 + last_rv = print_debug(event);
509 + break;
510 }
511 }
512
513 @@ -518,6 +574,8 @@
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},
519 /*symlink*/
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
525 @@ -24,9 +24,11 @@
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 */
535
536 #define EVAL_MATCH 1
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
541 @@ -0,0 +1 @@
542 + - live rules update (via inotify)