diff --git a/src/common/conf_post.h b/src/common/conf_post.h index 8ae5fd6f..57d3cff9 100644 --- a/src/common/conf_post.h +++ b/src/common/conf_post.h @@ -35,21 +35,24 @@ inline int readlink(const char *cp, void *buf, int cnt) { #define HAVE_STRUCT_TIMESPEC #define strdup _strdup #define timegm _mkgmtime +#ifdef _MSC_VER // gmtime is supposedly thread-safe on windows #define gmtime_r(A, B) gmtime(A) #define localtime_r(A,B) localtime(A) +#define PATH_MAX MAX_PATH +#define MAXPATHLEN PATH_MAX +typedef int mode_t; +#endif typedef DWORD32 u_int32_t; typedef DWORD64 u_int64_t; typedef unsigned __int8 u_int8_t; -typedef int mode_t; typedef int ssize_t; #define strncasecmp _strnicmp #define strcasecmp _stricmp #define ftruncate _chsize_s #define chdir _chdir -#define PATH_MAX MAX_PATH -#define MAXPATHLEN PATH_MAX + #define R_OK 4 #define W_OK 2 #define X_OK 4 diff --git a/src/common/rclinit.cpp b/src/common/rclinit.cpp index 88a10fec..b20c8ed5 100644 --- a/src/common/rclinit.cpp +++ b/src/common/rclinit.cpp @@ -17,6 +17,9 @@ #include "autoconfig.h" #include +#ifdef _WIN32 +#include "safewindows.h" +#endif #include #include #include @@ -31,11 +34,6 @@ #include "pathut.h" #include "unac.h" #include "smallut.h" -#include "execmd.h" - -#ifndef _WIN32 -static const int catchedSigs[] = {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2}; -#endif static pthread_t mainthread_id; @@ -45,29 +43,20 @@ static void siglogreopen(int) DebugLog::reopen(); } -RclConfig *recollinit(RclInitFlags flags, - void (*cleanup)(void), void (*sigcleanup)(int), - string &reason, const string *argcnf) +#ifndef _WIN32 +// We would like to block SIGCHLD globally, but we can't because +// QT uses it. Have to block it inside execmd.cpp +static const int catchedSigs[] = {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2}; +void initAsyncSigs(void (*sigcleanup)(int)) { - if (cleanup) - atexit(cleanup); - // We ignore SIGPIPE always. All pieces of code which can write to a pipe // must check write() return values. #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif - - // Make sure the locale is set. This is only for converting file names - // to utf8 for indexing. - setlocale(LC_CTYPE, ""); - - // We would like to block SIGCHLD globally, but we can't because - // QT uses it. Have to block it inside execmd.cpp // Install app signal handler if (sigcleanup) { -#ifndef _WIN32 struct sigaction action; action.sa_handler = sigcleanup; action.sa_flags = 0; @@ -78,13 +67,93 @@ RclConfig *recollinit(RclInitFlags flags, perror("Sigaction failed"); } } -#endif } + + // Install log rotate sig handler + { + struct sigaction action; + action.sa_handler = siglogreopen; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { + if (sigaction(SIGHUP, &action, 0) < 0) { + perror("Sigaction failed"); + } + } + } +} +#else + +// Windows signals etc. +// +// ^C can be caught by the signal() emulation, but not ^Break +// apparently, which is why we use the native approach too +// +// When a keyboard interrupt occurs, windows creates a thread inside +// the process and calls the handler. The process exits when the +// handler returns or after at most 10S +// +// In practise, only recollindex sets sigcleanup(), and the routine +// just sets a global termination flag. So we just call it and sleep, +// hoping that cleanup does not take more than what Windows will let +// us live. + +static void (*l_sigcleanup)(int); + +static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) +{ + if (l_sigcleanup == 0) + return FALSE; + + switch(fdwCtrlType) { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_BREAK_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + l_sigcleanup(SIGINT); + Sleep(10000); + return TRUE; + default: + return FALSE; + } +} + +static const int catchedSigs[] = {SIGINT, SIGTERM}; +void initAsyncSigs(void (*sigcleanup)(int)) +{ + // Install app signal handler + if (sigcleanup) { + l_sigcleanup = sigcleanup; + for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++) { + if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN) { + signal(catchedSigs[i], sigcleanup); + } + } + } + SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); +} + +#endif + +RclConfig *recollinit(RclInitFlags flags, + void (*cleanup)(void), void (*sigcleanup)(int), + string &reason, const string *argcnf) +{ + if (cleanup) + atexit(cleanup); + + // Make sure the locale is set. This is only for converting file names + // to utf8 for indexing. + setlocale(LC_CTYPE, ""); + DebugLog::getdbl()->setloglevel(DEBDEB1); DebugLog::setfilename("stderr"); if (getenv("RECOLL_LOGDATE")) DebugLog::getdbl()->logdate(1); + initAsyncSigs(sigcleanup); + RclConfig *config = new RclConfig(argcnf); if (!config || !config->ok()) { reason = "Configuration could not be built:\n"; @@ -120,20 +189,6 @@ RclConfig *recollinit(RclInitFlags flags, int lev = atoi(loglevel.c_str()); DebugLog::getdbl()->setloglevel(lev); } - // Install log rotate sig handler -#ifndef _WIN32 - { - struct sigaction action; - action.sa_handler = siglogreopen; - action.sa_flags = 0; - sigemptyset(&action.sa_mask); - if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { - if (sigaction(SIGHUP, &action, 0) < 0) { - perror("Sigaction failed"); - } - } - } -#endif // Make sure the locale charset is initialized (so that multiple // threads don't try to do it at once). @@ -192,8 +247,8 @@ RclConfig *recollinit(RclInitFlags flags, return config; } -// Signals are handled by the main thread. All others should call this routine -// to block possible signals +// Signals are handled by the main thread. All others should call this +// routine to block possible signals void recoll_threadinit() { #ifndef _WIN32 @@ -204,6 +259,13 @@ void recoll_threadinit() sigaddset(&sset, catchedSigs[i]); sigaddset(&sset, SIGHUP); pthread_sigmask(SIG_BLOCK, &sset, 0); +#else + // Not sure that this is needed at all or correct under windows. + for (unsigned int i = 0; i < sizeof(catchedSigs) / sizeof(int); i++) { + if (signal(catchedSigs[i], SIG_IGN) != SIG_IGN) { + signal(catchedSigs[i], SIG_IGN); + } + } #endif } diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index e5904c5c..e9d94ccc 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -164,14 +164,6 @@ static void recollCleanup() LOGDEB2(("recollCleanup: done\n")); } -static void sigcleanup(int) -{ - // We used to not call exit from here, because of the idxthread, but - // this is now gone, so... - recollNeedsExit = 1; - exit(1); -} - void applyStyleSheet(const QString& ssfname) { const char *cfname = (const char *)ssfname.toLocal8Bit(); @@ -305,7 +297,7 @@ int main(int argc, char **argv) string reason; - theconfig = recollinit(recollCleanup, sigcleanup, reason, &a_config); + theconfig = recollinit(recollCleanup, 0, reason, &a_config); if (!theconfig || !theconfig->ok()) { QString msg = "Configuration problem: "; msg += QString::fromUtf8(reason.c_str()); diff --git a/src/windows/SolutionSettings/SolutionSettings.props b/src/windows/SolutionSettings/SolutionSettings.props new file mode 100644 index 00000000..b7d5c95f --- /dev/null +++ b/src/windows/SolutionSettings/SolutionSettings.props @@ -0,0 +1,30 @@ + + + + + C:\pthreads-w32\Pre-built.2 + c:\iconv64 + C:\xapian\xapian-core-1.2.8 + C:\zlib + + + + + + $(pthreads) + true + + + $(libiconv) + true + + + $(xapian) + true + + + $(zlib) + true + + + \ No newline at end of file diff --git a/src/windows/SolutionSettings/SolutionSettings.vcxproj b/src/windows/SolutionSettings/SolutionSettings.vcxproj new file mode 100644 index 00000000..4bc9c1ef --- /dev/null +++ b/src/windows/SolutionSettings/SolutionSettings.vcxproj @@ -0,0 +1,129 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B} + SolutionSettings + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + \ No newline at end of file diff --git a/src/windows/SolutionSettings/SolutionSettings.vcxproj.filters b/src/windows/SolutionSettings/SolutionSettings.vcxproj.filters new file mode 100644 index 00000000..f81daba0 --- /dev/null +++ b/src/windows/SolutionSettings/SolutionSettings.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + \ No newline at end of file diff --git a/src/windows/Win32ProjectRecoll.sln b/src/windows/Win32ProjectRecoll.sln index 687df9b4..7327f0ec 100644 --- a/src/windows/Win32ProjectRecoll.sln +++ b/src/windows/Win32ProjectRecoll.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "recollq", "recollq\recollq. {23FF40E1-BA87-4E5F-9B22-2EB760FF403D} = {23FF40E1-BA87-4E5F-9B22-2EB760FF403D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SolutionSettings", "SolutionSettings\SolutionSettings.vcxproj", "{7713CDF1-27B3-4F9B-B207-C7CEB801C24B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -47,6 +49,14 @@ Global {C1D0CCD2-0015-44AC-A606-AC48BB80C133}.Release|x64.Build.0 = Release|x64 {C1D0CCD2-0015-44AC-A606-AC48BB80C133}.Release|x86.ActiveCfg = Release|Win32 {C1D0CCD2-0015-44AC-A606-AC48BB80C133}.Release|x86.Build.0 = Release|Win32 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Debug|x64.ActiveCfg = Debug|x64 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Debug|x64.Build.0 = Debug|x64 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Debug|x86.ActiveCfg = Debug|Win32 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Debug|x86.Build.0 = Debug|Win32 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Release|x64.ActiveCfg = Release|x64 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Release|x64.Build.0 = Release|x64 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Release|x86.ActiveCfg = Release|Win32 + {7713CDF1-27B3-4F9B-B207-C7CEB801C24B}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/windows/Win32ProjectRecoll.vcxproj b/src/windows/Win32ProjectRecoll.vcxproj index 5c6155eb..2da824c9 100644 --- a/src/windows/Win32ProjectRecoll.vcxproj +++ b/src/windows/Win32ProjectRecoll.vcxproj @@ -58,15 +58,19 @@ + + + + @@ -80,7 +84,7 @@ Disabled BUILDING_RECOLL;WIN32;__WIN32__;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) false - C:\Iconv64\include;C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib64\zlib-win64;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) + C:\Iconv64\include;C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) 4800;4996 @@ -95,7 +99,7 @@ Disabled BUILDING_RECOLL;__WIN32__;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) false - C:\Iconv64\include;C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib64\zlib-win64;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) + C:\Iconv64\include;C:\xapian\xapian-core-1.2.8\include;C:\Users\Bill\recoll\src\internfile;C:\Users\Bill\recoll\src\rcldb;C:\Users\Bill\recoll\src\index;C:\Users\Bill\recoll\src\bincimapmime;C:\Users\Bill\recoll\src\unac;C:\Users\Bill\recoll\src\windows;C:\zlib;C:\pthreads-w32\Pre-built.2\include;C:\Users\Bill\recoll\src\xaposix;C:\Users\Bill\recoll\src\common;C:\Users\Bill\recoll\src\utils;%(AdditionalIncludeDirectories) 4800;4996 diff --git a/src/windows/Win32ProjectRecoll.vcxproj.user b/src/windows/Win32ProjectRecoll.vcxproj.user new file mode 100644 index 00000000..6fb136bf --- /dev/null +++ b/src/windows/Win32ProjectRecoll.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/windows/recollindex/recollindex.vcxproj b/src/windows/recollindex/recollindex.vcxproj index 3881e5ee..a7520ae9 100644 --- a/src/windows/recollindex/recollindex.vcxproj +++ b/src/windows/recollindex/recollindex.vcxproj @@ -58,19 +58,25 @@ + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ true @@ -93,7 +99,7 @@ Console true - C:\zlib64\zlib-win64\win32\Debug;C:\xapian\xapian-core-1.2.8\win32\win32\Debug;C:\Users\Bill\recoll\src\windows\win32\Debug;C:\pthreads-w32\Pre-built.2\lib\x86;%(AdditionalLibraryDirectories) + C:\zlib\win32\Debug;C:\xapian\xapian-core-1.2.8\win32\win32\Debug;C:\Users\Bill\recoll\src\windows\win32\Debug;C:\pthreads-w32\Pre-built.2\lib\x86;%(AdditionalLibraryDirectories) Win32ProjectRecoll.lib;xapian-core.lib;libiconv.lib;zlib.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) @@ -110,8 +116,8 @@ Console true - C:\xapian\xapian-core-1.2.8\win32\x64\Debug;C:\Users\Bill\recoll\src\windows\x64\Debug;C:\pthreads-w32\Pre-built.2\lib\x64;%(AdditionalLibraryDirectories) - Win32ProjectRecoll.lib;C:\zlib64\zlib-win64\x64\Debug\zlib.lib;xapian-core.lib;C:\iconv64\libiconv\x64\Debug\libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) + C:\zlib\x64\Debug;C:\xapian\xapian-core-1.2.8\win32\x64\Debug;C:\Users\Bill\recoll\src\windows\x64\Debug;C:\pthreads-w32\Pre-built.2\lib\x64;%(AdditionalLibraryDirectories) + Win32ProjectRecoll.lib;zlib.lib;xapian-core.lib;libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) diff --git a/src/windows/recollindex/recollindex.vcxproj.user b/src/windows/recollindex/recollindex.vcxproj.user new file mode 100644 index 00000000..6fb136bf --- /dev/null +++ b/src/windows/recollindex/recollindex.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/windows/recollq/recollq.vcxproj b/src/windows/recollq/recollq.vcxproj index 8f24f557..70c95de4 100644 --- a/src/windows/recollq/recollq.vcxproj +++ b/src/windows/recollq/recollq.vcxproj @@ -58,15 +58,19 @@ + + + + @@ -96,7 +100,7 @@ Console true - C:\zlib64\zlib-win64\win32\Debug;C:\xapian\xapian-core-1.2.8\win32\Win32\Debug;C:\Users\Bill\recoll\src\windows\win32\Debug;C:\pthreads-w32\Pre-built.2\lib\x86;%(AdditionalLibraryDirectories) + C:\zlib\win32\Debug;C:\xapian\xapian-core-1.2.8\win32\Win32\Debug;C:\Users\Bill\recoll\src\windows\win32\Debug;C:\pthreads-w32\Pre-built.2\lib\x86;%(AdditionalLibraryDirectories) Win32ProjectRecoll.lib;zlib.lib;xapian-core.lib;libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;uuid.lib;%(AdditionalDependencies) @@ -113,8 +117,8 @@ Console true - C:\xapian\xapian-core-1.2.8\win32\x64\Debug;C:\Users\Bill\recoll\src\windows\x64\Debug;C:\pthreads-w32\Pre-built.2\lib\x64;%(AdditionalLibraryDirectories) - Win32ProjectRecoll.lib;C:\zlib64\zlib-win64\x64\Debug\zlib.lib;xapian-core.lib;C:\iconv64\libiconv\x64\Debug\libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) + C:\zlib\x64\Debug;C:\xapian\xapian-core-1.2.8\win32\x64\Debug;C:\Users\Bill\recoll\src\windows\x64\Debug;C:\pthreads-w32\Pre-built.2\lib\x64;%(AdditionalLibraryDirectories) + Win32ProjectRecoll.lib;zlib.lib;xapian-core.lib;libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies)