View Single Post
Old 08-13-2010, 10:09 AM   #398
pnt
Junior Member
pnt began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jul 2010
Device: kindle2
On an unrelated note, updated the usbnetwork packages according to pnt's suggestions .[/QUOTE]

@NiLuJe sorry about the late reply. Thank you for adopting my idea.

And I have a new idea, which makes easier to switch to usbnet mode without reboot. It's actually borrow from you that reboot kindle app when put "reboot" file into linkfonts/ folder. So I implemented to switch to usbnet mode when detecting "start" file in usbnet/ folder. I put the patch here. If you feel it's good, please merge when next release. Thanks.

Code:
--- usb-watchdog-helper.orig    Tue Jul 20 00:49:44 2010
+++ usb-watchdog-helper Sun Aug  1 16:41:08 2010
@@ -13,13 +13,19 @@
 # Lock file. We'll do a fucking lot of redundant checks to avoid race conditions... -_-"
 USBWD_LOCK_FILE="${LINKFONTS_BASEDIR}/usbwd.lock"

+USBNET_ENABLE=/mnt/us/usbnet/auto
+USBNET_SCRIPT=/mnt/us/usbnet/bin/usbnetwork
+USBNET_BASEDIR="/mnt/us/usbnet"
+USBWD_USBNET_FILE="${USBNET_BASEDIR}/start"
+
 # Add the PID of the dbus-monitor(s) to the list of running daemons to kill
 echo "$( pidof dbus-monitor )" >> ${WATCHDOG_PID}
 # Add our PID to the list of running daemons to kill
 echo "$$" >> ${WATCHDOG_PID}

 while read line ; do
-    if [ -f ${USBWD_REBOOT_FILE} -a ! -f ${USBWD_LOCK_FILE} ] ; then
+    if [ -f ${USBWD_REBOOT_FILE} -a ! -f ${USBWD_LOCK_FILE} -o -f ${USBWD_USBNET_FILE} -a ! -f ${USBWD_LOCK_FILE} ] ; then
         # We asked for a reboot on unplug, and we're not already locked in a reboot session, let's see...
         echo ${line} | grep usbPlugOut > /dev/null 2>&1
         if [ $? -eq 0 ] ; then
@@ -28,7 +34,7 @@
                 # We're still not in a locked session, assume we're the first, and lock using our PID.
                 echo "$$" > ${USBWD_LOCK_FILE}
                 # We really want to avoid running two restarts in case the Kindle did something weird with it's usbPlugOut event, or if we got more than one watchdog running (which would be a bug :p)
-                if [ -f ${USBWD_LOCK_FILE} -a "$( cat ${USBWD_LOCK_FILE} 2> /dev/null )" == "$$" ] ; then
+                if [ -f ${USBWD_REBOOT_FILE} -a -f ${USBWD_LOCK_FILE} -a "$( cat ${USBWD_LOCK_FILE} 2> /dev/null )" == "$$" ] ; then
                     # We only want to do this once, so kill the reboot file
                     rm -f ${USBWD_REBOOT_FILE}
                     # Log our restart
@@ -39,9 +45,29 @@
                     sync
                     # And restart the framework
                     /etc/init.d/framework restart
-                    # And then remove our lock file
-                    rm -rf ${USBWD_LOCK_FILE}
+                elif ! lsmod | grep g_ether > /dev/null && [ -f ${USBWD_USBNET_FILE} -a -f ${USBWD_LOCK_FILE} -a "$( cat ${USBWD_LOCK_FILE} 2> /dev/null )" == "$$" ] ; then
+                    mv ${USBWD_USBNET_FILE} ${USBWD_USBNET_FILE}_stub
+                    sleep 2
+                    sync
+                    if [ -x /etc/init.d/usbnet ]; then
+                        if [ -f ${USBNET_ENABLE} ]; then
+                            /etc/init.d/usbnet start
+                        else
+                            touch ${USBNET_ENABLE}
+                            /etc/init.d/usbnet start
+                            rm -f ${USBNET_ENABLE}
+                        fi
+                    elif [ -f ${USBNET_SCRIPT} ]; then
+                        [ -x ${USBNET_SCRIPT} ] || chmod +x ${USBNET_SCRIPT}
+                        ${USBNET_SCRIPT}
+                    fi
                 fi
+                # And then remove our lock file
+                rm -rf ${USBWD_LOCK_FILE}
             fi
         fi
     fi
pnt is offline   Reply With Quote