linux usb connect/disconnect event

后端 未结 3 1794
滥情空心
滥情空心 2021-02-02 01:53

Hello I am working on an embedded linux device with a usb port that uses the g_ether driver for usb networking.

When the usb plug is connected the dmesg output is:

3条回答
  •  悲&欢浪女
    2021-02-02 02:07

    You can use libudev or parse udevadm output as @Ambroz Bizjak suggested. Although, I advise against adding an additional process (stdbuf) and language (NCD), just to parse udevadm's output.

    A step between plain libudev and parsing output is modifying the udevadm sources. This solution reduces the needed resources and skips the parsing process altogether. When you look at the udev package, you will find the sources for udevd and udevadm in the udev directory.

    There, you have the main routine in udevadm.c and the source for udevadm monitor in udevadm-monitor.c. Every event received will be printed through print_device(). This is where you insert your code.

    If you're tight on memory, you can strip off unneeded code for control, info, settle, test-builtin, test and trigger. On my system (Ubuntu 12.04), this reduces the size of udevadm by about 75%.

提交回复
热议问题