Magellan Linux

Annotation of /trunk/usbip/usbippolld-sql

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209 - (hide annotations) (download)
Tue May 22 10:16:59 2007 UTC (17 years ago) by niro
File size: 2207 byte(s)
-disconnect all ports on daemon init
-disconnect stale and unreachable ports

1 niro 174 #!/bin/bash
2    
3     source /etc/conf.d/usbippolld
4 niro 179 source /usr/lib/alxconfig-ng/functions/mysqlfunctions
5 niro 174
6 niro 209 # reset connection status for all clients on daemon startup
7     mysqldo "update clients set connected='0'"
8    
9 niro 174 while true
10     do
11 niro 185 ALLCLIENTS=$(mysqldo "select ip from clients")
12 niro 174
13     for client in ${ALLCLIENTS}
14     do
15 niro 185 # filter all not connected clients
16     if [[ $(mysqldo "select connected from clients where ip='${client}'") = 1 ]]
17 niro 174 then
18 niro 185 BUSID=$(mysqldo "select busid from clients where ip='${client}'")
19 niro 174
20 niro 185 echo "-- polling client #${client} on dev ${BUSID}"
21     usbip -a ${client} ${BUSID}
22 niro 209
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 niro 174 else
31 niro 185 echo "-- client #${client} not found, removing from list"
32 niro 174
33     out=$(mktemp)
34 niro 185 port=$(usbip -p &> ${out};grep -B3 -i "${client}" ${out} | grep Port | cut -d' ' -f2| sed "s|:||")
35 niro 174 [[ ! -z ${port} ]] && usbip -d ${port}
36 niro 185
37     mysqldo "update clients set connected='0', busid='' where ip='${client}'"
38 niro 174 fi
39 niro 209 # give the device the chance to (dis)connect
40     sleep 3
41 niro 174 done
42 niro 184
43     sleep ${USBIP_WAIT_TIMEOUT}
44 niro 209
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 niro 174 done

Properties

Name Value
svn:executable *