Commit graph

2726 commits

Author SHA1 Message Date
Alan Jenkins d15fcce4b3 udevd: be more careful when matching against parents
I'm worried about what will happen with things like

KERNELS=="*" # pointless rule
KERNELS=="doesnt-match" # another pointless rule

Since TK_RULE < TK_M_PARENTS_MAX, we will try to match all three tokens
against parents of the current device.  I can't think of a bad case,
but it's not exactly good either.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-11-01 17:32:16 +01:00
Alan Jenkins 11ae757850 udevd: fix termination of rule execution
LAST_RULE was broken, and I broke TK_END by making it do the same.
It used a "break" which exited the switch statement, but not the loop!

==2953== Invalid read of size 4
==2953==    at 0x4081EE: dump_token (udev-rules.c:859)
==2953==    by 0x40BADB: udev_rules_apply_to_event (udev-rules.c:1849)
==2953==    by 0x403F17: udev_event_execute_rules (udev-event.c:554)
==2953==    by 0x418626: main (test-udev.c:100)
==2953==  Address 0x55ab1f8 is 0 bytes after a block of size 80 alloc'd
==2953==    at 0x4C23082: realloc (vg_replace_malloc.c:429)
==2953==    by 0x40B13B: udev_rules_new (udev-rules.c:1670)
==2953==    by 0x418536: main (test-udev.c:84)
...

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-11-01 17:29:26 +01:00
Kay Sievers 27691aa3ae write trace log to stderr 2008-10-31 16:22:55 +01:00
Kay Sievers bf18270222 fstab_import: add "change" event match 2008-10-30 16:41:47 +01:00
Kay Sievers 11ddcbf7b4 edd_id: add "change" event match 2008-10-30 16:41:27 +01:00
Kay Sievers 87fb336f39 rules: remove "add" match from usb device node rule 2008-10-30 16:11:49 +01:00
Kay Sievers ba6e84fe6a rules: remove SCSI timeouts
On Thu, Oct 30, 2008 at 03:55, Tejun Heo <tj@kernel.org> wrote:
The appropriate default timeout differs depending on the transport and
the type of the attached device, so the above two rules harm more than
help.  The affect of the above two rules weren't visible for some
reason but with recent block layer timeout update, they actually work
and cause problems.
2008-10-30 09:20:03 +01:00
Kay Sievers aeb53ca3d6 ATTR{}== always fails if the attribute does not exist 2008-10-29 22:22:12 +01:00
Kay Sievers 0bc74ea79f udevd: merge exec and run queue to minimize devpath string compares 2008-10-29 17:32:13 +01:00
Alan Jenkins 6270756cdc udevd: simplify rules execution loop
cur can't become NULL, and the check for TK_END
can be folded into the switch statement.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-28 10:02:43 +01:00
Kay Sievers 65807d09ec update NEWS 2008-10-28 02:26:35 +01:00
Alan Jenkins be7de4097a kerneldoc comment fixes
s/ressources/resources/

Also reduce commas per sentence and add a possessive apostrophe.
2008-10-26 15:55:47 +01:00
Kay Sievers 427e20b261 libudev: device - allocate envp array only once 2008-10-26 14:31:46 +01:00
Kay Sievers c6243a414e test: add RUN+="socket: ..." to a test to run monitor code 2008-10-26 04:35:32 +01:00
Kay Sievers 6493e655f7 libudev: device - fill envp array while composing monitor buffer
Thanks to Alan Jenkins, for the idea.
2008-10-26 03:39:41 +01:00
Kay Sievers dc4c7e463d fix $attr{[<subsystem>/<sysname>]<attribute>} substitution 2008-10-26 02:48:14 +01:00
Kay Sievers 1822e9b033 do not init string arrays, just clear first byte 2008-10-26 02:31:54 +01:00
Kay Sievers 21cfb0436c match_attr() - copy attr value only when needed 2008-10-26 02:16:54 +01:00
Alan Jenkins cd94c04c51 udevd: avoid implicit memset in match_attr()
Initializing a char array to "" is equivalent to a memset()
call - which is exactly what it gets compiled to.

Fixing this one callsite reduced memset() _user_ cpu cycles
from 2-4% to 0.05% on the EeePC.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-26 02:11:56 +01:00
Alan Jenkins e25fa4faf5 udevd: use a tighter loop for compare_devpath()
This crops up in my threaded udevd profiles from time to time.
It's not consistent - probably due to variations in the number
of concurrent events - but it can hit 4% user time and higher.

The change halves the user time spent in compare_devpath().

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-25 19:41:52 +02:00
Alan Jenkins 3e5c759543 fix handling of string_escape option 2008-10-25 15:19:48 +02:00
Kay Sievers 91a75e4ad4 match KEY="A|B" without temporary string copy 2008-10-25 03:00:03 +02:00
Kay Sievers b62557daff remove debug printf 2008-10-24 18:09:13 +02:00
Kay Sievers 39a08013a2 fix "unused" warnings 2008-10-24 17:42:31 +02:00
Kay Sievers c265440279 libudev: monitor - cache result of monitor send buffer 2008-10-24 16:36:27 +02:00
Kay Sievers 3c67f7d2df libudev: monitor - replace far too expensive snprintf() with strlcpy() 2008-10-24 15:09:43 +02:00
Kay Sievers db463fd309 special-case "?*" match to skip fnmatch() 2008-10-24 14:19:42 +02:00
Kay Sievers ac218d9cc8 determine at rule parse time if we need to call fnmatch()
This cuts down the large rule set's 120.000 calls to fnmatch() to
51.000, and we can just call strcmp for the simple matches.
2008-10-24 13:32:32 +02:00
Kay Sievers b0f7409f24 distinguish "match" from "assign" by (op < OP_MATCH_MAX) 2008-10-24 11:38:05 +02:00
Kay Sievers 154a7b8428 cache uid/gid during rule parsing
This cuts down the number of parsing /etc/group from ~700 to 11,
with some large rule files installed.
2008-10-24 10:51:04 +02:00
Kay Sievers f6bb9e981a fix uninitialized variable warnings 2008-10-24 09:37:37 +02:00
Kay Sievers 34d6a259dc rules: let empty strings added to buffer always return offset 0 2008-10-24 08:07:37 +02:00
Kay Sievers 548459e939 skip SYMLINK rules for devices without a device node 2008-10-23 21:42:23 +02:00
Alan Jenkins 7aeeaedc5f udevd: fix WAIT_FOR_SYSFS execution order
The wait should be ordered after matching KERNEL, ENV, etc.
but before ATTR.

