r3756 do a series of cleanups on temporary files and error reporting
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 19:28:06 +0000 (19:28 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sun, 6 Jun 2010 19:28:06 +0000 (19:28 +0000)
gateways/deviceconfig/fdry5.connector
gateways/deviceconfig/ios12.connector
gateways/deviceconfig/main
gateways/deviceconfig/vrp53.connector
gateways/deviceconfig/xos12.connector

index a2a48f21697c528717de559058894a88f317da24..bf6201440a5fc372583d03ad77b1640abb747924 100755 (executable)
@@ -42,7 +42,8 @@ prepare_connect_commands()
        exit 3
 }
 
-SESSION=`mktemp /tmp/fdry5.connector.XXXX`
+MYNAME=`basename $0`
+SESSION=`mktemp /tmp/$MYNAME.XXXX`
 [ -f "$SESSION" ] || exit 5
 prepare_connect_commands $ENDPOINT
 case $COMMAND in
@@ -55,9 +56,12 @@ deploy)
        outfile=/dev/null
        ;;
 *)
-       outfile=/dev/null
+       rm -f "$SESSION"
+       exit 6
+       ;;
 esac
 printf 'exit\r\nexit\r\n' >> "$SESSION"
-nc -w 30 -i 1 $ENDPOINT 23 < "$SESSION" > "$outfile"
+rc=0
+nc -w 30 -i 1 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
 rm -f "$SESSION"
-exit 0
+exit $rc
index dabf49347ba4d53dc27bf3f8bbabcbf272cbeaf9..e260dfd7f7807abf30a37eaeef85cd1474b78a7c 100755 (executable)
@@ -43,7 +43,8 @@ prepare_connect_commands()
        exit 3
 }
 
-SESSION=`mktemp /tmp/ios12.connector.XXXX`
+MYNAME=`basename $0`
+SESSION=`mktemp /tmp/$MYNAME.XXXX`
 [ -f "$SESSION" ] || exit 5
 prepare_connect_commands $ENDPOINT
 case $COMMAND in
@@ -60,10 +61,12 @@ deploy)
        outfile=/dev/null
        ;;
 *)
-       outfile=/dev/null
+       rm -f "$SESSION"
+       exit 6
        ;;
 esac
 printf 'quit\n' >> "$SESSION"
-nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile"
+rc=0
+nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
 rm -f "$SESSION"
-exit 0
+exit $rc
index 02b1e20471d8b0a3d459aca0a35b1f9a301c6e73..50e0c12d45f4514ee4b9d40d4d8d787a0a546d4e 100755 (executable)
@@ -18,11 +18,8 @@ MYDIR=`dirname $0`
 decode_error()
 {
        case "$1" in
-               0)
-                       echo -n 'success'
-               ;;
                1)
-                       echo -n 'internal error 1'
+                       echo -n 'invalid connector args'
                ;;
                2)
                        echo -n 'internal error 2'
@@ -31,40 +28,28 @@ decode_error()
                        echo -n 'password not found'
                ;;
                4)
-                       echo -n 'invalid password'
+                       echo -n 'netcat failed'
                ;;
                5)
                        echo -n 'cannot create temporary files'
                ;;
                6)
-                       echo -n 'invalid command'
-               ;;
-               7)
-                       echo -n 'unknown host OS'
+                       echo -n 'command not supported by device'
                ;;
                *)
-                       echo -n 'unknown error'
+                       echo -n "unknown error $1"
                ;;
        esac
 }
 
-do_work()
-{
-       local command=$1
-       local endpoint=$2
-       local handler=$3
-       local conftext=$4
+while read command endpoint handler conftext; do
        # sanity checks
        if [ -z "$endpoint" -o -z "$conftext" -o -z "$handler" -o -z "$command" ]; then
-               echo 'ERR!too few arguments to connect'
-               return
-       fi
-       if [ "$command" = "getcdpstatus" and "$handler" != "ios12" ]; then
-               echo 'ERR!getcdpstatus only works for ios12'
+               echo 'ERR!too few arguments in command'
                return
        fi
        [ -x "$MYDIR/$handler.connector" ] || {
-               echo "ERR!Handler '$handler' is not available"
+               echo "ERR!Connector '$handler' is not available"
                exit 1
        }
        "$MYDIR/$handler.connector" $endpoint $command "$conftext"
@@ -72,20 +57,11 @@ do_work()
        if [ $ret = 0 ]; then
                echo "OK!request '$command' complete for $endpoint"
        else
-               echo -n "ERR!Cannot connect to $endpoint ("
+               echo -n "ERR!connector error ("
                decode_error $ret
                echo ')'
        fi
-}
-
-while read cmd args; do
-       case $cmd in
-               get8021q|deploy|getcdpstatus)
-                       do_work $cmd $args
-                       ;;
-               *)
-                       echo "ERR!unknown command $cmd"
-       esac
 done
 
+# all error messages have been sent to stdout
 exit 0
index fb90d9304aa63293fae72144a1124e0572b240a7..082c8393cce041fbb99f8429309150ac6c9e65f8 100755 (executable)
@@ -56,9 +56,12 @@ deploy)
        outfile=/dev/null
        ;;
 *)
-       outfile=/dev/null
+       rm -f "$SESSION"
+       exit 6
+       ;;
 esac
 printf 'quit\n' >> "$SESSION"
-nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile"
+rc=0
+nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
 rm -f "$SESSION"
-exit 0
+exit $rc
index 4b600f5032f56cb5f5cf3aa3d6cda22b05c2d99a..da507e9082db03fbd9474b81495eb6bc144edd5c 100755 (executable)
@@ -57,10 +57,13 @@ deploy)
        outfile=/dev/null
        ;;
 *)
-       outfile=/dev/null
+       rm -f "$SESSION"
+       exit 6
+       ;;
 esac
 # quit, but don't save, if asked
 printf 'quit\nn\n' >> "$SESSION"
-nc -w30 $ENDPOINT 23 < "$SESSION" > "$outfile"
+rc=0
+nc -w30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
 rm -f "$SESSION"
-exit 0
+exit $rc