[Debichem-devel] Bug#641470: Bug#641470: psi3 fails optimizing geometry

Michael Banck mbanck at debian.org
Mon Apr 8 13:08:36 UTC 2013


retitle 641470 psi3: segfault in testsuite
severity 641470 serious
tags 641470 +patch
thanks

Hi,

On Tue, Sep 13, 2011 at 06:10:59PM +0200, Georg wrote:
> Package: psi3
> Version: 3.4.0-2
> Severity: important
> 
> The contents of the input file, corresponding to the example in the user
> manual:
> 
> % 6-31G** H2O Test optimization calculation
> psi: (
> label = "6-31G** SCF H2O"
> jobtype = opt
> wfn = ccsd
> reference = rhf
> dertype = first
> basis = "6-31G**"
> num_threads = 4
> memory = (2048 MB)
> zmat = (
>     o
>     h 1 roh
>     h 1 roh 2 ahoh
>   )
> zvars = (
>     roh    0.96031231
>     ahoh 104.09437511
>   )
> )
> 
> The console messages:
> 
>  The PSI3 Execution Driver
> PSI3 will perform a RHF CCSD optimisation via analytic gradients.
> The following programs will be executed:
> input
> REPEAT 40
>  cints
>  cscf
>  transqt2
>  ccsort
>  ccenergy
>  cchbar
>  cclambda
>  ccdensity
>  oeprop
>  transqt --backtr
>  cints --deriv1
>  optking --opt_step
> END
> psiclean
> 
> input
> REPEAT 40
>  CYCLE 1
>  cints
>  cscf
>  transqt2
>  ccsort
>  ccenergy
>  cchbar
>  cclambda
>  ccdensity
>  oeprop
>  transqt --backtr
>  cints --deriv1
>  optking --opt_step
> 
> Command optking --opt_step was terminated with signal 11

I had another look at psi3 yesterday, trying to increase test suite
coverage to CCSD(T) (test case cc13a) and CASSCF (test case casscf-opt)
analytical gradients, when I noticed that the test suite already dies in
the cc1 test case for the current package, see e.g.:

https://buildd.debian.org/status/fetch.php?pkg=psicode&arch=i386&ver=3.4.0-3&stamp=1332980543

|...Testing cc1...
|make[3]: Entering directory
|`/build/buildd-psicode_3.4.0-3-i386-A_7Xen/psicode-3.4.0/tests/cc1'
|Psi3 failed!
|make[3]: *** [cc1.test] Error 1
|make[3]: Leaving directory
|`/build/buildd-psicode_3.4.0-3-i386-A_7Xen/psicode-3.4.0/tests/cc1'
|make[2]: *** [quicktests] Error 1

The reason appears to be the same as with this bug: if a longer sequence
of commands is run, a segfault will happen eventually.

After much analyzing and debugging, I finally found the problem today:
the Debian-specific patch 07_464867_move_executables.patch adds
"/usr/lib/psi" to the environment so the sub-commands to be executed are
found.  However, this is done every time a sub-command is run and
eventually the maximum environment variable length is reached, at which
point other environment variables get overwritten.  Once $HOME gets
overwritten (and thus removed from the environment), the configuration
file handling in ~/.psirc in src/lib/libciomr/psi_start.cc and
src/lib/libpsio/ipv1_config.cc segfaults due to this code:

    userhome = getenv("HOME");
    cfname = (char *) malloc((10+strlen(userhome))*sizeof(char));

Probably psi3 should check for the return value of getenv, but certainly
we should not overwrite the environment.

The attached patch to 07_464867_move_executables.patch fixes this
problem by checking for the presence of /usr/lib/psi before adding it to
environment variable.  Both the test suite (cc1/cc13a) and the provided
example in this bug are running fine for me with this patch.


Cheers,

Michael
-------------- next part --------------
Index: patches/07_464867_move_executables.patch
===================================================================
--- patches/07_464867_move_executables.patch	(Revision 4169)
+++ patches/07_464867_move_executables.patch	(Arbeitskopie)
@@ -3,16 +3,20 @@
  are found.
 Bug-Debian: http://bugs.debian.org/464867
 
---- psicode-3.4.0.orig/src/bin/psi3/runcmd.cc
-+++ psicode-3.4.0/src/bin/psi3/runcmd.cc
-@@ -14,6 +14,11 @@
+Index: psicode-3.4.0/src/bin/psi3/runcmd.cc
+===================================================================
+--- psicode-3.4.0.orig/src/bin/psi3/runcmd.cc	2013-04-08 13:53:13.446693968 +0200
++++ psicode-3.4.0/src/bin/psi3/runcmd.cc	2013-04-08 13:54:54.059211598 +0200
+@@ -14,6 +14,13 @@
  void runcmd(int *errcod, char *cmd)
  {
  
 +  /* Debian places the helper executables into /usr/lib/psi */
 +  char *path = getenv("PATH");
-+  strcat(path, ":/usr/lib/psi");
-+  putenv(path);
++  if (strstr(path, "/usr/lib/psi") == NULL) {
++    strcat(path, ":/usr/lib/psi");
++    putenv(path);
++  }
 +
    /*
    i = system(cmd);


More information about the Debichem-devel mailing list