Without this, WAIT_FOR_SYSFS rules will be applied unconditionally
to all events.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-23 20:59:17 +02:00
Kay Sievers 9bdca442ef rule_generator: fix netif NAME= value extraction regex
$ sed -n -r \
    -e 's/^#.*//' \
    -e 's/[[:space:],]NAME="(eth[0-9]*)"[[:space:]]*(,.*|\\|)$/\1/p' \
    /dev/null /etc/udev/rules.d/70-persistent-net.rules
  SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:16:41:e2:8d:c7", ATTR{type}=="1", KERNEL=="eth*",eth4

  $ sed -n -r \
    -e 's/^#.*//' \
    -e 's/.*[[:space:],]NAME="(eth[0-9]*)".*/\1/p' \
    /dev/null /etc/udev/rules.d/70-persistent-net.rules
  eth4
2008-10-23 15:44:34 +02:00
Alan Jenkins 84629ccd85 udevd: fix memory leak
Re: b99028c963 shrink struct udev_event

TEST 136: test multi matches 2
device '/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0' expecting node 'right'
==15011==
==15011== 7 bytes in 1 blocks are definitely lost in loss record 1 of 1
==15011==    at 0x47F9AB8: malloc (vg_replace_malloc.c:207)
==15011==    by 0x489CB5F: strdup (in /lib32/libc-2.7.so)
==15011==    by 0x8050F40: udev_rules_apply_to_event (udev-rules.c:1973)
==15011==    by 0x804A658: udev_event_execute_rules (udev-event.c:549)
==15011==    by 0x805A636: main (test-udev.c:100)
add:         ok
==15012==
==15012== 7 bytes in 1 blocks are definitely lost in loss record 1 of 1
==15012==    at 0x47F1AB8: malloc (vg_replace_malloc.c:207)
==15012==    by 0x4898B5F: strdup (in /lib32/libc-2.7.so)
==15012==    by 0x8050F40: udev_rules_apply_to_event (udev-rules.c:1973)
==15012==    by 0x804A9DF: udev_event_execute_rules (udev-event.c:658)
==15012==    by 0x805A636: main (test-udev.c:100)
remove:      ok

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-23 11:33:22 +02:00
Kay Sievers b99028c963 shrink struct udev_event 2008-10-23 02:57:08 +02:00
Kay Sievers 40fd3bc837 shrink struct udev_event 2008-10-23 02:34:22 +02:00
Kay Sievers 5a05e120af do not create temporary node ($tempnode) if node already exists 2008-10-23 01:13:52 +02:00
Kay Sievers 6880b25d40 replace in-memory rules array with match/action token list
The in-memory rule array of a common desktop distro install took:
  1151088 bytes
with the token list:
  109232 bytes tokens (6827 * 16 bytes), 71302 bytes buffer
2008-10-23 00:13:59 +02:00
Kay Sievers a391f49d7f handle numerical owner/group string in lookup_user/group() 2008-10-22 23:59:53 +02:00
Alan Jenkins aaff3d023f use re-entrant variants of getpwnam and getgrnam
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-22 18:05:46 +02:00
Kay Sievers 14f4025607 add util_resolve_subsys_kernel() 2008-10-22 18:03:38 +02:00
Matthias Koenig fcd070d010 volume_id: swap - larger PAGE_SIZE support 2008-10-22 11:45:27 +02:00
Alan Jenkins 111e4f81ff replace strncpy() with strlcpy()
The problem was strncpy() doesn't stop after writing the terminating
NUL; by definition it goes on to zero the entire buffer.

I spy another use of strncpy in udev_device_add_property_from_string(),
which is responsible for another ~1% user cpu time...

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-21 23:55:13 +02:00
Kay Sievers 9a23e9e775 libudev: device - 128 -> ENVP_SIZE 2008-10-21 13:58:19 +02:00
Alan Jenkins be18918f65 libudev: allocate udev_device->envp[] dynamically
Measured 2% _user_ cpu time reduction on EeePC coldplug.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-21 13:56:23 +02:00
Alan Jenkins fa0e955a93 libudev: util - optimize path_encode()
Since we already know the length, use memcpy() instead.
Measured 2% _user_ cpu time reduction on EeePC coldplug.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-21 13:09:31 +02:00
Alan Jenkins b29a5e4ab9 use more appropriate alternatives to malloc()
Use calloc to request cleared memory instead.
Kernel and libc conspire to make this more efficient.

Also, replace one malloc() + strcpy() with strdup().

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
2008-10-21 12:54:57 +02:00
Kay Sievers a8a8930072 do not use the new work-in-progress parser rule matcher 2008-10-21 12:45:54 +02:00