使用 SynCE 将 PDA 设备与 Debian Buster 连接,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
这udev手册给我答复:
不允许启动守护进程或其他长时间运行的进程;分叉的进程,无论是否分离,都将在事件处理完成后被无条件终止。为了从 udev 规则激活长时间运行的进程,请提供一个服务单元并使用 SYSTEMD_WANTS 设备属性从 udev 设备中将其拉入。
较新的 udev 版本(来自 Ubuntu 16 和 Debian 8)通过对 udev 事务和由它们生成的进程设置严格的时间限制,阻止您在 RUN 或 PROGRAM 脚本中启动长期后台进程。至于对 udev 生成的脚本的长时间运行进程限制,如果您在后台启动某些内容,只要实际的脚本 udev 启动就会很快终止。 Udev 使用 cgroup 来搜索并销毁生成的任务。因此,所有线程都会收到终止信号。
systemd 路线是正确的方法,因为不建议从 udev 启动长时间运行的进程。