[GRASS5] work group changes

Roger S. Miller rgrmill at rt66.com
Mon Dec 18 12:04:44 EST 2000


Per Justin Hickey's suggestion, I'm sending these changes to the list.

The listing that follows provides a partial path name to each of the files
I changed offset by lines of "%", a brief description of the changes, and
the full listing of the file that contains the changes.

Roger Miller

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grass5.0beta10/src/libes/gis/mapset_msc.c
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I added a version of G__mapset_permissions that uses the access library
function to determine permissions on a mapset.  The new code is used when
RELAXED PERMISSION is defined, otherwise the old code is used.  In this
case RELAXED_PERMISSION is hardwired set

#define RELAXED_PERMISSION 1
/*********************************************************
 * G__make_mapset_element (element)
 *     char *element           element to be created in mapset
 *
 * make the specified element in the current mapset
 * will check for the existence of the element and
 * do nothing if it is found so this routine
 * can be called even if the element already exists
 ********************************************************/

#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "gis.h"

#include <sys/types.h>
#include <sys/stat.h>

int G__make_mapset_element (char *p_element)
{
    char command[1024];
    char *path;
    char *p;
    char *G_mapset();
    char *element;

    element = p_element;
    if (*element == 0)
	    return 0;
    strcpy (path = command, "mkdir ");
    while (*path)
	path++;

    G__file_name (p = path, "", "", G_mapset());
    while (*p)
	p++;
/* add trailing slash if missing */
    --p;
    if (*p++ != '/')
    {
	*p++ = '/' ;
	*p = 0;
    }

/* now append element, one directory at a time, to path */
    while (1)
    {
	if (*element == '/' || *element == 0)
	{
	    *p = 0;
/* MOD shapiro 16apr91 */
	    if (access (path, 0) != 0)
	    {
		mkdir(path,0777);
	    }
/* end MOD */
	    if (access (path, 0) != 0)
	    {
		system (command);
	    }
	    if (access (path, 0) != 0)
	    {
		char err[1024];
		sprintf (err, "can't make mapset element %s (%s)", p_element, path);
		G_fatal_error (err);
		exit(1);
	    }
	    if (*element == 0)
		return 1;
	}
	*p++ = *element++;
    }
}

/****************************************************************
* G__mapset_permissions (mapset)
*
* returns: 1 mapset exists, and user has permission
*          0 mapset exists, BUT user denied permission
*         -1 mapset does not exist
****************************************************************/

#ifdef RELAXED_PERMISSION
int G__mapset_permissions (char *mapset)
{
   char path[256];

   G__file_name (path,"","",mapset);

   if(access(path,F_OK) != 0)
         return -1;

   if(access(path,R_OK|W_OK) !=0)
         return 0;

   return 1;
}

#else
int G__mapset_permissions (char *mapset)
{
    char path[256];
    struct stat info;

    G__file_name (path,"","",mapset);

    if (stat (path, &info) != 0)
	    return -1;

    if (info.st_uid != getuid())
	    return 0;
    if (info.st_uid != geteuid())
	    return 0;

    return 1;
}
#endif

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grass5.0beta10/src/libes/gis/gisinit.c
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Very small change.  I added a line to set umask to 002.  The original code used 022.  RELAXED_PERMISSION is set to use 002, and not set to use 022.

#define RELAXED_PERMISSION 1
/**********************************************************************
 *
 *   G_gisinit(pgm)
 *      char *pgm        Name to be associated with current program
 *
 *  Does some program initialization.  Read comments in this file
 *  for details.
 **********************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "gis.h"
#include "G.h"
#include "version.h"

struct G__ G__ ;
static int initialized = 0;
static int gisinit();

CELL CELL_NODATA; /* defined in gis.h */

