bug-cvs
[Top][All Lists]
Advanced

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

Re: adding a new CVS_PID environment variable


From: Mark D. Baushke
Subject: Re: adding a new CVS_PID environment variable
Date: Sun, 09 Mar 2003 22:23:21 -0800

Larry Jones <lawrence.jones@eds.com> writes:

> Mark D. Baushke writes:
> > 
> > The extra processing consists of a getpid() call that is already being
> > done in the server side of the code and a setenv() call so that children
> > processes inherit the environment variable. If this is too much, I
> > suppose a configure option could be introduced to do this extra work
> > only when the user wants it done and it could default to off.
> 
> I'm convinced this is worth doing.  As you say, we're already doing the
> getpid() call to name the server's temp directory, so all that's needed
> is to add the call to putenv() to stuff it in the environment.  I'd say
> go ahead and do it (just be sure to check for HAVE_PUTENV around the
> call).

A current snapshot of the patch against top-of-tree follows my .signature

My biggest problem is that I am not sure that the sanity.sh changes will
actually work on all of our target platforms. Certainly, they will have
some problems when HAVE_PUTENV is not set. I have no good ideas for how
to detect that condition in the sanity.sh script. I am also not sure of
the right way to detect that the output of 'ps -l' is not what is
expected... at least not without adding a LOT of configure-like tests
into the sanity.sh or moving to a sanity.sh.in that generates the
sanity.sh file...

I have verified correct behavior of the tests on FreeBSD 4.2-RELEASE
(i386), Solaris 7 (sparc), and Redhat 7.3 GNU/Linux (i686). If you
can throw it in for testing on any other box, that would be great.

Suggestions and comments are welcome.

        Thanks,
        -- Mark

doc/ChangeLog entry:
2003-03-09  Mark D. Baushke  <mdb@cvshome.org>

        * cvs.texinfo (Environment Variables): Document new CVS_PID 
        variable.

man/ChangeLog entry:
2003-03-09  Mark D. Baushke  <mdb@cvshome.org>

        * cvs.1 (Environment Variables): Document new CVS_PID variable.

src/ChangeLog entry:
2003-03-09  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.

Index: doc/cvs.texinfo
===================================================================
RCS file: /cvs/ccvs/doc/cvs.texinfo,v
retrieving revision 1.559
diff -u -p -r1.559 cvs.texinfo
--- doc/cvs.texinfo     7 Mar 2003 19:27:56 -0000       1.559
+++ doc/cvs.texinfo     10 Mar 2003 06:05:52 -0000
@@ -13741,6 +13741,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: man/cvs.1
===================================================================
RCS file: /cvs/ccvs/man/cvs.1,v
retrieving revision 1.32
diff -u -p -r1.32 cvs.1
--- cvs.1       4 Mar 2003 22:56:19 -0000       1.32
+++ cvs.1       10 Mar 2003 06:15:18 -0000
@@ -2087,6 +2087,13 @@ the local repository, the revision numbe
 like 1.66.1000.xx. There is almost a dead-set certainty
 that there will be no conflicts with version numbers.
 .TP
+.SM CVS_PID
+This is the process identification (aka pid) number of the
+.B cvs
+process. It is often useful in the programs and/or scripts
+specified by the CVSROOT/commitinfo CVSROOT/verifymsg and
+CVSROOT/loginfo administrative files.
+.TP
 .SM CVS_RSH
 .B cvs
 uses the contents of this variable to determine the name of the
Index: src/cvs.h
===================================================================
RCS file: /cvs/ccvs/src/cvs.h,v
retrieving revision 1.242
diff -u -p -r1.242 cvs.h
--- src/cvs.h   7 Mar 2003 06:59:40 -0000       1.242
+++ src/cvs.h   10 Mar 2003 06:05:52 -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.175
diff -u -p -r1.175 main.c
--- src/main.c  13 Feb 2003 01:30:19 -0000      1.175
+++ src/main.c  10 Mar 2003 06:05:52 -0000
@@ -747,6 +747,14 @@ Copyright (c) 1989-2003 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.773
diff -u -p -r1.773 sanity.sh
--- src/sanity.sh       8 Mar 2003 06:33:13 -0000       1.773
+++ src/sanity.sh       10 Mar 2003 06:05:52 -0000
@@ -767,7 +767,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"
@@ -12692,6 +12692,100 @@ date: [0-9/]* [0-9:]*;  author: ${userna
          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"
+
+         dokeep
+
+         # undo commitinfo changes
+         cd ../CVSROOT
+         rm -fr ${CVSROOT_DIRNAME}/CVSROOT/commitinfo,v \
+                ${CVSROOT_DIRNAME}/CVSROOT/commitinfo
+         dotest env-cleanup-1 "${testcvs} -Q init" ''
+
+         cd ../..
+         rm -fr ${TESTDIR}/env ${CVSROOT_DIRNAME}/env
          ;;
 
        errmsg1)




reply via email to

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