bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

adding a new CVS_PID environment variable


From: Mark D. Baushke
Subject: adding a new CVS_PID environment variable
Date: Wed, 12 Feb 2003 13:04:25 -0800

Hi Folks,

The FreeBSD folks have had a CVS_PID environment variable in their
version of cvs since 1997-05-15 and they got it from the OpenBSD folks
before that. It is a simple addition. Here is my port of this feature.

The sanity.sh test is a bit more convoluted than I would like, if there
any suggestions for making it simpler or more robust, please let me
know.

        Comments?
        -- Mark

Index: doc/cvs.texinfo
===================================================================
RCS file: /cvs/ccvs/doc/cvs.texinfo,v
retrieving revision 1.552
diff -u -p -r1.552 cvs.texinfo
--- doc/cvs.texinfo     10 Feb 2003 18:51:29 -0000      1.552
+++ doc/cvs.texinfo     12 Feb 2003 20:53:37 -0000
@@ -13699,6 +13699,14 @@ if your server and client are both runni
 @code{patch} program.
 @end table
 
+@cindex CVS_PID, environment variable
+@item $CVS_PID
+This is the process identification (aka pid) number of
+the @sc{cvs} process. It is often useful in the
+programs and/or scripts specified by the
+@file{commitinfo}, @file{verifymsg}, @file{loginfo}
+files.
+
 @node Compatibility
 @appendix Compatibility between CVS Versions
 
Index: src/ChangeLog
===================================================================
RCS file: /cvs/ccvs/src/ChangeLog,v
retrieving revision 1.2352
diff -u -p -r1.2352 ChangeLog
--- src/ChangeLog       9 Feb 2003 04:13:27 -0000       1.2352
+++ src/ChangeLog       12 Feb 2003 20:53:37 -0000
@@ -1,3 +1,10 @@
+2003-02-12  Mark D. Baushke  <mdb@cvshome.org>
+
+       * cvs.h (CVS_PID_ENV): New environment variable CVS_PID has the
+       pid of the parent cvs process.
+       * main.c (main): Initialize it.
+       * sanity.sh (env): Test it.
+ 
 2003-02-08  Derek Price  <derek@ximbiot.com>
 
        * rcs.c (RCS_checkout): Supply the full function name in the TRACE
Index: src/cvs.h
===================================================================
RCS file: /cvs/ccvs/src/cvs.h,v
retrieving revision 1.239
diff -u -p -r1.239 cvs.h
--- src/cvs.h   7 Feb 2003 19:53:30 -0000       1.239
+++ src/cvs.h   12 Feb 2003 20:53:37 -0000
@@ -314,6 +314,7 @@ extern int errno;
 #define        CVSREAD_DFLT    0               /* writable files by default */
 
 #define        TMPDIR_ENV      "TMPDIR"        /* Temporary directory */
+#define        CVS_PID_ENV     "CVS_PID"       /* pid of running cvs */
 
 #define        EDITOR1_ENV     "CVSEDITOR"     /* which editor to use */
 #define        EDITOR2_ENV     "VISUAL"        /* which editor to use */
Index: src/main.c
===================================================================
RCS file: /cvs/ccvs/src/main.c,v
retrieving revision 1.174
diff -u -p -r1.174 main.c
--- src/main.c  3 Feb 2003 17:53:23 -0000       1.174
+++ src/main.c  12 Feb 2003 20:53:37 -0000
@@ -747,6 +747,14 @@ Copyright (c) 1989-2002 Brian Berliner, 
            (void) putenv (env);
            /* do not free env, as putenv has control of it */
        }
+       {
+           char *env;
+           /* XXX pid < 10^32 */
+           env = xmalloc (strlen (CVS_PID_ENV) + 1 + 32 + 1);
+           (void) sprintf (env, "%s=%ld", CVS_PID_ENV, (long) getpid ());
+           (void) putenv (env);
+           /* do not free env, as putenv has control of it */
+       }
 #endif
 
 #ifndef DONT_USE_SIGNALS
Index: src/sanity.sh
===================================================================
RCS file: /cvs/ccvs/src/sanity.sh,v
retrieving revision 1.757
diff -u -p -r1.757 sanity.sh
--- src/sanity.sh       9 Feb 2003 04:13:28 -0000       1.757
+++ src/sanity.sh       12 Feb 2003 20:53:38 -0000
@@ -688,7 +688,7 @@ if test x"$*" = x; then
        tests="${tests} cvsadm emptydir abspath toplevel toplevel2"
         tests="${tests} checkout_repository"
        # Log messages, error messages.
-       tests="${tests} mflag editor errmsg1 errmsg2 adderrmsg"
+       tests="${tests} mflag editor env errmsg1 errmsg2 adderrmsg"
        # Watches, binary files, history browsing, &c.
        tests="${tests} devcom devcom2 devcom3 watch4 watch5"
        tests="${tests} unedit-without-baserev"
