forked from Mirrors/openclonk
Create a log file for each instance of clonk on UNIXes (cmake only)
parent
37b630a472
commit
530a70f43c
|
@ -670,6 +670,7 @@ CHECK_INCLUDE_FILE_CXX(langinfo.h HAVE_LANGINFO_H)
|
|||
CHECK_INCLUDE_FILE_CXX(poll.h HAVE_POLL_H)
|
||||
CHECK_INCLUDE_FILE_CXX(sys/inotify.h HAVE_SYS_INOTIFY_H)
|
||||
CHECK_INCLUDE_FILE_CXX(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||
CHECK_INCLUDE_FILE_CXX(sys/file.h HAVE_SYS_FILE_H)
|
||||
if(USE_CONSOLE)
|
||||
CHECK_INCLUDE_FILE_CXX(readline.h HAVE_READLINE_H)
|
||||
CHECK_INCLUDE_FILE_CXX(readline/readline.h HAVE_READLINE_READLINE_H)
|
||||
|
|
|
@ -91,6 +91,9 @@
|
|||
/* Define to 1 if you have the <sys/inotify.h> header file. */
|
||||
#cmakedefine HAVE_SYS_INOTIFY_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#cmakedefine HAVE_SYS_FILE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SOCKET_H 1
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
#include <C4Components.h>
|
||||
#include <StdWindow.h>
|
||||
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SHARE_H) || defined(_WIN32)
|
||||
#include <share.h>
|
||||
#endif
|
||||
|
@ -53,10 +57,13 @@ bool OpenLog()
|
|||
sLogFileName = C4CFN_Log; int iLog = 2;
|
||||
#ifdef _WIN32
|
||||
while (!(C4LogFile = _fsopen(Config.AtUserDataPath(sLogFileName.getData()), "wt", _SH_DENYWR)))
|
||||
#elif HAVE_SYS_FILE_H
|
||||
while (!(C4LogFile = fopen(Config.AtUserDataPath(sLogFileName.getData()), "wb")) || flock(fileno(C4LogFile),LOCK_EX|LOCK_NB))
|
||||
#else
|
||||
while (!(C4LogFile = fopen(Config.AtUserDataPath(sLogFileName.getData()), "wb")))
|
||||
#endif
|
||||
{
|
||||
if(C4LogFile) fclose(C4LogFile); // Already locked by another instance?
|
||||
// If the file does not yet exist, the directory is r/o
|
||||
// don't go on then, or we have an infinite loop
|
||||
if (access(Config.AtUserDataPath(sLogFileName.getData()), 0))
|
||||
|
|
Loading…
Reference in New Issue