mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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.
This commit is contained in:
parent
ca546a8b7e
commit
805e51eff8
@ -174,7 +174,7 @@ fi
|
|||||||
|
|
||||||
LYX_CHECK_DEF(PATH_MAX, limits.h, [int n = PATH_MAX;])
|
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()
|
# Check the form of mkdir()
|
||||||
AC_FUNC_MKDIR
|
AC_FUNC_MKDIR
|
||||||
AC_FUNC_SELECT_ARGTYPES
|
AC_FUNC_SELECT_ARGTYPES
|
||||||
|
@ -40,7 +40,7 @@ configure_file(${TOP_BINARY_DIR}/configIncludes.h.cmake ${TOP_BINARY_DIR}/config
|
|||||||
set(Function_Defines)
|
set(Function_Defines)
|
||||||
foreach(_f alloca __argz_count __argz_next __argz_stringify
|
foreach(_f alloca __argz_count __argz_next __argz_stringify
|
||||||
chmod close _close dcgettext fcntl fork __fsetlocking
|
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
|
mkfifo open _open pclose _pclose popen _popen putenv readlink
|
||||||
setenv setlocale strcasecmp stpcpy strdup strerror strtoul tsearch unsetenv wcslen)
|
setenv setlocale strcasecmp stpcpy strdup strerror strtoul tsearch unsetenv wcslen)
|
||||||
string(TOUPPER ${_f} _UF)
|
string(TOUPPER ${_f} _UF)
|
||||||
|
11
src/LyX.cpp
11
src/LyX.cpp
@ -754,8 +754,15 @@ bool LyX::init()
|
|||||||
prependEnvPath("PATH", replaceEnvironmentPath(lyxrc.path_prefix));
|
prependEnvPath("PATH", replaceEnvironmentPath(lyxrc.path_prefix));
|
||||||
|
|
||||||
// Check that user LyX directory is ok.
|
// 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) {
|
if (!use_gui) {
|
||||||
// No need for a splash when there is no GUI
|
// No need for a splash when there is no GUI
|
||||||
|
@ -1064,6 +1064,28 @@ bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfun
|
|||||||
return true;
|
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 support
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -292,6 +292,8 @@ typedef std::pair<int, std::string> cmd_ret;
|
|||||||
|
|
||||||
cmd_ret const runCommand(std::string const & cmd);
|
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 support
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
Loading…
Reference in New Issue
Block a user