@@ -12367,6 +12367,107 @@ Action: (continue) ${PROG} \[[a-z]* abor
          rm -r 1
          rm ${TESTDIR}/editme
          rm -rf ${CVSROOT_DIRNAME}/first-dir
+         ;;
+
+       env)
+         # Test to see if the CVS_PID environment variable is being set
+         # This will only work on systems with HAVE_PUTENV
+         mkdir ${TESTDIR}/env
+         cd ${TESTDIR}/env
+         if ${testcvs} -q co . >>${LOGFILE} ; then
+           pass env-1
+         else
+           fail env-1
+         fi
+
+         cat > ${TESTDIR}/env/test-cvs-pid <<EOF
+#!${TESTSHELL}
+if test "x\$CVS_PID" != "x"; then
+  # In local mode, there is no directory with the pid in it for use.
+  # In remote mode the CVS_PID will be the parent process of the
+  # cvs process that runs the commitinfo script.
+  if test "x$remote" = "x:" ; then
+    ppid=\`pwd | sed -e 's,.*/cvs-serv,,'\`
+  else
+    # This assumes that the -l switch puts PPID in the banner and does
+    # not run the elements together such that whitespace surrounds the
+    # pid and ppid in the output. This could be made slightly simpler
+    # if all hosts had a 'ps' command that supported the -p switch,
+    # but Solaris 7 /usr/ucb/ps does not and that may be the one we use.
+    # It is because this is so messy that the CVS_PID feature exists.
+    ppid=\`ps -l |\\
+    awk '/PPID/ { for (i=1; i <= NF; i++) {
+                    if (\$i == "PPID") ppidx = i; 
+                    if (\$i == "PID") pidx = i;
+                 }
+                  next; 
+                }
+                { print \$pidx " " \$ppidx }' |\\
+    grep "^\$\$ " |\\
+    awk '{ print \$NF }'\`
+  fi
+  if test \$ppid = \${CVS_PID}; then
+    # The PID looks okay to me
+    exit 0
+  else
+    echo The environment variable CVS_PID is not properly set.
+    echo It should have been set to \$ppid but instead was \$CVS_PID
+    echo It is possible that this test is broken for your host.
+    echo Here is the output of the ps -l command:
+    ps -l
+    exit 1
+  fi
+else
+  # The environment variable CVS_PID is not set.
+  # FIXME. This problem be ignored if HAVE_PUTENV is not available and
+  # configured for this host, but this script does not know how cvs
+  # was built.
+  exit 0
+fi
+EOF
+         chmod +x ${TESTDIR}/env/test-cvs-pid
+         cd CVSROOT
+         echo "^env ${TESTDIR}/env/test-cvs-pid" >>commitinfo
+         dotest env-2 "${testcvs} -q ci -m test-pid commitinfo" \
+"Checking in commitinfo;
+${CVSROOT_DIRNAME}/CVSROOT/commitinfo,v  <--  commitinfo
+new revision: 1\.2; previous revision: 1\.1
+done
+${PROG} [a-z]*: Rebuilding administrative file database"
+         cd ..
+         mkdir env
+         dotest env-3 "${testcvs} -q add env" \
+"Directory ${CVSROOT_DIRNAME}/env added to the repository"
+         cd env
+         echo testing >file1
+         dotest env-4 "${testcvs} add file1" \
+"${PROG} [a-z]*: scheduling file .file1. for addition
+${PROG} [a-z]*: use .${PROG} commit. to add this file permanently"
+         dotest env-5 "${testcvs} -q commit -m test-pid" \
+"RCS file: ${CVSROOT_DIRNAME}/env/file1,v
+done
+Checking in file1;
+${CVSROOT_DIRNAME}/env/file1,v  <--  file1
+initial revision: 1\.1
+done"
+
+         if $keep; then
+           echo Keeping ${TESTDIR} and exiting due to --keep
+           exit 0
+         fi
+
+         # undo commitinfo changes
+         cd ../CVSROOT
+         dotest env-cleanup-1 "${testcvs} -q admin -o1.2 commitinfo" \
+"RCS file: ${CVSROOT_DIRNAME}/CVSROOT/commitinfo,v
+deleting revision 1\.2
+done"
+         chmod u+w ${CVSROOT_DIRNAME}/CVSROOT/commitinfo
+         echo '# vanilla commitinfo' >${CVSROOT_DIRNAME}/CVSROOT/commitinfo
+         chmod u-w ${CVSROOT_DIRNAME}/CVSROOT/commitinfo
+
+         cd ../..
+         rm -fr ${TESTDIR}/env ${CVSROOT_DIRNAME}/env
          ;;
 
        errmsg1)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]