0

我有一个问题,当我在华硕 E200ha 上插入 vga/hdmi 适配器时,我想启动一个脚本来启动“hostapd”。当我直接在命令行中启动它时该脚本运行良好,但当它被“udev”调用时它不起作用

这是 udev 捕获的行:

ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN="/home/user/hotspot.sh"

这是脚本“hotspot.sh”

#!/bin/bash
exec >  /var/log/hotplug-vga.log 2>&1;
service NetworkManager stop
killall wpasupplicant
hostapd -dd /etc/hostapd/hostapd.conf &

这是“hostapd.conf”文件

interface=wlan0
ieee80211n=1
driver=nl80211
ssid=chingpro
hw_mode=g
channel=6
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

当我执行指令“/usr/sbin/hostapd /home/user/hostapd.sh”时,一切正常:

wpasupplicant: aucun processus trouvé
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
ctrl_interface_group=0
nl80211: TDLS supported
nl80211: TDLS external setup
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
[...]
nl80211: assocresp_ies - hexdump(len=10): 7f 08 04 00 00 02 00 00 00 40
nl80211: Set wlan0 operstate 0->1 (UP)
netlink: Operstate: ifindex=18 linkmode=-1 (no change), operstate=6 (IF_OPER_UP)
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
wlan0: Setup of interface done.
ctrl_iface not configured!
[...]

但是当我连接我的 vga/hdmi 时,我可以看到我的脚本是使用“/var/log/hotplug-vga.log”中的日志执行的,但是“hostapd”的启动失败:

wpasupplicant: no process found
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
ctrl_interface_group=0
nl80211: TDLS supported
nl80211: TDLS external setup
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
nl80211: Supported cipher 00-0f-ac:2
nl80211: Supported cipher 00-0f-ac:4
nl80211: Supported cipher 00-0f-ac:6
nl80211: Supported cipher 00-0f-ac:13
nl80211: Supported cipher 00-0f-ac:11
nl80211: Supported cipher 00-0f-ac:12
nl80211: Supports Probe Response offload in AP mode
nl80211: Using driver-based off-channel TX
nl80211: Driver-advertised extended capabilities (default) - hexdump(len=8): 04 00 00 00 00 00 00 40
nl80211: Driver-advertised extended capabilities mask (default) - hexdump(len=8): 04 00 00 00 00 00 00 40
nl80211: Use separate P2P group interface (driver advertised support)
nl80211: Enable multi-channel concurrent (driver advertised support)
nl80211: use P2P_DEVICE support
nl80211: interface wlan0 in phy phy15
nl80211: Set mode ifindex 18 iftype 3 (AP)
nl80211: Setup AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Subscribe to mgmt frames with AP handle 0x557d15b300e0
nl80211: Register frame type=0xb0 (WLAN_FC_STYPE_AUTH) nl_handle=0x557d15b300e0 match=
nl80211: Register frame command failed (type=176): ret=-114 (Operation already in progress)
nl80211: Register frame match - hexdump(len=0): [NULL]
nl80211: Could not configure driver mode
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
nl80211: Remove monitor interface: refcount=0
nl80211: Remove beacon (ifindex=18)
netlink: Operstate: ifindex=18 linkmode=0 (kernel-control), operstate=6 (IF_OPER_UP)
nl80211 driver initialization failed.
hostapd_interface_deinit_free(0x557d15b294c0)
hostapd_interface_deinit_free: num_bss=1 conf->num_bss=1
hostapd_interface_deinit(0x557d15b294c0)
wlan0: interface state UNINITIALIZED->DISABLED
hostapd_bss_deinit: deinit bss wlan0
wlan0: AP-DISABLED
hostapd_cleanup(hapd=0x557d15b2a730 (wlan0))
hostapd_free_hapd_data: Interface wlan0 wasn't started
hostapd_interface_deinit_free: driver=(nil) drv_priv=(nil) -> hapd_deinit
hostapd_interface_free(0x557d15b294c0)
hostapd_interface_free: free hapd 0x557d15b2a730
hostapd_cleanup_iface(0x557d15b294c0)
hostapd_cleanup_iface_partial(0x557d15b294c0)
hostapd_cleanup_iface: free iface=0x557d15b294c0

我花了很多时间来了解直接发送此脚本或通过 udev 发送此脚本的区别,但目前没有成功。

我正在做一个全新的“debian buster”安装


我使用相同的脚本安装 Ubuntu 18.04,但我遇到了同样的问题:脚本在命令行中运行良好,但在 udev 启动时失败!

谢谢你的帮助

4

2 回答 2

0

我知道这是一个老问题,但我也为这个问题苦苦挣扎并找到了解决方法。

我不知道为什么从 udev 调用时 hostapd 的行为会有所不同,但是页面 https://wiki.archlinux.org/index.php/udev#Spawning_long-running_processes 提供了解决方案,但针对不同的问题进行了构思。这个想法是将 hostapd 的执行处理到 udev 之外的守护进程,在本例中是 atd。这个守护进程在 debian 的包 'at' 中。安装后,您可以使用 udev 脚本调用 hostapd

echo "/usr/sbin/hostapd -B -P /path/to/pidfile /path/to/hostapd.config" | 现在

于 2020-08-15T08:52:13.780 回答
0

首先,您确定“service NetworkManager stop”确实运行了吗?“手动运行但不是从 cron/udev/initscript 运行”中的许多问题是由 PATH 的差异引起的。“服务”可能不在 udev 的路径上。

其次,这真的是你应该运行的命令吗?在https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047上,建议使用以下解决方案:

nmcli nm wifi off
rfkill unblock wlan

或者在可疑路径的情况下,也许最好把它写成

/usr/bin/nmcli nm wifi off
/usr/sbin/rfkill unblock wlan
于 2019-01-20T23:26:58.240 回答