Skip to content

Simple example about systemd (sd-event & sd-device) to monitor USB devices on connection

License

Notifications You must be signed in to change notification settings

carvilsi/systemd-usb-monitor-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

systemd USB monitor example

Simple example about systemd (sd-event & sd-device) to monitor USB devices on connection

Compile and Run

Compile with gcc:

gcc usb_sd_device_monitor.c -o usbthingy `pkg-config --libs --cflags libsystemd`

And run it:

./usbthingy

Note: It's quite possible that on Ubuntu you'll need to install the libsystem-dev package. At least was my case for Ubuntu 23.04 (lunar)

sudo apt install libsystemd-dev

Seems that on Arch Linux is already installed.

Example of output

This is the output that I get when I connect my Zowie mouse:

syspath: /sys/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.3
devtype: usb_device
subsystem: usb
first_sysattr: idProduct
first_tag: seat
id_vendor: 1af3
id_product: 0001
product: ZOWIE Gaming mouse

I will appreciate any comment, suggestions or improvement from you; Also if you like it please leave a ⭐ ;)

About

Simple example about systemd (sd-event & sd-device) to monitor USB devices on connection

Topics

Resources

License

Stars

Watchers

Forks

Languages