Hi,
can we please have some locking mechanism here?

While parallel export testing is OK, if the userdir is configured,
it is not if started with a fresh created userdir.

I have a patch implementing it. While this works for me, I am unsure,
if this is the right c++ way, or if this is platform independent.

Originally I wanted to use
        string const lock_file = 
addName(package().user_support().absFileName(),".lock")
but the problem here is, that the userdir may not be already created.

        Kornel
diff --git a/src/LyX.cpp b/src/LyX.cpp
index 09fcfd5..d8cfd2e 100644
--- a/src/LyX.cpp
+++ b/src/LyX.cpp
@@ -72,6 +72,7 @@
 #include <stdlib.h>
 #include <string>
 #include <vector>
+#include <fcntl.h>
 
 using namespace std;
 using namespace lyx::support;
@@ -754,8 +755,25 @@ bool LyX::init()
 		prependEnvPath("PATH", replaceEnvironmentPath(lyxrc.path_prefix));
 
 	// Check that user LyX directory is ok.
-	if (queryUserLyXDir(package().explicit_user_support()))
-		reconfigureUserLyXDir();
+	{
+	  string const lock_file = addName(package().system_temp_dir().absFileName(),
+					   ".lyx_configure_lock");
+	  int fd = open(lock_file.c_str(), O_CREAT|O_APPEND|O_SYNC|O_RDWR, 0666);
+	  struct flock lock;
+	  if (fd >= 0) {
+	    memset((char *) &lock, 0, sizeof(lock));
+	    lock.l_type = F_WRLCK;
+	    if (fcntl(fd, F_SETLKW, &lock) < 0) {
+	      close(fd);
+	      fd = -1;
+	    }
+	  }
+	  if (queryUserLyXDir(package().explicit_user_support()))
+	    reconfigureUserLyXDir();
+	  if ( fd >= 0) {
+	    close(fd);
+	  }
+	}
 
 	if (!use_gui) {
 		// No need for a splash when there is no GUI

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

Reply via email to