int G_gisinit( char *pgm)
{
    char *mapset;
    char msg[100];

    G_set_program_name (pgm);

    CELL_NODATA = 0;	/* 0 for the moment */

/* Make sure location and mapset are set */
    G_location_path();
    switch (G__mapset_permissions (mapset = G_mapset()))
    {
    case 1:
	    break;
    case 0:
	    sprintf(msg,"MAPSET %s - permission denied", mapset);
	    G_fatal_error (msg);
	    exit(-1);
	    break;
    default:
	    sprintf(msg,"MAPSET %s not found", mapset);
	    G_fatal_error (msg);
	    exit(-1);
	    break;
    }

    gisinit();

    return 0;
}

int G_no_gisinit(void)
{
    gisinit();

    return 0;
}

int G__check_gisinit()
{
    if (initialized) return 1;
    fprintf (stderr, "\7ERROR: System not initialized. Programmer forgot to call G_gisinit()\n");
    sleep(3);
    exit(-1);
}

static int gisinit()
{
    int i ;

/* Mark window as not set */
    G__.window_set = 0 ;

/* no histograms */
    G__.want_histogram = 0;

/* Mark all cell files as closed */
    for (i = 0; i < MAXFILES; i++)
    {
	G__.fileinfo[i].open_mode = -1;
    }

/* Set compressed data buffer size to zero */
    G__.compressed_buf_size = 0;
    G__.work_buf_size = 0;
    G__.null_buf_size = 0;
    G__.mask_buf_size = 0;
    /* mask buf we always want to keep allocated */
    G__reallocate_mask_buf();

/* set the write type for floating maps */
    G__.fp_type = FCELL_TYPE;
    G__.fp_nbytes = XDR_FLOAT_NBYTES;

/* Set masking flag unknown */
    G__.auto_mask = -1 ;

/* set architecture dependant bit patterns for embeded null vals */
    G__init_null_patterns();

    initialized = 1;

#ifdef RELAXED_PERMISSION
    umask(002);

#else
    umask(022);

#endif

    return 0;
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grass5/etc/Init.sh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I moved the locking step from the beginning of the code to the point after
LOCATION is defined, then modified that part of the script to use $LOCATION
rather than $HOME.  It was not necessary to change the "lock.c" code.  I also
changed the error message to reflect that change.  In the bash setup, I
changed "umask 022" to "umask 002".  I don't see that similar changes can be
made for other shells.

#############################################################################
#
# $Id: init.sh,v 1.23 2000/12/07 07:36:24 cho Exp $
#
# MODULE:   	Grass Initialization
# AUTHOR(S):	Original author unknown - probably CERL
#   	    	Huidae Cho - Korea - hdcho at geni.knu.ac.kr
#   	    	Justin Hickey - Thailand - jhickey at hpcc.nectec.or.th
#   	    	Markus Neteler - Germany - neteler at geog.uni-hannover.de
# PURPOSE:  	The source file for this shell script is in
#   	    	src/general/init/init.sh. It sets up some environment
#   	    	variables and the lock file. It also parses any remaining
#   	    	command line options for setting the GISDBASE, LOCATION, and/or
#   	    	MAPSET. Finally it starts grass with the appropriate user
#   	    	interface and cleans up after it is finished.
# COPYRIGHT:    (C) 2000 by the GRASS Development Team
#
#               This program is free software under the GNU General Public
#   	    	License (>=v2). Read the file COPYING that comes with GRASS
#   	    	for details.
#
#############################################################################

: ${GISBASE?}

# Set PATH to GRASS bin, ETC to GRASS etc
ETC=$GISBASE/etc
PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
export PATH

# Set some environment variables if they are not set
if [ ! "$PAGER" ] ; then
    PAGER=more
    export PAGER
fi

if [ ! "$GRASS_TCLSH" ] ; then
    GRASS_TCLSH=tclsh
    export GRASS_TCLSH
fi

if [ ! "$GRASS_WISH" ] ; then
    GRASS_WISH=wish
    export GRASS_WISH
fi

# First time user - GISRC is defined in the grass script
if [ ! -f $GISRC ] ; then
    cat $ETC/grass_intro
    echo
    echo "Hit RETURN to continue"
    read ans

    # This is a hack for not having a good initial gui - should be removed
    # with next version of initialization gui
    GRASS_GUI="text"
fi

echo "Starting GRASS ..."

# Check if we are running X windows by checking the DISPLAY variable
if [ "$DISPLAY" ] ; then

    # Check if we need to find wish
    if [ "$GRASS_GUI" = "tcltk" ] ; then

	# Search for a wish program
	WISH=

	for i in `echo $PATH | sed 's/^:/.:/
    	    	    		    s/::/:.:/g
				    s/:$/:./
				    s/:/ /g'`
	do
	    if [ -f $i/$GRASS_WISH ] ; then
    		WISH=$GRASS_WISH
		break
	    fi
	done

	# Check if wish was found
	if [ "$WISH" ] ; then

	    # Set the tcltkgrass base directory
	    TCLTKGRASSBASE=$GISBASE/tcltkgrass
	    export TCLTKGRASSBASE
	else

	    # Wish was not found - switch to text interface mode
	    echo
    	    echo "WARNING: The wish command ($GRASS_WISH) was not found!"
	    echo "Please check your GRASS_WISH environment variable."
	    echo "Use the -help option for details."
	    echo "Switching to text based interface mode."
	    echo
	    echo "Hit RETURN to continue."
	    read ans

	    GRASS_GUI="text"
	fi
    fi
else

    # Display a message if a graphical interface was expected
    if [ "$GRASS_GUI" != "text" ] ; then
        # Set the interface mode to text
    	echo
	echo "WARNING: It appears that the X Windows system is not active."
	echo "A graphical based user interface is not supported."
	echo "Switching to text based interface mode."
	echo
	echo "Hit RETURN to continue"
	read ans

        GRASS_GUI="text"
    fi
fi

export GRASS_GUI

# Save the user interface variable in the grassrc file - choose a temporary
# file name that should not match another file
if [ -f $GISRC ] ; then
    awk '$1 !~ /GRASS_GUI/ {print}' $GISRC > $GISRC.$$
    echo "GRASS_GUI: $GRASS_GUI" >> $GISRC.$$
    mv -f $GISRC.$$ $GISRC
fi

# Parsing argument to get LOCATION
if [ ! "$1" ] ; then

    # Try interactive startup
    LOCATION=
else

    # Try non-interactive startup
    L=

    if [ "$1" = "-" ] ; then

    	if [ "$LOCATION" ] ; then
    	    L=$LOCATION
    	fi
    else
    	L=$1

    	if [ `echo $L | cut -c 1` != "/" ] ; then
    	    L=`pwd`/$L
    	fi
    fi

    if [ "$L" ] ; then
    	MAPSET=`basename $L`
    	L=`dirname $L`

    	if [ "$L" != "." ] ; then
    	    LOCATION_NAME=`basename $L`
    	    L=`dirname $L`

    	    if [ "$L" != "." ] ; then
    	    	GISDBASE=$L
    	    fi
    	fi
    fi

    if [ "$GISDBASE" -a "$LOCATION_NAME" -a "$MAPSET" ] ; then
    	LOCATION=$GISDBASE/$LOCATION_NAME/$MAPSET

    	if [ ! -r $LOCATION/WIND ] ; then
    	    echo "$LOCATION: No such location"
    	    exit
    	fi
    	export GISDBASE LOCATION_NAME MAPSET

    	if [ -s $GISRC ] ; then
    	    sed -e "s|^GISDBASE:.*$|GISDBASE: $GISDBASE|; \
    	    	s|^LOCATION_NAME:.*$|LOCATION_NAME: $LOCATION_NAME|; \
    	    	s|^MAPSET:.*$|MAPSET: $MAPSET|" $GISRC > $GISRC.$$

    	    if [ $? -eq 0 ] ; then
    	    	mv -f $GISRC.$$ $GISRC
    	    else
    	    	rm -f $GISRC.$$
    	    	echo "Failed to create new $GISRC"
    	    	LOCATION=
    	    fi
    	else
    	    echo "GISDBASE: $GISDBASE" > $GISRC
    	    echo "LOCATION_NAME: $LOCATION_NAME" >> $GISRC
    	    echo "MAPSET: $MAPSET" >> $GISRC
    	fi
    else
    	echo "GISDBASE, LOCATION_NAME and MAPSET variables not set properly."
    	echo "Interactive startup needed."
    	exit
    fi
fi

# User selects LOCATION and MAPSET if not set
if [ ! "$LOCATION" ] ; then

    case "$GRASS_GUI" in

	# Check for text interface
	text)
	    $ETC/set_data

	    case $? in
     	    	0) ;;
     	    	*) exit ;;
    	    esac

	    eval `g.gisenv`
	    ;;

	# Check for tcltk interface
	tcltk)
	    eval `$WISH -file $TCLTKGRASSBASE/script/gis_set.tcl`

	    case $? in
     	    	1)
		    # The gis_set.tcl script printed an error message so wait
		    # for user to read it
		    echo "Hit RETURN to continue..."
		    read ans

		    GRASS_GUI="text"

		    export GRASS_GUI
                    if [ -f $GISRC ] ; then
                        awk '$1 !~ /GRASS_GUI/ {print}' $GISRC > $GISRC.$$
                        echo "GRASS_GUI: $GRASS_GUI" >> $GISRC.$$
                        mv -f $GISRC.$$ $GISRC
                    fi

		    $ETC/set_data

		    case $? in
     	    		0) ;;
     	    		*) exit ;;
    		    esac

		    eval `g.gisenv`
		    ;;

     	    	0)
		    # These checks should not be necessary with real init stuff
		    if [ "$LOCATION_NAME" = "##NONE##" ] ; then
    	    		$ETC/set_data
    	    		if [ $? != 0 ]; then
    	    		    echo "GISDBASE: $OLD_DB" > $GISRC
    	    		    echo "LOCATION_NAME: $OLD_LOC" >> $GISRC
    	    		    echo "MAPSET: $OLD_MAP" >> $GISRC
    	    		    exit
    	    		fi
    	    		eval `g.gisenv`
    		    fi

		    if [ "$LOCATION_NAME" = "##ERROR##" ] ; then
    	    		echo "The selected location is not a valid GRASS location"
    	    		exit
		    fi

		    ;;

		*)
		    echo "Invalid return code from gis_set.tcl."
		    echo "Please advise GRASS developers of this error."
		    ;;
    	    esac

	    ;;
	*)
	    # Shouldn't need this but you never know
	    echo "ERROR: Invalid user interface specified."
	    echo "Use the -help option to grass for valid interfaces."
	    exit
	    ;;
    esac
