diff --git a/src/utils/closefrom.cpp b/src/utils/closefrom.cpp index 94e48c45..161d5a8f 100644 --- a/src/utils/closefrom.cpp +++ b/src/utils/closefrom.cpp @@ -73,12 +73,14 @@ #include "closefrom.h" #include -#include +#include "safeunistd.h" #include #include +#ifndef _WIN32 #include #include #include +#endif /* #define DEBUG_CLOSEFROM */ diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 434c647f..e8f22b4f 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -1611,13 +1611,13 @@ int Pidfile::write_pid() } char pidstr[20]; sprintf(pidstr, "%u", int(getpid())); - lseek(fd, 0, 0); + ::lseek(fd, 0, 0); if (::write(fd, pidstr, strlen(pidstr)) != (PATHUT_SSIZE_T)strlen(pidstr)) { m_reason = "write failed"; return -1; } #ifdef _WIN32 - close(fd); + ::close(fd); #endif return 0; } diff --git a/src/windows/execmd_w.cpp b/src/windows/execmd_w.cpp index ff63b3dd..8d39f8bb 100644 --- a/src/windows/execmd_w.cpp +++ b/src/windows/execmd_w.cpp @@ -32,6 +32,7 @@ #include #include "smallut.h" #include "pathut.h" +#include "closefrom.h" using namespace std; @@ -1242,13 +1243,26 @@ void ReExec::reexec() return; } - // Fill up argv - int i = 0; + // Fill up argv. Can you believe that we need to quote the args !! + // Esp. argv[0] if it's c:\program files\... std::vector> ptrs; - for (const auto& arg: m_argv) { + std::unique_ptr cmd = utf8towchar(m_argv[0]); + unsigned int i = 0; + for (; i < m_argv.size(); i++) { + LOGDEB2("argv[" << i << "] " << m_argv[i] << "\n"); + std::string arg; + argQuote(m_argv[i], arg); + LOGDEB2(" Quoted: [" << arg << "]\n"); ptrs.push_back(utf8towchar(arg)); - argv[i++] = ptrs.back().get(); + argv[i] = ptrs.back().get(); } argv[i] = nullptr; - _wexecvp(argv[0], argv); + + // Close all descriptors except 0,1,2 + // Does not work under windows for some reason, the new process does not start + //libclf_closefrom(3); + + auto ret = _wexecvp(cmd.get(), argv); + LOGERR("_WEXECVP ["<