3 |
source /etc/conf.d/usbippolld |
source /etc/conf.d/usbippolld |
4 |
source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
5 |
|
|
6 |
|
# reset connection status for all clients on daemon startup |
7 |
|
mysqldo "update clients set connected='0'" |
8 |
|
|
9 |
while true |
while true |
10 |
do |
do |
11 |
ALLCLIENTS=$(mysqldo "select ip from clients") |
ALLCLIENTS=$(mysqldo "select ip from clients") |
19 |
|
|
20 |
echo "-- polling client #${client} on dev ${BUSID}" |
echo "-- polling client #${client} on dev ${BUSID}" |
21 |
usbip -a ${client} ${BUSID} |
usbip -a ${client} ${BUSID} |
22 |
|
|
23 |
|
# disconnect non reachable ports |
24 |
|
if [[ -n $(out=$(mktemp);usbip -a ${client} ${BUSID} &> ${out}; grep '\[Connection refused\]' ${out}) ]] || |
25 |
|
[[ -n $(out=$(mktemp);usbip -a ${client} ${BUSID} &> ${out}; grep '\[No route to host\]' ${out}) ]] |
26 |
|
then |
27 |
|
echo "-- client #${client} *non* reachable on dev ${BUSID}; reset connection state" |
28 |
|
mysqldo "update clients set connected='0', busid='' where ip='${client}'" |
29 |
|
fi |
30 |
else |
else |
31 |
echo "-- client #${client} not found, removing from list" |
echo "-- client #${client} not found, removing from list" |
32 |
|
|
36 |
|
|
37 |
mysqldo "update clients set connected='0', busid='' where ip='${client}'" |
mysqldo "update clients set connected='0', busid='' where ip='${client}'" |
38 |
fi |
fi |
39 |
|
# give the device the chance to (dis)connect |
40 |
|
sleep 3 |
41 |
done |
done |
42 |
|
|
43 |
sleep ${USBIP_WAIT_TIMEOUT} |
sleep ${USBIP_WAIT_TIMEOUT} |
44 |
|
|
45 |
|
## #TODO: fix driver b0rkage |
46 |
|
# mage-lager ~ # usbip -d 05 |
47 |
|
# 8 ports available |
48 |
|
# |
49 |
|
# port 5 detached |
50 |
|
# mage-lager ~ # usbip -p |
51 |
|
# 8 ports available |
52 |
|
# |
53 |
|
# usbip err: vhci_driver.c: 60 (imported_device_init) sysfs_open_device 007 [No such file or directory] |
54 |
|
# usbip err: vhci_driver.c: 140 (parse_status) init new device [No such file or directory] |
55 |
|
|
56 |
|
|
57 |
|
# disconnect all stale ports |
58 |
|
staleports=$(out=$(mktemp);usbip -p &> ${out};grep '\<Port Initializing\>' ${out} | grep Port | cut -d' ' -f2 | sed "s|:||") |
59 |
|
if [[ -n ${staleports} ]] |
60 |
|
then |
61 |
|
# wait some seconds, or driver may break !! |
62 |
|
sleep ${USBIP_WAIT_TIMEOUT} |
63 |
|
for port in ${staleports} |
64 |
|
do |
65 |
|
echo "-- disconnecting stale port #${port}" |
66 |
|
usbip -d ${port} |
67 |
|
# give the device the chance to disconnect |
68 |
|
sleep 3 |
69 |
|
done |
70 |
|
fi |
71 |
done |
done |