use status-handle instead of winsrv cmdline option

JSON-75
Claudio Luck 5 years ago
parent 1ac6bda685
commit b0ce3bde6c

@ -16,7 +16,7 @@
HANDLE gPipeRd = NULL;
HANDLE gPipeWr = NULL;
void daemonize (const bool daemonize, const uintptr_t winsrv)
void daemonize (const bool daemonize, const uintptr_t status_handle)
{
TCHAR * szWinFrontCmdline, * szWinSrvCmdline;
DWORD dwWinFrontCmdlineLen;
@ -34,11 +34,11 @@ void daemonize (const bool daemonize, const uintptr_t winsrv)
* additional open file handles. But the new process must learn about the
* value of the filehandles somehow; only handles dedicated to stderr/stdout/stdin
* redirection can be passed "internally" via system call. So we simply pass the
* handle as a string over the command line; as "winsrv" argument. See CreateProcess
* documentation for more information.
* handle as a string over the command line; #defined STATUS_HANDLE "status-handle".
* See CreateProcess documentation for more information.
*/
gPipeWr = (HANDLE) winsrv;
gPipeWr = (HANDLE) status_handle;
if (gPipeWr == NULL)
{
@ -54,19 +54,19 @@ void daemonize (const bool daemonize, const uintptr_t winsrv)
throw std::runtime_error("Cannot configure pipe read handle!");
/*
* Create new command line with appended " --winsrv <handle>"
* Create new command line with appended " --status-handle <handle>"
*/
szWinFrontCmdline = GetCommandLine(); // FIXME: Unicode GetCommandLineW, and wmain()
dwWinFrontCmdlineLen = _tcslen(szWinFrontCmdline);
if (dwWinFrontCmdlineLen + 50 >= MAX_PATH) // + 50 to accommodate " --winsrv PRIuPRT"
dwWinFrontCmdlineLen = _tcslen(szWinFrontCmdline) + _tcslen(_T(" -- ")) + _tcslen(_T(STATUS_HANDLE));
if (dwWinFrontCmdlineLen + 40 >= MAX_PATH) // + 40 to accommodate PRIuPRT
throw std::runtime_error("Command line too long to be extend!");
if (!(szWinSrvCmdline = (TCHAR *)calloc(dwWinFrontCmdlineLen + 50 + 1, sizeof(TCHAR))))
if (!(szWinSrvCmdline = (TCHAR *)calloc(dwWinFrontCmdlineLen + 40 + 1, sizeof(TCHAR))))
throw std::runtime_error("Memory allocation for background process command line failed!");
_stprintf_s(szWinSrvCmdline, dwWinFrontCmdlineLen + 50 + 0,
_T("%s --winsrv %" PRIuPTR), szWinFrontCmdline,
((uintptr_t)(void*)gPipeWr));
_stprintf_s(szWinSrvCmdline, dwWinFrontCmdlineLen + 40 + 0,
_T("%s --" STATUS_HANDLE " %") PRIuPTR, szWinFrontCmdline,
((uintptr_t)gPipeWr));
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
@ -196,7 +196,7 @@ void handle_sig_term (int signal)
sig_term_recv = 1;
}
void daemonize (const bool daemonize, const uintptr_t winsrv)
void daemonize (const bool daemonize, const uintptr_t status_handle)
{
int retval = EXIT_FAILURE;
pid_t pid, sid, daemon_pid;

@ -3,14 +3,11 @@
#include <cstdint>
// cstdint uintptr_t is optional
#ifndef uintptr_t
#define ptrdiff_t uintptr_t
#endif
#define STATUS_HANDLE "status-handle"
// fork(), go into background, close all ttys etc...
// system-specific! (POSIX, Windows, ...?)
void daemonize(const bool daemonize, const uintptr_t winsrv);
void daemonize(const bool daemonize, const uintptr_t status_handle);
void daemonize_commit(int retval);
#endif

@ -16,7 +16,7 @@ namespace po = boost::program_options;
bool debug_mode = false;
bool do_sync = false;
bool ignore_missing_session = false;
uintptr_t winsrv = 0;
uintptr_t status_handle = 0;
std::string address = "127.0.0.1";
std::string logfile = "";
@ -57,7 +57,7 @@ try
("logfile,l", po::value<std::string>(&logfile)->default_value(logfile), "Name of the logfile. Can be \"stderr\" for log to stderr or empty for no log.")
("ignore-missing-session", po::bool_switch(&ignore_missing_session), "Ignore when no PEP_SESSION can be created.")
#ifdef _WIN32
("winsrv", po::value<uintptr_t>(&winsrv)->default_value(0), "For internal use (HANDLE)")
((STATUS_HANDLE), po::value<uintptr_t>(&status_handle)->default_value(0), "Status file handle, for internal use.")
#endif
;
@ -88,7 +88,7 @@ try
}
if( debug_mode == false )
daemonize (!debug_mode, (const uintptr_t) winsrv);
daemonize (!debug_mode, (const uintptr_t) status_handle);
JsonAdapter ja( my_logfile );
ja.do_sync( do_sync)

Loading…
Cancel
Save