使用 SynCE 将 PDA 设备与 Debian 连接,USB 串行设备被识别并连接到 ttyUSB 总线,获取 IP 地址并在几秒钟后断开连接(两秒,最多三秒)。它在系统日志中的样子如下:
Jan 18 20:26:57 debian10 dccm[1505]: Message: synce_device_dbus_init: registering object path '/org/synce/dccm/Device/_devices_pci0000_00_0000_00_06_0_usb2_2_2_2_2_1_0_ttyUSB0_tty_ttyUSB0'
Jan 18 20:26:57 debian10 dccm[1505]: DEBUG: synce_device_manager_device_obj_path_changed_cb: sending connected signal for /org/synce/dccm/Device/_devices_pci0000_00_0000_00_06_0_usb2_2_2_2_2_1_0_ttyUSB0_tty_ttyUSB0
Jan 18 20:26:57 debian10 dccm[1505]: DEBUG: synce_device_dbus_init: obj_path set to /org/synce/dccm/Device/_devices_pci0000_00_0000_00_06_0_usb2_2_2_2_2_1_0_ttyUSB0_tty_ttyUSB0
Jan 18 20:26:57 debian10 dccm[1505]: DEBUG: get_password_flag_text: setting password flags unset
Jan 18 20:26:57 debian10 dccm[1505]: DEBUG: synce_device_legacy_info_received: setting CTRL_STATE_CONNECTED
Jan 18 20:26:58 debian10 dccm[1505]: DEBUG: gudev_uevent_callback: received uevent **remove** for device /sys/devices/virtual/net/ppp0/queues/tx-0
Jan 18 20:26:58 debian10 dccm[1505]: DEBUG: gudev_uevent_callback: received uevent **remove** for device /sys/devices/virtual/net/ppp0/queues/rx-0
Jan 18 20:26:58 debian10 dccm[1505]: DEBUG: gudev_uevent_callback: received uevent **remove** for device /sys/devices/virtual/net/ppp0
看到输出后,我决定深入研究使用“udevadm control -l debug”监控 UDEV 事件......结果如下:
Jan 23 15:01:28 debian10 dccm[1157]: DEBUG: get_password_flag_text: setting password flags unset
Jan 23 15:01:30 debian10 systemd-udevd[237]: Cleanup idle workers
Jan 23 15:01:30 debian10 systemd-udevd[1322]: Unload module index
Jan 23 15:01:30 debian10 systemd-udevd[1322]: Unloaded link configuration context.
Jan 23 15:01:30 debian10 systemd-udevd[1299]: Unload module index
Jan 23 15:01:30 debian10 systemd-udevd[1299]: Unloaded link configuration context.
Jan 23 15:01:30 debian10 systemd-udevd[237]: Worker [1299] exited
Jan 23 15:01:30 debian10 systemd-udevd[237]: Worker [1322] exited
Jan 23 15:01:30 debian10 systemd-udevd[237]: rx-0: Device (SEQNUM=1738, ACTION=remove) is queued
Jan 23 15:01:30 debian10 systemd-udevd[237]: Validate module index
Jan 23 15:01:30 debian10 systemd-udevd[237]: Check if link configuration needs reloading.
Jan 23 15:01:30 debian10 systemd-udevd[237]: Successfully forked off 'n/a' as PID 1327.
Jan 23 15:01:30 debian10 systemd-udevd[237]: rx-0: Worker [1327] is forked for processing SEQNUM=1738.
Jan 23 15:01:30 debian10 systemd-udevd[237]: tx-0: Device (SEQNUM=1739, ACTION=remove) is queued
Jan 23 15:01:30 debian10 systemd-udevd[237]: Successfully forked off 'n/a' as PID 1328.
Jan 23 15:01:30 debian10 systemd-udevd[237]: tx-0: Worker [1328] is forked for processing SEQNUM=1739.
Jan 23 15:01:30 debian10 systemd-udevd[237]: ppp0: Device (SEQNUM=1740, ACTION=remove) is queued
Jan 23 15:01:30 debian10 systemd-udevd[1327]: rx-0: Processing device (SEQNUM=1738, ACTION=remove)
Jan 23 15:01:30 debian10 systemd-udevd[1328]: tx-0: Processing device (SEQNUM=1739, ACTION=remove)
Jan 23 15:01:30 debian10 dccm[1157]: DEBUG: gudev_uevent_callback: received uevent remove for device /sys/devices/virtual/net/ppp0/queues/tx-0
Jan 23 15:01:30 debian10 systemd-udevd[1328]: tx-0: Device (SEQNUM=1739, ACTION=remove) processed
Jan 23 15:01:30 debian10 dccm[1157]: DEBUG: gudev_uevent_callback: received uevent remove for device /sys/devices/virtual/net/ppp0/queues/rx-0
Jan 23 15:01:30 debian10 systemd-udevd[1327]: rx-0: Device (SEQNUM=1738, ACTION=remove) processed
Jan 23 15:01:30 debian10 systemd-udevd[1327]: rx-0: sd-device-monitor: Passed 157 byte to netlink monitor
Jan 23 15:01:30 debian10 systemd-udevd[1328]: tx-0: sd-device-monitor: Passed 157 byte to netlink monitor
Jan 23 15:01:30 debian10 systemd-udevd[237]: ppp0: sd-device-monitor: Passed 179 byte to netlink monitor
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: Processing device (SEQNUM=1740, ACTION=remove)
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: RUN 'ifupdown-hotplug' /usr/lib/udev/rules.d/80-ifupdown.rules:5
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: IMPORT builtin 'path_id' /usr/lib/udev/rules.d/80-net-setup-link.rules:5
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: IMPORT builtin 'path_id' fails: No such file or directory
Jan 23 15:01:30 debian10 systemd-udevd[1327]: Starting 'ifupdown-hotplug'
Jan 23 15:01:30 debian10 systemd-udevd[1327]: Successfully forked off '(spawn)' as PID 1329.
Jan 23 15:01:30 debian10 systemd-udevd[1327]: Process 'ifupdown-hotplug' succeeded.
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: Device (SEQNUM=1740, ACTION=remove) processed
Jan 23 15:01:30 debian10 dccm[1157]: DEBUG: gudev_uevent_callback: received uevent remove for device /sys/devices/virtual/net/ppp0
Jan 23 15:01:30 debian10 systemd-udevd[1327]: ppp0: sd-device-monitor: Passed 298 byte to netlink monitor
Jan 23 15:01:34 debian10 systemd-udevd[237]: Cleanup idle workers
Jan 23 15:01:34 debian10 systemd-udevd[1327]: Unload module index
Jan 23 15:01:34 debian10 systemd-udevd[1327]: Unloaded link configuration context.
Jan 23 15:01:34 debian10 systemd-udevd[1328]: Unload module index
Jan 23 15:01:34 debian10 systemd-udevd[1328]: Unloaded link configuration context.
Jan 23 15:01:34 debian10 systemd-udevd[237]: Worker [1327] exited
Jan 23 15:01:34 debian10 systemd-udevd[237]: Worker [1328] exited
显然,SynCE 使用基于 glib 的 gudev 来监控 udev 事件。监听事件“uevent”信号,为此,将回调附加到此信号并等待通知。USB 设备未拔出,没有理由发出信号“操作移除”。在 Ubuntu 14.04 上,它开箱即用,运行良好。
这是我的知识。我不知道如何接近问题的根源。我需要使 ppp0 <--> /dev/ttyUSB0 连接稳定。任何帮助或建议都将受到欢迎并非常感谢。
答案1
如何防止 udevd 错误地将设备 ppp 的删除事件列入队列?
udevd 没有做任何“错误”的事情;ACTION=remove
是由内核发出的(并由 udevd 重新发出)因为设备消失了,而不是相反。换句话说,udevd 只是对删除作出反应,而不是导致删除。
USB 设备未拔出,无信号“操作移除”的原因。
日志中的事件与 ttyUSB0 设备无关 - 它们仅提到 ppp0 网络接口,这是完全不同的东西。ttyUSB0 设备并不是使 ppp0 存在的原因 -它是pppd
创建 ppp0 的守护进程。
(因此为“/sys/devices/virtual”。直接连接到某个物理设备的网络接口实际上将显示为该物理设备的子设备。)
因为 ppp0 是由 pppd 动态创建的,所以它消失的最可能原因是 pppd 进程由于某种原因崩溃或退出。
(尽管,它不一定非得是 pppd — — 有可能 dccm 本身会处理 PPP 并创建这个接口 — — 但这种可能性较小;大多数此类工具并不会尝试重新发明事物,它们只是产生 pppd。)
答案2
这udev 手册请回复我:
不允许启动守护进程或其他长时间运行的进程;分叉进程(无论是否分离)将在事件处理完成后无条件终止。为了从 udev 规则激活长时间运行的进程,请提供服务单元并使用 SYSTEMD_WANTS 设备属性将其从 udev 设备中拉入。
较新的 udev 版本(来自 Ubuntu 16 和 Debian 8)通过对 udev 事务及其产生的进程设置严格的时间限制,阻止您在 RUN 或 PROGRAM 脚本中启动长期存在的后台进程。至于对 udev 产生的脚本的长期运行进程限制,如果您在后台启动某些东西,只要 udev 启动的实际脚本很快终止。Udev 使用 cgroups 来查找并销毁产生的任务。因此,所有线程都会收到终止信号。
systemd 路线是正确的方法,因为不建议从 udev 启动长时间运行的进程。