From 941f558413e7cdaa8a566106021b81d419707cd9 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 7 Jun 2012 00:19:32 +0300 Subject: [PATCH] run_gingerbread: fix signal handling and exit --- pnd/gingerbread.pxml | 2 +- pnd/{run.sh => run_gingerbread.sh} | 63 +++++++++++++++++++++--------- scripts/make_pnd.sh | 2 +- 3 files changed, 46 insertions(+), 21 deletions(-) rename pnd/{run.sh => run_gingerbread.sh} (83%) diff --git a/pnd/gingerbread.pxml b/pnd/gingerbread.pxml index fec4c4f..77e70f3 100644 --- a/pnd/gingerbread.pxml +++ b/pnd/gingerbread.pxml @@ -17,7 +17,7 @@ The whole Android 2.3.4 (Gingerbread) OS fitted inside a PND - + diff --git a/pnd/run.sh b/pnd/run_gingerbread.sh similarity index 83% rename from pnd/run.sh rename to pnd/run_gingerbread.sh index 98894e8..521dc97 100755 --- a/pnd/run.sh +++ b/pnd/run_gingerbread.sh @@ -1,18 +1,22 @@ #!/bin/bash -# run/kill Android from Linux +# run/kill Android from Linux, the hackjob script # (c) Grazvydas "notaz" Ignotas, 2012 set -e -x if [ "`id -u`" != "0" ]; then - gksudo -m "Android needs root privileges to run, please enter your password" $0 - exit 0 + # gksudo causes logging not to work somehow.. + # so use it to only ask for password, use sudo to re-run the script + gksudo -m "Android needs root privileges to run, please enter your password" id + exec sudo -n $0 fi root=/mnt/android mpoint_main=`pwd` kernel_ver=`uname -r` +exitcode=1 -trap onexit 1 2 3 15 EXIT +trap onexit INT QUIT TERM EXIT +trap '' HUP err() { @@ -46,22 +50,22 @@ onexit() sleep 0.5 - for i in `seq 5`; do + for i in `seq 4`; do sdmounts=`grep -e '\.android_secure' -e 'secure/asec' -e 'mnt/sdcard' /proc/mounts` if [ -n "$sdmounts" ]; then echo "$sdmounts" | awk '{print $2}' | xargs umount fi - umount $root/mnt/asec - umount $root/debug - umount $root/dev/pts - umount $root/dev - umount $root/proc - umount $root/sys - umount $root/data - umount $root/system || umount -i $root/system - - sleep 1 + omounts=`grep "$root/" /proc/mounts | awk '{print $2}'` + if [ -n "$omounts" ]; then + for m in $omounts; do + if ! umount $m; then + umount -i $m + fi + done + fi + + sleep 0.5 if umount $root; then break; fi @@ -75,6 +79,24 @@ onexit() /etc/init.d/NetworkManager start /etc/init.d/slim-init start fi + + if ! ps a | grep -q 'pnd_run.*run_gingerbread.sh'; then + # something killed pnd_run, have to clean up for it + cat > /tmp/clean_android.sh < /dev/null + rm $0 +EOF + cd /tmp/ + chmod +x /tmp/clean_android.sh + /tmp/clean_android.sh & + sleep 1 + fi + exit $exitcode } @@ -137,7 +159,7 @@ mount -o loop,rw,noatime rootfs.ext2 $root mount --bind $mpoint_main/system/ $root/system/ mount -o loop,rw,noatime data.ext4 $root/data -mkdir -p $root/vendor +mkdir -p $root/vendor/ # handle SGX mkdir -p $root/vendor/pvr @@ -218,10 +240,10 @@ killall chvt 2> /dev/null || true ifconfig wlan0 down set -e -cp /etc/pointercal $root/vendor/ -cp /lib/modules/$kernel_ver/kernel/drivers/net/wireless/wl1251/wl1251_sdio.ko $root/vendor/ +cp -v /etc/pointercal $root/vendor/ +cp -v /lib/modules/$kernel_ver/kernel/drivers/net/wireless/wl1251/wl1251_sdio.ko $root/vendor/ mkdir -p $root/vendor/firmware -cp /lib/firmware/brf6300.bin $root/vendor/firmware/ +cp -v /lib/firmware/brf6300.bin $root/vendor/firmware/ # some cleanup rm -rf $root/acct/uid/* @@ -246,3 +268,6 @@ done # real init can't be killed this way killall init + +# done, run exit handler indirectly +exitcode=0 diff --git a/scripts/make_pnd.sh b/scripts/make_pnd.sh index f53ef0b..944471d 100755 --- a/scripts/make_pnd.sh +++ b/scripts/make_pnd.sh @@ -29,7 +29,7 @@ tar xf /tmp/pnd_android/system.tar.bz2 mkdir -p pandora/pvr cp ../../device/openpandora/pandora/pnd/gingerbread.png pandora/ cp ../../device/openpandora/pandora/pnd/gingerbread.pxml pandora/ -cp ../../device/openpandora/pandora/pnd/run.sh pandora/ +cp ../../device/openpandora/pandora/pnd/run_gingerbread.sh pandora/ cp ../../device/openpandora/pandora/pnd/readme.txt pandora/ cp -r ../../device/openpandora/pandora/pvr/3* pandora/pvr/ mv /tmp/pnd_android/rootfs.ext2 pandora/default_rootfs.ext2 -- 2.39.5