fi

LOCATION=${GISDBASE?}/${LOCATION_NAME?}/${MAPSET?}
export LOCATION

# Set the GIS_LOCK variable to current process id
lockfile=$LOCATION/.gislock5
GIS_LOCK=$$
export GIS_LOCK

# Check for concurrent use
$ETC/lock $lockfile $$
case $? in
    0) ;;
    1)
    	echo $MAPSET is currently in use. Concurrent use is not allowed.
    	exit ;;
    *)
    	echo Unable to properly access $lockfile
    	echo Please notify system personel.
    	exit ;;
esac

trap "" 2 3

sh="`basename $SHELL`"
case "$sh" in
    ksh)  shellname="Korn Shell";;
    csh)  shellname="C Shell" ;;
    tcsh) shellname="TC Shell" ;;
    bash) shellname="Bash Shell" ;;
    sh)   shellname="Bourne Shell";;
    *)    shellname=shell;;
esac

# Start the chosen GUI but ignore text
case "$GRASS_GUI" in

    # Check for tcltk interface
    tcltk)
        $GISBASE/bin/tcltkgrass &
	;;

    # Ignore others
    *)
    	;;
esac

# Display the version and license info
clear

echo "Welcome to GRASS 5.0beta10 (December 2000) "
echo
echo "Geographic Resources Analysis Support System (GRASS) is Copyright,"
echo "1999-2000 by the GRASS Development Team, and licensed under terms of the"
echo "GNU General Public License (GPL)."
echo
echo "This GRASS 5.0beta10 release is coordinated and produced by the"
echo "GRASS Development Team headquartered at University of Hannover with"
echo "worldwide support and further development sites located at Baylor"
echo "University and the University of Illinois."
echo
echo "This program is distributed in the hope that it will be useful, but"
echo "WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU"
echo "General Public License for more details."
echo
echo "This version running thru the $shellname ($SHELL)"
echo "Help is available with the command:      g.help"
echo "See the licence terms with:              g.version"

