summaryrefslogtreecommitdiff
path: root/barcode_scanner_daemon.py
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-10-15 12:48:30 +0200
committerxengineering <mail2xengineering@protonmail.com>2020-10-15 12:48:30 +0200
commit3f739baab456c2cc977f11090381d1f61eb023c4 (patch)
treea35293cd7a0164601213bdfbd10774a1e998ebc1 /barcode_scanner_daemon.py
parent449b490f233371fe28e9089a05982cd5634285d2 (diff)
downloadiot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.tar
iot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.tar.zst
iot-barcode-scanner-3f739baab456c2cc977f11090381d1f61eb023c4.zip
Split Executable to reduce root-priviledged Code Execution
Diffstat (limited to 'barcode_scanner_daemon.py')
-rwxr-xr-xbarcode_scanner_daemon.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/barcode_scanner_daemon.py b/barcode_scanner_daemon.py
new file mode 100755
index 0000000..38f0514
--- /dev/null
+++ b/barcode_scanner_daemon.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python3
+
+
+"""Executable to read the Key Events from the Barcode Scanner (root Priviledges necessary)"""
+
+
+import evdev
+import os
+
+import iot_barcode_scanner.config as config
+
+
+def main():
+
+ try:
+ # read config
+ cfg = config.get_config()
+ fifo_path = cfg["scanner"]["fifo_path"]
+ event_device_path = cfg["scanner"]["evdev_path"]
+
+ # prepare fifo
+ os.makedirs(os.path.dirname(fifo_path), exist_ok=True)
+ os.mkfifo(fifo_path)
+
+ barcode_scanner = evdev.InputDevice(event_device_path)
+ with barcode_scanner.grab_context():
+ for event in barcode_scanner.read_loop():
+ if event.type == evdev.ecodes.EV_KEY:
+ eventdata = evdev.categorize(event)
+ if eventdata.keystate:
+ with open(fifo_path, "a") as fifo:
+ fifo.append(eventdata.keycode)
+
+ except KeyboardInterrupt:
+ pass
+
+ finally:
+ os.remove(fifo_path)
+
+
+if __name__ == "__main__":
+ main()