Am Sonntag, 6. August 2017 um 21:55:57, schrieb Scott Kostyshak 
<skost...@lyx.org>
> On Sun, Aug 06, 2017 at 10:17:16AM +0200, Kornel Benko wrote:
>
> > This should not happen. The check for the need of reconfiguration is done 
> > at LyX.cpp:1053
> >     bool LyX::queryUserLyXDir(bool explicit_userdir)
> > which is called at LyX.cpp:921.
> > This call is guarded with fileLock(lock_file.c_str());
> > And the reconfiguration is done in the same guard.
> >         {
> >                 string const lock_file = package().getConfigureLockName();
> >                 int fd = fileLock(lock_file.c_str());
> >
> >                 if (queryUserLyXDir(package().explicit_user_support())) {
> >                         package().reconfigureUserLyXDir("");
> >                         // Now the user directory is present on first start.
> >                         initTemplatePath();
> >                 }
> >                 fileUnlock(fd, lock_file.c_str());
> >         }
>
> Thanks for that clue. Attached is a patch that I used for debugging to figure
> out what is calling configure.py. Running the parallel ctests (with many jobs)
> with the patch applied, gave the following files on my desktop:
>
>     callingconfig_47059
>     configurepy_46743_ppid46728
>     configurepy_47073_ppid47059
>
> Already we can see that the LyX binary calls configure.py once (assuming that
> the LyX binary can only call it from that function), and that configure.py was
> called twice.
>
>     $ cat configurepy_46743_ppid46728
>     command_ is /usr/bin/python3 -tt 
> /home/scott/lyxbuilds/master/repo/lib/scripts/../configure.py 
> --binary-dir=/home/scott/lyxbuilds/master/CMakeBuild/bin/
>     pcommand_ is /usr/bin/cmake 
> -DLYX_TESTS_USERDIR=/home/scott/lyxbuilds/master/CMakeBuild/Testing/.lyx 
> -DLYX_USERDIR_VER=LYX_USERDIR_23x -DLYX_PYTHON_EXECUTABLE=/usr/bin/python3 
> -DPY_SCRIPT=/home/scott/lyxbuilds/master/repo/src/tex2lyx/test/runtests.py 
> -DTEX2LYX_EXE=/home/scott/lyxbuilds/master/CMakeBuild/bin/tex2lyx 
> -DSCRIPT_DIR=/home/scott/lyxbuilds/master/repo/lib/scripts 
> -DWORKDIR=/home/scott/lyxbuilds/master/CMakeBuild/src/tex2lyx/test 
> -DTESTFILE=test.ltx -P 
> /home/scott/lyxbuilds/master/repo/src/tex2lyx/test/runtests.cmake
>
>     $ cat configurepy_47073_ppid47059
>     command_ is python -tt /home/scott/lyxbuilds/master/repo/lib/configure.py 
> --binary-dir=/home/scott/lyxbuilds/master/CMakeBuild/bin/
>     pcommand_ is /home/scott/lyxbuilds/master/CMakeBuild/bin/lyx -batch 
> -userdir /home/scott/lyxbuilds/master/CMakeBuild/Testing/.lyx 
> /home/scott/lyxbuilds/master/repo/autotests/export/MissingEndLayoutBetweenTables.lyx
>
> I'm not sure how to proceed to make _configure_needed more robust inside
> runtests.cmake.
>
> Is an alternative to make configure.py thread safe (is this a correct use of 
> the
> term?) itself by having a lock inside of it?

Searching for calls to configGileNeedsUpdate() I came across the file 
tex2lyx.cpp.
The test there is not complete compared to the one in LyX.cpp, see patch 
001-tex2lyx.cpp.patch.

In src/support/filetools.cpp, we could check if the locking was successful.

I'm running the tests now, we may have some luck.

> Scott

        Kornel
diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index 3c0bf81..fc6ea1e 100644
--- a/src/tex2lyx/tex2lyx.cpp
+++ b/src/tex2lyx/tex2lyx.cpp
@@ -1060,7 +1060,9 @@ int TeX2LyXApp::run()
 		if (configFileNeedsUpdate("lyxrc.defaults") ||
 		    configFileNeedsUpdate("lyxmodules.lst") ||
 		    configFileNeedsUpdate("textclass.lst") ||
-		    configFileNeedsUpdate("packages.lst"))
+		    configFileNeedsUpdate("packages.lst") ||
+		    configFileNeedsUpdate("lyxciteengines.lst") ||
+		    configFileNeedsUpdate("xtemplates.lst"))
 			package().reconfigureUserLyXDir("");
 		fileUnlock(fd, lock_file.c_str());
 	} else
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 12457cb..68e21a4 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -1217,10 +1217,13 @@ int fileLock(const char * lock_file)
 	int fd = -1;
 #if defined(HAVE_LOCKF)
 	fd = open(lock_file, O_CREAT|O_APPEND|O_SYNC|O_RDWR, 0666);
-	if (fd == -1)
+	if (fd == -1) {
+		lyxerr << "Can't open the file " << lock_file << ", pid = " << ::getpid() << endl;
 		return -1;
+	}
 	if (lockf(fd, F_LOCK, 0) != 0) {
 		close(fd);
+		lyxerr << "Can't lock the file " << lock_file << ", pid = " << ::getpid() << endl;
 		return -1;
 	}
 #endif

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to