[GRASS5] Files left in /tmp from Init.sh

Hi

I noticed since I use GRASS 5.7 and also GRASS 6.0 cvs 2 problems (linked)
that I don't have with GRASS 5.4

PROBLEM 1

A large number of temporary directories and files are left in the /tmp
directory

PROBLEM 2

The MAPSET and LOCATION, when defined for a session, are not saved
in .grassrc6 for a next session.

I realized that the problem was linked to the way I exit GRASS (I click the
GRASS shell-window away and usually don't use the exit command) and to the
etc/Init.sh file. The same problem appears when GRASS exit abnormally ex:
grass60 /nonexistentlocation/mapset

PROPOSAL OF SOLUTION

Works fine on mandrake 10.1 with grass 6.0 beta2, as I am a biologist and not
a real developer, you should look at this proposal carefuly :slight_smile:

The changes are placed between #ooooooooooooooooo.
In order not to send a too long file I cut bin/init.sh at several places
indicated with [...].

If it is not the right way to do, tell me, I will do otherwise next time.

Philippe Juillerat

#! /bin/sh
#############################################################################
#
# $Id: init.sh,v 1.58 2005/02/03 02:24:42 hamish Exp $
#
# MODULE: GRASS Initialization

[...]

(umask 077 && mkdir "$tmp") || {
    echo "Cannot create temporary directory! Exiting." 1>&2
    exit 1
}
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# remove temporary directory and session files from tmpdir when exiting
trap "rm -rf $tmp" 0
# trapping signal SIGHUP give the opportunity to exit by clicking the
# GRASS shell-window
trap "echo 'User break!' ; exit" 1 2 3 15
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
GISRC="$tmp/gisrc"
export GISRC

[...]

# Check for concurrent use
lockfile="$LOCATION/.gislock"
"$ETC/lock" "$lockfile" $$
case $? in
    0) ;;
    1)
      echo `whoami` is currently running GRASS in selected mapset. Concurrent
use not allowed.
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# rm -rf "$tmp" # Have to be removed since already included
# in trap command above
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
      exit 1 ;;
    *)
      echo Unable to properly access "$lockfile"
      echo Please notify system personel.
      exit 1 ;;
esac

#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# Save $GISRC and remove session files from tmpdir when exiting with the
# terminal window's close button
trap "cp $GISRC $GISRCRC ; exit" 1
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
trap "" 2 3 15
CYGWIN=`uname | grep CYGWIN`

[...]

#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# all specified signals are are reset to their original values
trap 0 1 2 3 15
#ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

# GRASS session finished
tput clear
echo "Closing monitors....."
for MON in `d.mon -L | grep running | grep -v "not running" | sed 's/ .*//'`
do
    echo d.mon stop=$MON
    d.mon stop=$MON
done

echo "Cleaning up temporary files....."

"$ETC/clean_temp" > /dev/null
rm -f "$lockfile"

# Save GISRC
cp "$GISRC" "$GISRCRC"
rm -rf "$tmp" # remove session files from tmpdir

echo "done"
echo
echo
echo
echo "Goodbye from GRASS GIS"
echo

The previous proposal of solution to remove files left in /tmp directory (when
GRASS 6.0 or 5.7 is left without command "exit") is not a good idea. To trap
the signal SIGHUP in particular introduce more problems than it solve.
There is a simplier and better (I think) solution which is:

in etc/Init.sh v 1.58 2005/02/03 02:24:42 hamish

As soon as temporary directory is created:
row 107
+ trap "rm -rf $tmp" 0

row 542
- rm -rf "$tmp" # remove session files from tmpdir

After LOCATION and MAPSET are saved in $GISRC
row 549
+ trap "cp $GISRC $GISRCRC ; rm -rf $tmp" 0

row 715
- trap 2 3 15
+ trap 0 2 3 15

I wait for your suggestions
Thanks
Philippe

The previous proposal of solution to remove files left in /tmp
directory (when GRASS 6.0 or 5.7 is left without command "exit") is
not a good idea. To trap the signal SIGHUP in particular introduce
more problems than it solve. There is a simplier and better (I think)
solution which is:

in etc/Init.sh v 1.58 2005/02/03 02:24:42 hamish

As soon as temporary directory is created:
row 107
+ trap "rm -rf $tmp" 0

row 542
- rm -rf "$tmp" # remove session files from tmpdir

After LOCATION and MAPSET are saved in $GISRC
row 549
+ trap "cp $GISRC $GISRCRC ; rm -rf $tmp" 0

row 715
- trap 2 3 15
+ trap 0 2 3 15

I wait for your suggestions

A couple more cases where files get left behind in /tmp:

- exiting GRASS from both Startup Tcl GUI (Exit) and text UI (^C)
- auto-exit of GRASS after "Create Location From EPSG"

Hamish