Quellcode durchsuchen

- revise the stderr processing of run-command processor in case of -d/--debug - add -k/--keep option to run-command processor for debug purposes Submitted by: Christian Reiber <chrei@krischan.org>

Ralf S. Engelschall vor 21 Jahren
Ursprung
Commit
2e1228a7eb
4 geänderte Dateien mit 91 neuen und 28 gelöschten Zeilen
  1. 2 0
      openpkg/HISTORY
  2. 80 23
      openpkg/rc
  3. 5 3
      openpkg/rc.8
  4. 4 2
      openpkg/rc.pod

+ 2 - 0
openpkg/HISTORY

@@ -2,6 +2,8 @@
 2004
 ====
 
+20040604 revise the stderr processing of run-command processor in case of -d/--debug
+20040604 add -k/--keep option to run-command processor for debug purposes
 20040604 add GNU bash 2.05b vendor patches 001-007
 20040604 port to HP-UX 11.11 platform
 20040602 upgrade to cURL 7.12.0

+ 80 - 23
openpkg/rc

@@ -64,6 +64,7 @@ silent=0
 verbose=0
 debug=0
 help=0
+keep=0
 print=0
 eval=0
 config=0
@@ -81,6 +82,7 @@ while [ $# -gt 0 ]; do
         -v|--verbose ) verbose=1     ;;
         -d|--debug   ) debug=1       ;;
         -h|--help    ) help="Usage"  ;;
+        -k|--keep    ) keep=1        ;;
         -p|--print   ) print=1       ;;
         -e|--eval    ) eval=1        ;;
         -c|--config  ) config=1      ;;
@@ -96,7 +98,7 @@ if [ ".$help" != .0 ]; then
     if [ ".$help" != ".Usage" ]; then
         echo "$progname:ERROR: $help" 1>&2
     fi
-    echo "Usage: $progname [-s|--silent] [-v|--verbose] [-d|--debug] [-h|--help]" 1>&2
+    echo "Usage: $progname [-s|--silent] [-v|--verbose] [-d|--debug] [-k|--keep] [-h|--help]" 1>&2
     echo "       [-p|--print] [-e|--eval] [-c|--config] [-q|--query]" 1>&2
     echo "       <package> <command> [<command> ...]"  1>&2
     if [ ".$help" != ".Usage" ]; then
@@ -411,8 +413,13 @@ for cmd in $cmds; do
         echo ". $rcconf" >>$tmpfile
 
         #   for --eval redirect stderr and stdout (but remember stdout)
+        #   (let stderr pass unfiltered in case of debug mode)
         if [ ".$eval" = .1 ]; then
-            echo "exec 3<&1- 1>/dev/null 2>/dev/null" >>$tmpfile
+            if [ ".$debug" = .1 ]; then
+               echo "exec 3<&1- 1>/dev/null" >>$tmpfile
+            else
+               echo "exec 3<&1- 1>/dev/null 2>/dev/null" >>$tmpfile
+            fi
         fi
     fi
 
@@ -507,9 +514,17 @@ for cmd in $cmds; do
             #   execute the generated script with GNU Bash
             if [ ".$user" != ".$s_user" ]; then
                 #   execute as different user
+                if [ ".$verbose" = .1 ]; then
+                    echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: executing as user $s_user"
+                fi 
                 if [ ".$user" = ".@l_susr@" -a ".@l_susr@" = ".root" ]; then
-                    su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
-                    rc=$?
+                    if [ ".$debug" = .1 ]; then
+                        su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile
+                        rc=$?
+                    else
+                        su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
+                        rc=$?
+                    fi
                 elif [ ".@l_susr@" != ".root" ]; then
                     #   do not complain if we would not have any chance
                     #   at all to switch the user because we are running
@@ -523,8 +538,16 @@ for cmd in $cmds; do
                 fi
             else
                 #   execute as current user
-                $bash $tmpfile >$outfile 2>$errfile
-                rc=$?
+                if [ ".$verbose" = .1 ]; then
+                    echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: executing as user $user"
+                fi 
+                if [ ".$debug" = .1 ]; then
+                    $bash $tmpfile >$outfile
+                    rc=$?
+                else
+                    $bash $tmpfile >$outfile 2>$errfile
+                    rc=$?
+                fi
             fi
             if [ $rc -ne 0 ]; then
                 if [ ".$silent" = .0 ]; then
