Contents of /trunk/usbip/usbippolld-sql
Parent Directory | Revision Log
Revision 209 -
(show annotations)
(download)
Tue May 22 10:16:59 2007 UTC (17 years, 4 months ago) by niro
File size: 2207 byte(s)
Tue May 22 10:16:59 2007 UTC (17 years, 4 months ago) by niro
File size: 2207 byte(s)
-disconnect all ports on daemon init -disconnect stale and unreachable ports
1 | #!/bin/bash |
2 | |
3 | source /etc/conf.d/usbippolld |
4 | 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 |
10 | do |
11 | ALLCLIENTS=$(mysqldo "select ip from clients") |
12 | |
13 | for client in ${ALLCLIENTS} |
14 | do |
15 | # filter all not connected clients |
16 | if [[ $(mysqldo "select connected from clients where ip='${client}'") = 1 ]] |
17 | then |
18 | BUSID=$(mysqldo "select busid from clients where ip='${client}'") |
19 | |
20 | echo "-- polling client #${client} on dev ${BUSID}" |
21 | 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 |
31 | echo "-- client #${client} not found, removing from list" |
32 | |
33 | out=$(mktemp) |
34 | port=$(usbip -p &> ${out};grep -B3 -i "${client}" ${out} | grep Port | cut -d' ' -f2| sed "s|:||") |
35 | [[ ! -z ${port} ]] && usbip -d ${port} |
36 | |
37 | mysqldo "update clients set connected='0', busid='' where ip='${client}'" |
38 | fi |
39 | # give the device the chance to (dis)connect |
40 | sleep 3 |
41 | done |
42 | |
43 | 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 |
Properties
Name | Value |
---|---|
svn:executable | * |