[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-cvs
Subject: [LyX/master] Implement file locking and apply to configure
From: Kornel Benko <kornel () lyx ! org>
Date: 2013-11-20 18:42:25
Message-ID: 20131120184225.C3D0A280253 () lyx ! lyx ! org
[Download RAW message or body]
commit 805e51eff86a1c249d80728dcd3f8d70313bc35e
Author: Kornel Benko <kornel@lyx.org>
Date: Wed Nov 20 19:40:32 2013 +0100
Implement file locking and apply to configure
Functions for file locking are added. They are used for ensuring that
for specified userdir only one LyX process runs configure.
diff --git a/configure.ac b/configure.ac
index b572f49..1fe6d9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -174,7 +174,7 @@ fi
LYX_CHECK_DEF(PATH_MAX, limits.h, [int n = PATH_MAX;])
-AC_CHECK_FUNCS(chmod close _close fork getpid _getpid lstat mkfifo open _open pclose \
_pclose popen _popen readlink putenv setenv strerror unsetenv) +AC_CHECK_FUNCS(chmod \
close _close fork getpid _getpid lockf lstat mkfifo open _open pclose _pclose popen \
_popen readlink putenv setenv strerror unsetenv) # Check the form of mkdir()
AC_FUNC_MKDIR
AC_FUNC_SELECT_ARGTYPES
diff --git a/development/cmake/ConfigureChecks.cmake \
b/development/cmake/ConfigureChecks.cmake index b6b0b14..71291a5 100644
--- a/development/cmake/ConfigureChecks.cmake
+++ b/development/cmake/ConfigureChecks.cmake
@@ -40,7 +40,7 @@ configure_file(${TOP_BINARY_DIR}/configIncludes.h.cmake \
${TOP_BINARY_DIR}/config set(Function_Defines)
foreach(_f alloca __argz_count __argz_next __argz_stringify
chmod close _close dcgettext fcntl fork __fsetlocking
- getcwd getegid getgid getpid _getpid gettext getuid lstat mempcpy mkdir _mkdir
+ getcwd getegid getgid getpid _getpid gettext getuid lstat lockf mempcpy mkdir \
_mkdir mkfifo open _open pclose _pclose popen _popen putenv readlink
setenv setlocale strcasecmp stpcpy strdup strerror strtoul tsearch unsetenv wcslen)
string(TOUPPER ${_f} _UF)
diff --git a/src/LyX.cpp b/src/LyX.cpp
index 09fcfd5..b777e55 100644
--- a/src/LyX.cpp
+++ b/src/LyX.cpp
@@ -754,8 +754,15 @@ 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 = package().user_support().absFileName() + \
".lyx_configure_lock"; + int fd = fileLock(lock_file.c_str());
+
+ if (queryUserLyXDir(package().explicit_user_support())) {
+ reconfigureUserLyXDir();
+ }
+ fileUnlock(fd, lock_file.c_str());
+ }
if (!use_gui) {
// No need for a splash when there is no GUI
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index f991455..387045f 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -1064,6 +1064,28 @@ bool prefs2prefs(FileName const & filename, FileName const & \
tempfile, bool lfun return true;
}
+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 (lockf(fd, F_LOCK, 0) != 0) {
+ close(fd);
+ return(-1);
+ }
+#endif
+ return(fd);
+}
+
+void fileUnlock(int fd, const char * lock_file)
+{
+#if defined(HAVE_LOCKF)
+ if ( fd >= 0) {
+ (void) lockf(fd, F_ULOCK, 0);
+ close(fd);
+ }
+#endif
+}
} //namespace support
} // namespace lyx
diff --git a/src/support/filetools.h b/src/support/filetools.h
index 92c6eb5..58d1154 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -292,6 +292,8 @@ typedef std::pair<int, std::string> cmd_ret;
cmd_ret const runCommand(std::string const & cmd);
+int fileLock(const char * lock_file);
+void fileUnlock(int fd, const char * lock_file);
} // namespace support
} // namespace lyx
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic