| 1 | BEGIN { |
| 2 | Re_Begin = "^UDEV + \[ *[0-9]+\.[0-9]+\] +" |
| 3 | } |
| 4 | |
| 5 | ($0 ~ Re_Begin) { |
| 6 | handle_event($0) |
| 7 | next |
| 8 | } |
| 9 | |
| 10 | function handle_event(payload, payload_parts, event, |
| 11 | path, n_path_parts, |
| 12 | devname \ |
| 13 | ) { |
| 14 | sub(Re_Begin, "", payload) |
| 15 | split(payload, payload_parts, " +") |
| 16 | event = payload_parts[1] |
| 17 | path = payload_parts[2] |
| 18 | if (event == "add" || event == "change") { |
| 19 | devname = devname_lookup(path) |
| 20 | } else { |
| 21 | n_path_parts = split(path, path_parts, "/") |
| 22 | devname = path_parts[n_path_parts] |
| 23 | } |
| 24 | print(event, devname) |
| 25 | } |
| 26 | |
| 27 | function devname_lookup(path, cmd, line_parts, devname) { |
| 28 | cmd = "udevadm info --path=" path |
| 29 | while (cmd | getline line) { |
| 30 | if (line ~ /^E: +DEVNAME/) { |
| 31 | split(line, line_parts, "=") |
| 32 | devname = line_parts[2] |
| 33 | break |
| 34 | } |
| 35 | } |
| 36 | close(cmd) |
| 37 | return devname |
| 38 | } |