"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.6.2/tools/tinlock" (23 Aug 2021, 1413 Bytes) of package /linux/misc/tin-2.6.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /bin/sh
    2 # wrapper to prevent running multiple instances of tin
    3 # 2000-01-19 <urs@tin.org>
    4 
    5 prog=/usr/local/bin/tin
    6 
    7 args=${1+"$@"}
    8 
    9 name=`basename $prog`
   10 host=`hostname`
   11 pid=$$
   12 lock=$host" "$pid
   13 
   14 if test -d ${TIN_HOMEDIR-"$HOME"} ; then
   15     lockdir=${TIN_HOMEDIR-"$HOME"}/.tin
   16     file=tinlock
   17 else
   18     lockdir=${TMPDIR-/tmp}
   19     if test -z $USER; then
   20         if test -z $UID ; then
   21             UID=`id|sed 's,uid=\([0-9]\+\).*,\1,'`
   22         fi
   23     fi
   24     file=tinlock.${USER-"$UID"}
   25 fi
   26 
   27 lockfile=$lockdir/$file
   28 
   29 if test -f $lockfile ; then
   30     echo "Found \"$lockfile\"! Another $name running on:"
   31     awk '{print $1" with pid: "$2"?"}' < $lockfile
   32     echo "(q)uit - start (r)ead-only - (d)elete lock and start normal."
   33     IFS="       " read key
   34     case $key in
   35         [dD]*)
   36             echo "Removing \"$lockfile\" and starting $name normal..."
   37             rm -f $lockfile || (echo "Can't delete \"$lockfile\"" ; exit 1)
   38             trap "rm -f $lockfile; exit" 0 1 2 3 15
   39             (echo $lock > $lockfile && $prog $args && rm -f $lockfile) || echo "Oops!"
   40             ;;
   41         [rR]*)
   42             echo "Starting $name in no-write (-X) mode..."
   43             $prog -X $args
   44             echo "There might still be copy(s) of $name running on:"
   45             awk '{print $1" with pid: "$2}' < $lockfile
   46             echo "If this is not the case remember to remove \"$lockfile\"."
   47             ;;
   48         *)
   49             echo "Aborting..."
   50             exit 1
   51             ;;
   52     esac
   53 else
   54     trap "rm -f $lockfile; exit" 0 1 2 3 15
   55     (echo $lock > $lockfile && $prog $args && rm -f $lockfile) || echo "Oops!"
   56 fi