if [ "$GRASS_GUI" = "text" ] ; then
    echo "Start the graphical user interface with: tcltkgrass&"
else
    echo "If required, restart the graphical user interface with: tcltkgrass&"
fi

echo "When ready to quit enter:                exit"

case "$sh" in

csh|tcsh)
    USERHOME=$HOME      # save original home
    HOME=$LOCATION
    export HOME
    cshrc=$HOME/.cshrc
    tcshrc=$HOME/.tcshrc
    rm -f $cshrc $tcshrc
    echo "set home = $USERHOME" > $cshrc
    echo "set history = 30 noclobber ignoreeof" >> $cshrc

    echo "set prompt = '\\" >> $cshrc
    echo "Mapset <${MAPSET}> in Location <${LOCATION_NAME}> \\" >> $cshrc
    echo "GRASS 5.0beta10 > '" >> $cshrc
    echo 'set BOGUS=``;unset BOGUS' >> $cshrc

    if [ -r $USERHOME/.grass.cshrc ]
    then
	cat $USERHOME/..grass.cshrc >> $cshrc
    fi

    if [ -r $USERHOME/.cshrc ]
    then
	grep '^ *set  *mail *= *' $USERHOME/.cshrc >> $cshrc
    fi

    if [ -r $USERHOME/.tcshrc ]
    then
	grep '^ *set  *mail *= *' $USERHOME/.tcshrc >> $cshrc
    fi

    if [ -r $USERHOME/.login ]
    then
	grep '^ *set  *mail *= *' $USERHOME/.login >> $cshrc
    fi

    echo "set path = ( $PATH ) " | sed 's/:/ /'g >> $cshrc

    cp $cshrc $tcshrc
    $ETC/run $SHELL

    HOME=$USERHOME
    export HOME
    ;;

bash)
    USERHOME=$HOME      # save original home
    HOME=$LOCATION      # save .bashrc in $LOCATION
    export HOME
    bashrc=$HOME/.bashrc
    rm -f $bashrc
    echo "test -z $PROFILEREAD && . /etc/profile" > $bashrc
    echo "test -e ~/.alias && . ~/.alias" >> $bashrc
#    echo "umask 022" >> $bashrc
    echo "umask 002" >> $bashrc
    echo "PS1='GRASS:\w > '" >> $bashrc

    if [ -r $USERHOME/.grass.bashrc ]
    then
        cat $USERHOME/.grass.bashrc >> $bashrc
    fi

    echo "export PATH=$PATH" >> $bashrc
    echo "export HOME=$USERHOME" >> $bashrc # restore user home path

    $ETC/run $SHELL
    HOME=$USERHOME
    export HOME
    ;;

*)

PS1="
Mapset <$MAPSET> in Location <$LOCATION_NAME>
GRASS-GRID > "

    export PS1

    $ETC/run $SHELL
    ;;
esac

trap 2 3

# Grass session finished
clear
echo "Cleaning up temporary files....."

($ETC/clean_temp > /dev/null &)
rm -f $lockfile

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



---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list