Move SUBSYSTEM and DEVPATH to record fields

These attributes seem to always be present so don't label them.
This commit is contained in:
Emery Hemingway 2023-07-04 13:17:03 +01:00
parent 9906654543
commit 4512b33fa9
4 changed files with 33 additions and 22 deletions

View File

@ -28,9 +28,8 @@ Example Syndicate server configuration:
Example message stream: Example message stream:
``` ```
<uevent 32663 add {DEVNAME: "input/event23", DEVPATH: "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.4/0003:1D50:6122.0026/input/input47/event23", MAJOR: "13", MINOR: "87", SUBSYSTEM: "input"}> <uevent "power_supply" "/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:18/PNP0C09:01/PNP0C0A:03/power_supply/BAT0" change {POWER_SUPPLY_CAPACITY: 98, POWER_SUPPLY_CAPACITY_LEVEL: "Normal", POWER_SUPPLY_CYCLE_COUNT: 236, POWER_SUPPLY_ENERGY_FULL: 44672000, POWER_SUPPLY_ENERGY_FULL_DESIGN: 50464000, POWER_SUPPLY_ENERGY_NOW: 43821000, POWER_SUPPLY_MANUFACTURER: "ASUSTeK", POWER_SUPPLY_MODEL_NAME: "ASUS Battery", POWER_SUPPLY_NAME: "BAT0", POWER_SUPPLY_POWER_NOW: 7691000, POWER_SUPPLY_PRESENT: 1, POWER_SUPPLY_SERIAL_NUMBER: " ", POWER_SUPPLY_STATUS: "Charging", POWER_SUPPLY_TECHNOLOGY: "Li-ion", POWER_SUPPLY_TYPE: "Battery", POWER_SUPPLY_VOLTAGE_MIN_DESIGN: 15200000, POWER_SUPPLY_VOLTAGE_NOW: 15200000} 3916>
<uevent 32664 add {DEVNAME: "input/mouse5", DEVPATH: "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.4/0003:1D50:6122.0026/input/input47/mouse5", MAJOR: "13", MINOR: "37", SUBSYSTEM: "input"}> ,uevent "hidraw" "/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:248A:5B2F.0011/hidraw/hidraw2" add {DEVNAME: "hidraw2", MAJOR: 247, MINOR: 2} 3980>
<uevent 32665 add {DEVNAME: "hidraw10", DEVPATH: "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.4/0003:1D50:6122.0026/hidraw/hidraw10", MAJOR: "247", MINOR: "10", SUBSYSTEM: "hidraw"}> <uevent "hid" "/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:248A:5B2F.0011" bind {DRIVER: "hid-generic", HID_ID: "0003:0000248A:00005B2F", HID_NAME: "XCTECH Ninjutso Katana Superlight", HID_PHYS: "usb-0000:00:14.0-2/input2", HID_UNIQ: 0, MODALIAS: "hid:b0003g0001v0000248Ap00005B2F"} 3981>
<uevent 32666 bind {DEVPATH: "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.4/0003:1D50:6122.0026", DRIVER: "hid-generic", HID_ID: "0003:00001D50:00006122", HID_NAME: "Ultimate Gadget Laboratories Ultimate Hacking Keyboard", HID_PHYS: "usb-0000:00:14.0-3/input4", HID_UNIQ: "", MODALIAS: "hid:b0003g0001v00001D50p00006122", SUBSYSTEM: "hid"}> <uevent "usb" "/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2" bind {DEVTYPE: "usb_interface", DRIVER: "usbhid", INTERFACE: "3/0/0", MODALIAS: "usb:v248Ap5B2Fd0116dc00dsc00dp00ic03isc00ip00in02", PRODUCT: "248a/5b2f/116", TYPE: "0/0/0"} 3982>
<uevent 32667 bind {DEVPATH: "/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.4", DEVTYPE: "usb_interface", DRIVER: "usbhid", INTERFACE: "3/1/2", MODALIAS: "usb:v1D50p6122d0101dc00dsc00dp00ic03isc01ip02in04", PRODUCT: "1d50/6122/101", SUBSYSTEM: "usb", TYPE: "0/0/0"}>
``` ```

View File

@ -41,7 +41,7 @@ proc openUeventSocket: AsyncSocket =
proc main(facet: Facet; ds: Ref; sock: AsyncSocket) = proc main(facet: Facet; ds: Ref; sock: AsyncSocket) =
var var
buf = newString(1 shl 14) buf = newString(1 shl 14)
msg = initRecord("uevent", 0.toPreserve, "".toSymbol, initDictionary()) msg = initRecord("uevent", "".toPreserve, "".toPreserve, "".toSymbol, initDictionary(), 0.toPreserve)
key, val: string key, val: string
proc recvUevent {.gcsafe.} = proc recvUevent {.gcsafe.} =
let fut = recvInto(sock, buf[0].addr, buf.len) let fut = recvInto(sock, buf[0].addr, buf.len)
@ -55,22 +55,34 @@ proc main(facet: Facet; ds: Ref; sock: AsyncSocket) =
inc i, skipWhile(buf, {'\0'}, i) inc i, skipWhile(buf, {'\0'}, i)
inc i, parseUntil(buf, key, {'=', '@'}, i) inc i, parseUntil(buf, key, {'=', '@'}, i)
if i < n: if i < n:
if buf[i] == '@': let sep = buf[i]
if msg.record[2].dict.len > 0: inc i, parseUntil(buf, val, '\0', i+1)+1
cannonicalize(msg.record[1]) case sep
of '@':
if msg.record[3].dict.len > 0:
cannonicalize(msg.record[3])
message(turn, ds, msg) message(turn, ds, msg)
msg.record[2].dict.setLen(0) msg.record[3].dict.setLen(0)
inc i, parseUntil(buf, val, '\0', i+1)+1 of '=':
elif key == "SEQNUM": if key == "SUBSYSTEM":
var seqnum: int msg.record[0].string = val
inc i, parseInt(buf, seqnum, i+1)+1 elif key == "DEVPATH":
msg.record[0].int = seqnum.BiggestInt msg.record[1].string = val
else: elif key == "ACTION":
inc i, parseUntil(buf, val, '\0', i+1)+1 msg.record[2].symbol = Symbol val
if key == "ACTION": elif key == "SEQNUM":
msg.record[1].symbol = Symbol val discard parseBiggestInt(val, msg.record[4].int)
else: else:
add(msg.record[2].dict, (key.toSymbol, val.toPreserve,)) # TODO: check if val can be an integer
var num: BiggestInt
if parseBiggestInt(val, num) == val.len:
add(msg.record[3].dict, (key.toSymbol, num.toPreserve,))
else:
add(msg.record[3].dict, (key.toSymbol, val.toPreserve,))
val.setLen(0)
else:
stderr.writeLine "uevent parser synchronization lost"
break
recvUevent() recvUevent()
recvUevent() recvUevent()

View File

@ -1,6 +1,6 @@
# Package # Package
version = "20230702" version = "20230704"
author = "Emery Hemingway" author = "Emery Hemingway"
description = "Syndicated actor for publishing Linux device events" description = "Syndicated actor for publishing Linux device events"
license = "Unlicense" license = "Unlicense"

View File

@ -1,3 +1,3 @@
version 1. version 1.
Uevent = <uvent @seqnum int @action string @attrs {symbol: string ...:...}> . Uevent = <uvent @subsystem string @devpath string @action string @attrs {symbol: string ...:...} @seqnum int> .