@@ -533,17 +556,33 @@ for cmd in $cmds; do
                     verbose_pos=0
                 fi
                 #   give details of execution failure
-                ( echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: failed with return code $rc" 1>&2
+                ( echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: failed with return code $rc"
                   if [ ".`cat $outfile $errfile`" != . ]; then
-                      echo "+----Log:--------------------------------------------------------------"
+                      echo "openpkg:rc:NOTICE: output from stdout/stderr is following:"
+                      echo "+----------------------------------------------------------------------"
                       cat $outfile $errfile | sed -e 's;^;| ;'
                       echo "+----------------------------------------------------------------------"
+                  else
+                      echo "openpkg:rc:NOTICE: no output occurred on stdout/stderr"
                   fi
                 ) 1>&2
 
                 #   enforce global return value
                 rv=1
             else
+                #   give details of execution success in case verbose operation is requested
+                if [ ".$verbose" = .1 ]; then
+                    ( echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: succeeded with return code $rc"
+                      if [ ".`cat $outfile $errfile`" != . ]; then
+                          echo "openpkg:rc:NOTICE: output from stdout/stderr is following:"
+                          echo "+----------------------------------------------------------------------"
+                          cat $outfile $errfile | sed -e 's;^;| ;'
+                          echo "+----------------------------------------------------------------------"
+                      else
+                          echo "openpkg:rc:NOTICE: no output occurred on stdout/stderr"
+                      fi
+                    ) 1>&2
+                fi
                 if [ ".$s_output" = .yes ]; then
                     #   accumulate script output for later display
                     cat $outfile >>$allfile
@@ -580,17 +619,32 @@ for cmd in $cmds; do
 
         #   now replace temporary script with its output
         #   by executing it and capturing its output
-        env -i \
-            HOME="$HOME" \
-            USER="$USER" \
-            LOGNAME="$LOGNAME" \
-            TERM="$TERM" \
-            PATH="$PATH_ORIG" \
-            MANPATH="$MANPATH" \
-            INFOPATH="$INFOPATH" \
-            LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
-            $bash --norc --noprofile --posix \
-            $tmpfile >$outfile 2>/dev/null
+        #   (let stderr pass unfiltered in case of debug mode)
+        if [ ".$debug" = .1 ]; then
+            env -i \
+                HOME="$HOME" \
+                USER="$USER" \
+                LOGNAME="$LOGNAME" \
+                TERM="$TERM" \
+                PATH="$PATH_ORIG" \
+                MANPATH="$MANPATH" \
+                INFOPATH="$INFOPATH" \
+                LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
+                $bash --norc --noprofile --posix \
+                $tmpfile >$outfile
+        else
+            env -i \
+                HOME="$HOME" \
+                USER="$USER" \
+                LOGNAME="$LOGNAME" \
+                TERM="$TERM" \
+                PATH="$PATH_ORIG" \
+                MANPATH="$MANPATH" \
+                INFOPATH="$INFOPATH" \
+                LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
+                $bash --norc --noprofile --posix \
+                $tmpfile >$outfile 2>/dev/null
+        fi
         cp $outfile $tmpfile
 
         #   for --eval we cannot just print the resulting script because
@@ -622,10 +676,13 @@ done
 
 #   cleanup temporary files except the result script in
 #   case of --eval (which is then removed by the caller).
-rm -f $outfile $errfile $allfile >/dev/null 2>&1 || true
-if [ ".$eval" = .0 ]; then
-    rm -f $tmpfile >/dev/null 2>&1 || true
-    rm -rf $tmpdir >/dev/null 2>&1 || true
+#   keep those files for debugging purposes if requested.
+if [ ".$keep" = .0 ]; then
+    rm -f $outfile $errfile $allfile >/dev/null 2>&1 || true
+    if [ ".$eval" = .0 ]; then
+        rm -f $tmpfile >/dev/null 2>&1 || true
+        rm -rf $tmpdir >/dev/null 2>&1 || true
+    fi
 fi
 
 #   now clean the exit trap and exit with the global return value

+ 5 - 3
openpkg/rc.8

@@ -134,7 +134,7 @@
 \&\fB@l_prefix@/etc/rc\fR \- OpenPKG Run\-Command Processor
 .SH "SYNOPSIS"
 .IX Header "SYNOPSIS"
-\&\fB@l_prefix@/etc/rc\fR [\fB\-s\fR|\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-d\fR|\fB\-\-debug\fR] \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]
+\&\fB@l_prefix@/etc/rc\fR [\fB\-s\fR|\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-d\fR|\fB\-\-debug\fR] [\fB\-k\fR|\fB\-\-keep\fR] \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]
 .PP
 \&\fB@l_prefix@/etc/rc\fR \fB\-p\fR|\fB\-\-print\fR \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]
 .PP
