From 7881cb4e1b00d5b538c9999ceb1b6790b6e06963 Mon Sep 17 00:00:00 2001 From: drgr33n Date: Thu, 17 Dec 2009 03:57:56 +0000 Subject: Added killscript() to fix broken pipe bug when script killed manually. When the script was killed by ctrl+c the progress function caused broken pipe to occur. Added creation of cleanup scripts to unmount devices and clean folders. Blueman does not unmount devices when using this bash script. So now blueman_open creates cleanup scripts in /etc/rc.d/rc0.d & */rc6.d. These scripts also clean themselves upon running. --- blueman_open | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'blueman_open') diff --git a/blueman_open b/blueman_open index f51a881..9b08e0e 100755 --- a/blueman_open +++ b/blueman_open @@ -14,6 +14,11 @@ own_name=$(basename $0) basedir=${basedir:-/mnt} dir=${basedir}/$device_addr browser=${browser:-"xdg-open"} +cleanup_script="#!/bin/bash\n +#cleanup bluetooth mount directories on shutdown / restart\n\n\ +fusermount -uz $dir\n +rm -rf $dir\nrm /etc/rc.d/rc0.d/$device_addr-cleanup.sh 1>/dev/null 2>/dev/null\n&\ +rm /etc/rc.d/rc6.d/$device_addr-cleanup.sh 1>/dev/null 2>/dev/null" count=0 @@ -30,6 +35,17 @@ else echo "0" > $p_file fi +# fix broken pipe when unexpected error occurs + +trap killscript INT + +killscript() +{ + echo "Initializing clean shutdown......" + echo "100" > $p_file # kill gtk window + exit 0 # kill script +} + #gtkdialog abstraction gtkbox_interactive() { @@ -114,6 +130,10 @@ mount_device () [ ! -z $DEBUG ] && logger -i -t $own_name "Open $dir with $browser" out=$($browser $dir 2>&1) [ ! -z $DEBUG ] && logger -i -t $own_name "$out" + # setup cleanup script + echo -e $cleanup_script > /etc/rc.d/rc0.d/$device_addr-cleanup.sh + chmod +x /etc/rc.d/rc0.d/$device_addr-cleanup.sh + ln -s /etc/rc.d/rc0.d/$device_addr-cleanup.sh /etc/rc.d/rc6.d/$device_addr-cleanup.sh exit 0 else logger -i -t $own_name "Failed to mount $device_addr to $dir from try $i " -- cgit v1.2.3