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