@@ -157,8 +157,8 @@ run-command facilities. It mainly merges the classical startup/shutdown
 procedures with periodical procedures into a single approach.
 .SH "USAGE"
 .IX Header "USAGE"
-.IP "\fB@l_prefix@/etc/rc\fR [\fB\-s\fR|\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-d\fR|\fB\-\-debug\fR] \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]" 4
-.IX Item "@l_prefix@/etc/rc [-s|--silent] [-v|--verbose] [-d|--debug] package command [command ...]"
+.IP "\fB@l_prefix@/etc/rc\fR [\fB\-s\fR|\fB\-\-silent\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-d\fR|\fB\-\-debug\fR] [\fB\-k\fR|\fB\-\-keep\fR] \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]" 4
+.IX Item "@l_prefix@/etc/rc [-s|--silent] [-v|--verbose] [-d|--debug] [-k|--keep] package command [command ...]"
 \&\fBRun-Command Execution.\fR This executes one or more specified
 \&\fIcommand\fRs in a particular \fIpackage\fR or in all installed packages if
 \&\fIpackage\fR is "\f(CW\*(C`all\*(C'\fR". Option \fB\-\-silent\fR can be used to explicitly
@@ -166,6 +166,8 @@ disable progress messages on \f(CW\*(C`stderr\*(C'\fR. Option \fB\-\-verbose\fR
 to explicitly enable progress messages on \f(CW\*(C`stderr\*(C'\fR. By default, \fBrc\fR
 automatically determines whether progress messages should be displayed
 or not depending on whether \f(CW\*(C`stderr\*(C'\fR is connected to a terminal device.
+Option \fB\-\-keep\fR can be used for debugging purposes to keep the
+temporary files were generated during internal processing.
 .IP "\fB@l_prefix@/etc/rc\fR \fB\-p\fR|\fB\-\-print\fR \fIpackage\fR \fIcommand\fR [\fIcommand\fR ...]" 4
 .IX Item "@l_prefix@/etc/rc -p|--print package command [command ...]"
 \&\fBRun-Command Printing.\fR This is like the run-command execution (see

+ 4 - 2
openpkg/rc.pod

@@ -31,7 +31,7 @@ B<@l_prefix@/etc/rc> - OpenPKG Run-Command Processor
 
 =head1 SYNOPSIS
 
-B<@l_prefix@/etc/rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] I<package> I<command> [I<command> ...]
+B<@l_prefix@/etc/rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] [B<-k>|B<--keep>] I<package> I<command> [I<command> ...]
 
 B<@l_prefix@/etc/rc> B<-p>|B<--print> I<package> I<command> [I<command> ...]
 
@@ -58,7 +58,7 @@ procedures with periodical procedures into a single approach.
 
 =over 4
 
-=item B<@l_prefix@/etc/rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] I<package> I<command> [I<command> ...]
+=item B<@l_prefix@/etc/rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] [B<-k>|B<--keep>] I<package> I<command> [I<command> ...]
 
 B<Run-Command Execution.> This executes one or more specified
 I<command>s in a particular I<package> or in all installed packages if
@@ -67,6 +67,8 @@ disable progress messages on C<stderr>. Option B<--verbose> can be used
 to explicitly enable progress messages on C<stderr>. By default, B<rc>
 automatically determines whether progress messages should be displayed
 or not depending on whether C<stderr> is connected to a terminal device.
+Option B<--keep> can be used for debugging purposes to keep the
+temporary files were generated during internal processing.
 
 =item B<@l_prefix@/etc/rc> B<-p>|B<--print> I<package> I<command> [I<command> ...]