Testsuite: perl version oddity
[exim.git] / src / src / exicyclog.src
index 3fdcf4ffdcb4bf8738065d73c6570ba6abd5e52d..e807099c1470e200f78f8f16189ccf14bd64b9c4 100644 (file)
@@ -1,8 +1,9 @@
 #! /bin/sh
-# $Cambridge: exim/src/src/exicyclog.src,v 1.5 2006/03/16 11:51:10 ph10 Exp $
 
-# Copyright (c) 2006 University of Cambridge.
+# Copyright (c) The Exim Maintainers 2023
+# Copyright (c) University of Cambridge, 1995 - 2015
 # See the file NOTICE for conditions of use and distribution.
+# SPDX-License-Identifier: GPL-2.0-or-later
 
 # This script takes the following command line arguments:
 # -l dir       Log file directory
@@ -20,6 +21,8 @@
 # COMPRESS_SUFFIX
 # CHOWN_COMMAND
 # CHGRP_COMMAND
+# CHMOD_COMMAND
+# TOUCH_COMMAND
 # MV_COMMAND
 # RM_COMMAND
 
@@ -51,10 +54,12 @@ keep=EXICYCLOG_MAX
 compress=COMPRESS_COMMAND
 suffix=COMPRESS_SUFFIX
 
-chown=CHOWN_COMMAND
 chgrp=CHGRP_COMMAND
+chmod=CHMOD_COMMAND
+chown=CHOWN_COMMAND
 mv=MV_COMMAND
 rm=RM_COMMAND
+touch=TOUCH_COMMAND
 
 # End of editable lines
 #########################################################################
@@ -69,6 +74,11 @@ while [ $# -gt 0 ] ; do
   -k) keep=$2
       shift
       ;;
+   --version|-v)
+      echo "`basename $0`: $0"
+      echo "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION"
+      exit 0
+      ;;
    *) echo "** exicyclog: unknown option $1"
       exit 1
       ;;
@@ -80,7 +90,7 @@ done
 # in different places. We have a fudge that will search the usual suspects if
 # requested.
 
-for cmd in chown chgrp mv rm ; do
+for cmd in chgrp chmod chown mv rm touch; do
   eval "oldcmd=\$$cmd"
   if [ "$oldcmd" != "look_for_it" ] ; then continue ; fi
   newcmd=$cmd
@@ -183,11 +193,13 @@ if [ "$log_file_path" = "" ]; then
   logdir=$spool_directory/log
   mainlog=mainlog
   rejectlog=rejectlog
+  paniclog=paniclog
 else
   logdir=`echo $log_file_path | sed 's?/[^/]*$??'`
   logbase=`echo $log_file_path | sed 's?^.*/??'`
   mainlog=`echo $logbase | sed 's/%s/main/'`
   rejectlog=`echo $logbase | sed 's/%s/reject/'`
+  paniclog=`echo $logbase | sed 's/%s/panic/'`
 fi
 
 # Get into the log directory to do the business.
@@ -227,13 +239,16 @@ $b
 # Now do the job. First remove the files that have "fallen off the bottom".
 # Look for both the compressed and uncompressed forms.
 
-if [ $keep -lt 10 ]; then keept=0$keep; else keept=$keep; fi;
+if [ $keep -lt 10 ]; then rotation=0$keep; else rotation=$keep; fi;
 
-if [ -f $mainlog.$keept ]; then $rm $mainlog.$keept; fi;
-if [ -f $mainlog.$keept.$suffix ]; then $rm $mainlog.$keept.$suffix; fi;
+if [ -f $mainlog.$rotation ]; then $rm $mainlog.$rotation; fi;
+if [ -f $mainlog.$rotation.$suffix ]; then $rm $mainlog.$rotation.$suffix; fi;
 
-if [ -f $rejectlog.$keept ]; then $rm $rejectlog.$keept; fi;
-if [ -f $rejectlog.$keept.$suffix ]; then $rm $rejectlog.$keept.$suffix; fi;
+if [ -f $rejectlog.$rotation ]; then $rm $rejectlog.$rotation; fi;
+if [ -f $rejectlog.$rotation.$suffix ]; then $rm $rejectlog.$rotation.$suffix; fi;
+
+if [ -f $paniclog.$rotation ]; then $rm $paniclog.$rotation; fi;
+if [ -f $paniclog.$rotation.$suffix ]; then $rm $paniclog.$rotation.$suffix; fi;
 
 # Now rename all the previous old files by increasing their numbers by 1.
 # When the number is less than 10, insert a leading zero.
@@ -242,7 +257,7 @@ count=$keep
 if [ $count -lt 10 ]; then countt=0$count; else countt=$count; fi
 
 while [ $count -gt 1 ]; do
-  old=`expr $count - 1`
+  old=`expr -- $count - 1`
   if [ $keep -gt 99 ]; then
     if   [ $old -lt 10 ]; then oldt=00$old
     elif [ $old -lt 100 ]; then oldt=0$old
@@ -261,6 +276,11 @@ while [ $count -gt 1 ]; do
   elif [ -f $rejectlog.$oldt.$suffix ]; then
     $mv $rejectlog.$oldt.$suffix $rejectlog.$countt.$suffix
   fi
+  if [ -f $paniclog.$oldt ]; then
+    $mv $paniclog.$oldt $paniclog.$countt
+  elif [ -f $paniclog.$oldt.$suffix ]; then
+    $mv $paniclog.$oldt.$suffix $paniclog.$countt.$suffix
+  fi
   count=$old
   countt=$oldt
 done
@@ -269,14 +289,34 @@ done
 
 if [ $keep -gt 99 ]; then first=001; else first=01; fi
 
+# Grab our pid ro avoid race in file creation
+ourpid=$$
+
 if [ -f $mainlog ]; then
   $mv $mainlog $mainlog.$first
   $chown $user:$group $mainlog.$first
+  $touch $mainlog.$ourpid
+  $chown $user:$group $mainlog.$ourpid
+  $chmod 640 $mainlog.$ourpid
+  $mv $mainlog.$ourpid $mainlog
 fi
 
 if [ -f $rejectlog ]; then
   $mv $rejectlog $rejectlog.$first
   $chown $user:$group $rejectlog.$first
+  $touch $rejectlog.$ourpid
+  $chown $user:$group $rejectlog.$ourpid
+  $chmod 640 $rejectlog.$ourpid
+  $mv $rejectlog.$ourpid $rejectlog
+fi
+
+if [ -f $paniclog ]; then
+  $mv $paniclog $paniclog.$first
+  $chown $user:$group $paniclog.$first
+  $touch $paniclog.$ourpid
+  $chown $user:$group $paniclog.$ourpid
+  $chmod 640 $paniclog.$ourpid
+  $mv $paniclog.$ourpid $paniclog
 fi
 
 # Now scan the (0)02 and later files, compressing where necessary, and
@@ -301,7 +341,12 @@ while [ $count -le $keep ]; do
   if [ -f $rejectlog.$countt.$suffix ]; then
     $chown $user:$group $rejectlog.$countt.$suffix
   fi
-  count=`expr $count + 1`
+  if [ -f $paniclog.$countt ]; then $compress $paniclog.$countt; fi
+  if [ -f $paniclog.$countt.$suffix ]; then
+    $chown $user:$group $paniclog.$countt.$suffix
+  fi
+
+  count=`expr -- $count + 1`
 done
 
 # End of exicyclog