unsigned long tls_index;\r
\r
/* Convert error code to error string - must call LocalFree() on return value */\r
-char *error_string(unsigned long error) {\r
+TCHAR *error_string(unsigned long error) {\r
/* Thread-safe buffer */\r
- char *error_message = (char *) TlsGetValue(tls_index);\r
+ TCHAR *error_message = (TCHAR *) TlsGetValue(tls_index);\r
if (! error_message) {\r
- error_message = (char *) LocalAlloc(LPTR, NSSM_ERROR_BUFSIZE);\r
- if (! error_message) return "<out of memory for error message>";\r
+ error_message = (TCHAR *) LocalAlloc(LPTR, NSSM_ERROR_BUFSIZE);\r
+ if (! error_message) return _T("<out of memory for error message>");\r
TlsSetValue(tls_index, (void *) error_message);\r
}\r
\r
- if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char *) error_message, NSSM_ERROR_BUFSIZE, 0)) {\r
- if (_snprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, "system error %lu", error) < 0) return 0;\r
+ if (! FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (TCHAR *) error_message, NSSM_ERROR_BUFSIZE, 0)) {\r
+ if (_sntprintf_s(error_message, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
}\r
return error_message;\r
}\r
\r
/* Convert message code to format string */\r
-char *message_string(unsigned long error) {\r
- char *ret;\r
- if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) {\r
- ret = (char *) HeapAlloc(GetProcessHeap(), 0, 32);\r
- if (_snprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, "system error %lu", error) < 0) return 0;\r
+TCHAR *message_string(unsigned long error) {\r
+ TCHAR *ret;\r
+ if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &ret, NSSM_ERROR_BUFSIZE, 0)) {\r
+ ret = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 32 * sizeof(TCHAR));\r
+ if (_sntprintf_s(ret, NSSM_ERROR_BUFSIZE, _TRUNCATE, _T("system error %lu"), error) < 0) return 0;\r
}\r
return ret;\r
}\r
void log_event(unsigned short type, unsigned long id, ...) {\r
va_list arg;\r
int count;\r
- char *s;\r
- char *strings[NSSM_NUM_EVENT_STRINGS];\r
+ TCHAR *s;\r
+ TCHAR *strings[NSSM_NUM_EVENT_STRINGS];\r
\r
/* Open event log */\r
- HANDLE handle = RegisterEventSource(0, TEXT(NSSM));\r
+ HANDLE handle = RegisterEventSource(0, NSSM);\r
if (! handle) return;\r
\r
/* Log it */\r
count = 0;\r
va_start(arg, id);\r
- while ((s = va_arg(arg, char *)) && count < NSSM_NUM_EVENT_STRINGS - 1) strings[count++] = s;\r
+ while ((s = va_arg(arg, TCHAR *)) && count < NSSM_NUM_EVENT_STRINGS - 1) strings[count++] = s;\r
strings[count] = 0;\r
va_end(arg);\r
- ReportEvent(handle, type, 0, id, 0, count, 0, (const char **) strings, 0);\r
+ ReportEvent(handle, type, 0, id, 0, count, 0, (const TCHAR **) strings, 0);\r
\r
/* Close event log */\r
DeregisterEventSource(handle);\r
void print_message(FILE *file, unsigned long id, ...) {\r
va_list arg;\r
\r
- char *format = message_string(id);\r
+ TCHAR *format = message_string(id);\r
if (! format) return;\r
\r
va_start(arg, id);\r
- vfprintf(file, format, arg);\r
+ _vftprintf(file, format, arg);\r
va_end(arg);\r
\r
LocalFree(format);\r
int popup_message(unsigned int type, unsigned long id, ...) {\r
va_list arg;\r
\r
- char *format = message_string(id);\r
+ TCHAR *format = message_string(id);\r
if (! format) {\r
- return MessageBox(0, "Message %lu was supposed to go here!", NSSM, MB_OK | MB_ICONEXCLAMATION);\r
+ return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
\r
- char blurb[256];\r
+ TCHAR blurb[256];\r
va_start(arg, id);\r
- if (vsnprintf_s(blurb, sizeof(blurb), _TRUNCATE, format, arg) < 0) {\r
+ if (_vsntprintf_s(blurb, sizeof(blurb), _TRUNCATE, format, arg) < 0) {\r
va_end(arg);\r
LocalFree(format);\r
- return MessageBox(0, "Message %lu was supposed to go here!", NSSM, MB_OK | MB_ICONEXCLAMATION);\r
+ return MessageBox(0, _T("Message %lu was supposed to go here!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
va_end(arg);\r
\r
#ifndef EVENT_H\r
#define EVENT_H\r
\r
-char *error_string(unsigned long);\r
-char *message_string(unsigned long);\r
+TCHAR *error_string(unsigned long);\r
+TCHAR *message_string(unsigned long);\r
void log_event(unsigned short, unsigned long, ...);\r
void print_message(FILE *, unsigned long, ...);\r
int popup_message(unsigned int, unsigned long, ...);\r
static HWND tablist[NSSM_NUM_TABS];\r
static int selected_tab;\r
\r
-int nssm_gui(int resource, char *name) {\r
+int nssm_gui(int resource, TCHAR *name) {\r
/* Create window */\r
HWND dlg = CreateDialog(0, MAKEINTRESOURCE(resource), 0, install_dlg);\r
if (! dlg) {\r
if (translated) *timeout = configured;\r
}\r
\r
-static inline void check_io(char *name, char *buffer, size_t bufsize, unsigned long control) {\r
+static inline void check_io(TCHAR *name, TCHAR *buffer, size_t bufsize, unsigned long control) {\r
if (! SendMessage(GetDlgItem(tablist[NSSM_TAB_IO], control), WM_GETTEXTLENGTH, 0, 0)) return;\r
if (GetDlgItemText(tablist[NSSM_TAB_IO], control, buffer, (int) bufsize)) return;\r
popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_PATH_TOO_LONG, name);\r
\r
/* Get startup directory. */\r
if (! GetDlgItemText(tablist[NSSM_TAB_APPLICATION], IDC_DIR, service->dir, sizeof(service->dir))) {\r
- memmove(service->dir, service->exe, sizeof(service->dir));\r
+ _sntprintf_s(service->dir, _countof(service->dir), _TRUNCATE, _T("%s"), service->exe);\r
strip_basename(service->dir);\r
}\r
\r
if (service->default_exit_action == CB_ERR) service->default_exit_action = 0;\r
\r
/* Get I/O stuff. */\r
- check_io("stdin", service->stdin_path, sizeof(service->stdin_path), IDC_STDIN);\r
- check_io("stdout", service->stdout_path, sizeof(service->stdout_path), IDC_STDOUT);\r
- check_io("stderr", service->stderr_path, sizeof(service->stderr_path), IDC_STDERR);\r
+ check_io(_T("stdin"), service->stdin_path, sizeof(service->stdin_path), IDC_STDIN);\r
+ check_io(_T("stdout"), service->stdout_path, sizeof(service->stdout_path), IDC_STDOUT);\r
+ check_io(_T("stderr"), service->stderr_path, sizeof(service->stderr_path), IDC_STDERR);\r
/* Override stdout and/or stderr. */\r
if (SendDlgItemMessage(tablist[NSSM_TAB_IO], IDC_TRUNCATE, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
if (service->stdout_path[0]) service->stdout_disposition = CREATE_ALWAYS;\r
/* Get environment. */\r
unsigned long envlen = (unsigned long) SendMessage(GetDlgItem(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT), WM_GETTEXTLENGTH, 0, 0);\r
if (envlen) {\r
- char *env = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, envlen + 2);\r
+ TCHAR *env = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (envlen + 2) * sizeof(TCHAR));\r
if (! env) {\r
- popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, "environment", "install()");\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
cleanup_nssm_service(service);\r
return 5;\r
}\r
/* Strip CR and replace LF with NULL. */\r
unsigned long newlen = 0;\r
unsigned long i, j;\r
- for (i = 0; i < envlen; i++) if (env[i] != '\r') newlen++;\r
+ for (i = 0; i < envlen; i++) if (env[i] != _T('\r')) newlen++;\r
/* Must end with two NULLs. */\r
newlen += 2;\r
\r
- char *newenv = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newlen);\r
+ TCHAR *newenv = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, newlen * sizeof(TCHAR));\r
if (! newenv) {\r
HeapFree(GetProcessHeap(), 0, env);\r
- popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, "environment", "install()");\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
cleanup_nssm_service(service);\r
return 5;\r
}\r
\r
for (i = 0, j = 0; i < envlen; i++) {\r
- if (env[i] == '\r') continue;\r
- if (env[i] == '\n') newenv[j] = '\0';\r
+ if (env[i] == _T('\r')) continue;\r
+ if (env[i] == _T('\n')) newenv[j] = _T('\0');\r
else newenv[j] = env[i];\r
j++;\r
}\r
envlen = newlen;\r
\r
/* Test the environment is valid. */\r
- char path[MAX_PATH];\r
- GetModuleFileName(0, path, sizeof(path));\r
+ TCHAR path[MAX_PATH];\r
+ GetModuleFileName(0, path, _countof(path));\r
STARTUPINFO si;\r
ZeroMemory(&si, sizeof(si));\r
si.cb = sizeof(si);\r
PROCESS_INFORMATION pi;\r
ZeroMemory(&pi, sizeof(pi));\r
+ unsigned long flags = CREATE_SUSPENDED;\r
+#ifdef UNICODE\r
+ flags |= CREATE_UNICODE_ENVIRONMENT;\r
+#endif\r
\r
- if (! CreateProcess(0, path, 0, 0, 0, CREATE_SUSPENDED, env, 0, &si, &pi)) {\r
+ if (! CreateProcess(0, path, 0, 0, 0, flags, env, 0, &si, &pi)) {\r
unsigned long error = GetLastError();\r
if (error == ERROR_INVALID_PARAMETER) {\r
popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
/* See if it works. */\r
switch (install_service(service)) {\r
case 1:\r
- popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, "service", "install()");\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("install()"));\r
cleanup_nssm_service(service);\r
return 1;\r
\r
\r
switch (remove_service(service)) {\r
case 1:\r
- popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, "service", "remove()");\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("remove()"));\r
cleanup_nssm_service(service);\r
return 1;\r
\r
return 0;\r
}\r
\r
-static char *browse_filter(int message) {\r
+static TCHAR *browse_filter(int message) {\r
switch (message) {\r
- case NSSM_GUI_BROWSE_FILTER_APPLICATIONS: return "*.exe;*.bat;*.cmd";\r
- case NSSM_GUI_BROWSE_FILTER_DIRECTORIES: return ".";\r
+ case NSSM_GUI_BROWSE_FILTER_APPLICATIONS: return _T("*.exe;*.bat;*.cmd");\r
+ case NSSM_GUI_BROWSE_FILTER_DIRECTORIES: return _T(".");\r
case NSSM_GUI_BROWSE_FILTER_ALL_FILES: /* Fall through. */\r
- default: return "*.*";\r
+ default: return _T("*.*");\r
}\r
}\r
\r
}\r
\r
/* Browse for application */\r
-void browse(HWND window, char *current, unsigned long flags, ...) {\r
+void browse(HWND window, TCHAR *current, unsigned long flags, ...) {\r
if (! window) return;\r
\r
va_list arg;\r
OPENFILENAME ofn;\r
ZeroMemory(&ofn, sizeof(ofn));\r
ofn.lStructSize = sizeof(ofn);\r
- ofn.lpstrFilter = (char *) HeapAlloc(GetProcessHeap(), 0, bufsize);\r
+ ofn.lpstrFilter = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, bufsize * sizeof(TCHAR));\r
/* XXX: Escaping nulls with FormatMessage is tricky */\r
if (ofn.lpstrFilter) {\r
ZeroMemory((void *) ofn.lpstrFilter, bufsize);\r
/* "Applications" + NULL + "*.exe" + NULL */\r
va_start(arg, flags);\r
while (i = va_arg(arg, int)) {\r
- char *localised = message_string(i);\r
- _snprintf_s((char *) ofn.lpstrFilter + len, bufsize, _TRUNCATE, localised);\r
- len += strlen(localised) + 1;\r
+ TCHAR *localised = message_string(i);\r
+ _sntprintf_s((TCHAR *) ofn.lpstrFilter + len, bufsize, _TRUNCATE, localised);\r
+ len += _tcslen(localised) + 1;\r
LocalFree(localised);\r
- char *filter = browse_filter(i);\r
- _snprintf_s((char *) ofn.lpstrFilter + len, bufsize - len, _TRUNCATE, "%s", filter);\r
- len += strlen(filter) + 1;\r
+ TCHAR *filter = browse_filter(i);\r
+ _sntprintf_s((TCHAR *) ofn.lpstrFilter + len, bufsize - len, _TRUNCATE, _T("%s"), filter);\r
+ len += _tcslen(filter) + 1;\r
}\r
va_end(arg);\r
/* Remainder of the buffer is already zeroed */\r
}\r
- ofn.lpstrFile = new char[MAX_PATH];\r
+ ofn.lpstrFile = new TCHAR[MAX_PATH];\r
if (flags & OFN_NOVALIDATE) {\r
/* Directory hack. */\r
- _snprintf_s(ofn.lpstrFile, MAX_PATH, _TRUNCATE, ":%s:", message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES));\r
+ _sntprintf_s(ofn.lpstrFile, MAX_PATH, _TRUNCATE, _T(":%s:"), message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES));\r
}\r
- else _snprintf_s(ofn.lpstrFile, MAX_PATH, _TRUNCATE, "%s", current);\r
+ else _sntprintf_s(ofn.lpstrFile, MAX_PATH, _TRUNCATE, _T("%s"), current);\r
ofn.lpstrTitle = message_string(NSSM_GUI_BROWSE_TITLE);\r
ofn.nMaxFile = MAX_PATH;\r
ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | flags;\r
/* Button was pressed or control was controlled. */\r
case WM_COMMAND:\r
HWND dlg;\r
- char buffer[MAX_PATH];\r
+ TCHAR buffer[MAX_PATH];\r
\r
switch (LOWORD(w)) {\r
/* Browse for application. */\r
\r
/* Application tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_APPLICATION);\r
- tab.cchTextMax = (int) strlen(tab.pszText);\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_APPLICATION, (LPARAM) &tab);\r
tablist[NSSM_TAB_APPLICATION] = CreateDialog(0, MAKEINTRESOURCE(IDD_APPLICATION), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_APPLICATION], SW_SHOW);\r
\r
/* Shutdown tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_SHUTDOWN);\r
- tab.cchTextMax = (int) strlen(tab.pszText);\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_SHUTDOWN, (LPARAM) &tab);\r
tablist[NSSM_TAB_SHUTDOWN] = CreateDialog(0, MAKEINTRESOURCE(IDD_SHUTDOWN), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_SHUTDOWN], SW_HIDE);\r
\r
/* Restart tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_EXIT);\r
- tab.cchTextMax = (int) strlen(tab.pszText);\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText);\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_EXIT, (LPARAM) &tab);\r
tablist[NSSM_TAB_EXIT] = CreateDialog(0, MAKEINTRESOURCE(IDD_APPEXIT), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_EXIT], SW_HIDE);\r
\r
/* I/O tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_IO);\r
- tab.cchTextMax = (int) strlen(tab.pszText) + 1;\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText) + 1;\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_IO, (LPARAM) &tab);\r
tablist[NSSM_TAB_IO] = CreateDialog(0, MAKEINTRESOURCE(IDD_IO), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_IO], SW_HIDE);\r
\r
/* Environment tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_ENVIRONMENT);\r
- tab.cchTextMax = (int) strlen(tab.pszText) + 1;\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText) + 1;\r
SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_ENVIRONMENT, (LPARAM) &tab);\r
tablist[NSSM_TAB_ENVIRONMENT] = CreateDialog(0, MAKEINTRESOURCE(IDD_ENVIRONMENT), window, tab_dlg);\r
ShowWindow(tablist[NSSM_TAB_ENVIRONMENT], SW_HIDE);\r
#include <commctrl.h>\r
#include "resource.h"\r
\r
-int nssm_gui(int, char *);\r
+int nssm_gui(int, TCHAR *);\r
void centre_window(HWND);\r
int install(HWND);\r
int remove(HWND);\r
absolutely need. If we later add some indispensible imports we can
return non-zero here to force an application exit.
*/
-HMODULE get_dll(const char *dll, unsigned long *error) {
+HMODULE get_dll(const TCHAR *dll, unsigned long *error) {
*error = 0;
HMODULE ret = LoadLibrary(dll);
ZeroMemory(&imports, sizeof(imports));
- imports.kernel32 = get_dll("kernel32.dll", &error);
+ imports.kernel32 = get_dll(_T("kernel32.dll"), &error);
if (imports.kernel32) {
imports.AttachConsole = (AttachConsole_ptr) get_import(imports.kernel32, "AttachConsole", &error);
if (! imports.AttachConsole) {
WakeConditionVariable_ptr WakeConditionVariable;
} imports_t;
-HMODULE get_dll(const char *, unsigned long *);
+HMODULE get_dll(const TCHAR *, unsigned long *);
FARPROC get_import(HMODULE, const char *, unsigned long *);
int get_imports();
void free_imports();
#include "nssm.h"\r
\r
/* Get path, share mode, creation disposition and flags for a stream. */\r
-int get_createfile_parameters(HKEY key, char *prefix, char *path, unsigned long *sharing, unsigned long default_sharing, unsigned long *disposition, unsigned long default_disposition, unsigned long *flags, unsigned long default_flags) {\r
- char value[NSSM_STDIO_LENGTH];\r
+int get_createfile_parameters(HKEY key, TCHAR *prefix, TCHAR *path, unsigned long *sharing, unsigned long default_sharing, unsigned long *disposition, unsigned long default_disposition, unsigned long *flags, unsigned long default_flags) {\r
+ TCHAR value[NSSM_STDIO_LENGTH];\r
\r
/* Path. */\r
- if (_snprintf_s(value, sizeof(value), _TRUNCATE, "%s", prefix) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, prefix, "get_createfile_parameters()", 0);\r
+ if (_sntprintf_s(value, _countof(value), _TRUNCATE, _T("%s"), prefix) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, prefix, _T("get_createfile_parameters()"), 0);\r
return 1;\r
}\r
switch (expand_parameter(key, value, path, MAX_PATH, true, false)) {\r
}\r
\r
/* ShareMode. */\r
- if (_snprintf_s(value, sizeof(value), _TRUNCATE, "%s%s", prefix, NSSM_REG_STDIO_SHARING) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_SHARING, "get_createfile_parameters()", 0);\r
+ if (_sntprintf_s(value, _countof(value), _TRUNCATE, _T("%s%s"), prefix, NSSM_REG_STDIO_SHARING) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_SHARING, _T("get_createfile_parameters()"), 0);\r
return 3;\r
}\r
switch (get_number(key, value, sharing, false)) {\r
}\r
\r
/* CreationDisposition. */\r
- if (_snprintf_s(value, sizeof(value), _TRUNCATE, "%s%s", prefix, NSSM_REG_STDIO_DISPOSITION) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_DISPOSITION, "get_createfile_parameters()", 0);\r
+ if (_sntprintf_s(value, _countof(value), _TRUNCATE, _T("%s%s"), prefix, NSSM_REG_STDIO_DISPOSITION) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_DISPOSITION, _T("get_createfile_parameters()"), 0);\r
return 5;\r
}\r
switch (get_number(key, value, disposition, false)) {\r
}\r
\r
/* Flags. */\r
- if (_snprintf_s(value, sizeof(value), _TRUNCATE, "%s%s", prefix, NSSM_REG_STDIO_FLAGS) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_FLAGS, "get_createfile_parameters()", 0);\r
+ if (_sntprintf_s(value, _countof(value), _TRUNCATE, _T("%s%s"), prefix, NSSM_REG_STDIO_FLAGS) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REG_STDIO_FLAGS, _T("get_createfile_parameters()"), 0);\r
return 7;\r
}\r
switch (get_number(key, value, flags, false)) {\r
return 0;\r
}\r
\r
-int set_createfile_parameter(HKEY key, char *prefix, char *suffix, unsigned long number) {\r
- char value[NSSM_STDIO_LENGTH];\r
+int set_createfile_parameter(HKEY key, TCHAR *prefix, TCHAR *suffix, unsigned long number) {\r
+ TCHAR value[NSSM_STDIO_LENGTH];\r
\r
- if (_snprintf_s(value, sizeof(value), _TRUNCATE, "%s%s", prefix, suffix) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, suffix, "set_createfile_parameter()", 0);\r
+ if (_sntprintf_s(value, _countof(value), _TRUNCATE, _T("%s%s"), prefix, suffix) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, suffix, _T("set_createfile_parameter()"), 0);\r
return 1;\r
}\r
\r
return set_number(key, value, number);\r
}\r
\r
-HANDLE append_to_file(char *path, unsigned long sharing, SECURITY_ATTRIBUTES *attributes, unsigned long disposition, unsigned long flags) {\r
+HANDLE append_to_file(TCHAR *path, unsigned long sharing, SECURITY_ATTRIBUTES *attributes, unsigned long disposition, unsigned long flags) {\r
HANDLE ret;\r
\r
/* Try to append to the file first. */\r
}\r
\r
int get_output_handles(HKEY key, STARTUPINFO *si) {\r
- char path[MAX_PATH];\r
- char stdout_path[MAX_PATH];\r
+ TCHAR path[MAX_PATH];\r
+ TCHAR stdout_path[MAX_PATH];\r
unsigned long sharing, disposition, flags;\r
bool set_flags = false;\r
\r
if (get_createfile_parameters(key, NSSM_REG_STDOUT, path, &sharing, NSSM_STDOUT_SHARING, &disposition, NSSM_STDOUT_DISPOSITION, &flags, NSSM_STDOUT_FLAGS)) return 3;\r
if (path[0]) {\r
/* Remember path for comparison with stderr. */\r
- if (_snprintf_s(stdout_path, sizeof(stdout_path), _TRUNCATE, "%s", path) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "stdout_path", "get_output_handles", 0);\r
+ if (_sntprintf_s(stdout_path, _countof(stdout_path), _TRUNCATE, _T("%s"), path) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("stdout_path"), _T("get_output_handles"), 0);\r
return 4;\r
}\r
\r
#define NSSM_STDERR_DISPOSITION OPEN_ALWAYS\r
#define NSSM_STDERR_FLAGS FILE_ATTRIBUTE_NORMAL\r
\r
-int get_createfile_parameters(HKEY, char *, char *, unsigned long *, unsigned long, unsigned long *, unsigned long, unsigned long *, unsigned long);\r
-int set_createfile_parameter(HKEY, char *, char *, unsigned long);\r
-HANDLE append_to_file(char *, unsigned long, SECURITY_ATTRIBUTES *, unsigned long, unsigned long);\r
+int get_createfile_parameters(HKEY, TCHAR *, TCHAR *, unsigned long *, unsigned long, unsigned long *, unsigned long, unsigned long *, unsigned long);\r
+int set_createfile_parameter(HKEY, TCHAR *, TCHAR *, unsigned long);\r
+HANDLE append_to_file(TCHAR *, unsigned long, SECURITY_ATTRIBUTES *, unsigned long, unsigned long);\r
int get_output_handles(HKEY, STARTUPINFO *);\r
void close_output_handles(STARTUPINFO *);\r
\r
Il path completo verso %s è troppo lungo!
.
+MessageId = +1
+SymbolicName = NSSM_MESSAGE_FLAGS_TOO_LONG
+Severity = Informational
+Language = English
+The program flags are too long!
+.
+Language = French
+The program flags are too long!
+.
+Language = Italian
+The program flags are too long!
+.
MessageId = +1
SymbolicName = NSSM_MESSAGE_OUT_OF_MEMORY_FOR_IMAGEPATH
extern bool is_admin;\r
extern imports_t imports;\r
\r
-/* String function */\r
-int str_equiv(const char *a, const char *b) {\r
- int i;\r
- for (i = 0; ; i++) {\r
- if (tolower(b[i]) != tolower(a[i])) return 0;\r
- if (! a[i]) return 1;\r
- }\r
+/* Are two strings case-insensitively equivalent? */\r
+int str_equiv(const TCHAR *a, const TCHAR *b) {\r
+ size_t len = _tcslen(a);\r
+ if (_tcslen(b) != len) return 0;\r
+ if (_tcsnicmp(a, b, len)) return 0;\r
+ return 1;\r
}\r
\r
/* Remove basename of a path. */\r
-void strip_basename(char *buffer) {\r
- size_t len = strlen(buffer);\r
+void strip_basename(TCHAR *buffer) {\r
+ size_t len = _tcslen(buffer);\r
size_t i;\r
- for (i = len; i && buffer[i] != '\\' && buffer[i] != '/'; i--);\r
+ for (i = len; i && buffer[i] != _T('\\') && buffer[i] != _T('/'); i--);\r
/* X:\ is OK. */\r
- if (i && buffer[i-1] == ':') i++;\r
- buffer[i] = '\0';\r
+ if (i && buffer[i - 1] == _T(':')) i++;\r
+ buffer[i] = _T('\0');\r
}\r
\r
/* How to use me correctly */\r
FreeSid(AdministratorsGroup);\r
}\r
\r
-int main(int argc, char **argv) {\r
+int _tmain(int argc, TCHAR **argv) {\r
/* Remember if we are admin */\r
check_admin();\r
\r
/* Elevate */\r
if (argc > 1) {\r
/* Valid commands are install or remove */\r
- if (str_equiv(argv[1], "install")) {\r
+ if (str_equiv(argv[1], _T("install"))) {\r
if (! is_admin) {\r
print_message(stderr, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_INSTALL);\r
exit(100);\r
}\r
exit(pre_install_service(argc - 2, argv + 2));\r
}\r
- if (str_equiv(argv[1], "remove")) {\r
+ if (str_equiv(argv[1], _T("remove"))) {\r
if (! is_admin) {\r
print_message(stderr, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_REMOVE);\r
exit(100);\r
#include <shlwapi.h>\r
#include <stdarg.h>\r
#include <stdio.h>\r
+#include <tchar.h>\r
#include <windows.h>\r
#include "service.h"\r
#include "event.h"\r
#include "io.h"\r
#include "gui.h"\r
\r
-int str_equiv(const char *, const char *);\r
-void strip_basename(char *);\r
+int str_equiv(const TCHAR *, const TCHAR *);\r
+void strip_basename(TCHAR *);\r
\r
-#define NSSM "nssm"\r
-#define NSSM_VERSION "2.21"\r
+#define NSSM _T("nssm")\r
+#define NSSM_VERSION _T("2.21")\r
#define NSSM_VERSIONINFO 2,21,0,0\r
-#define NSSM_DATE "2013-11-24"\r
+#define NSSM_DATE _T("2013-11-24")\r
\r
/*\r
Throttle the restart of the service if it stops before this many\r
*/
HANDLE process_handle = OpenProcess(PROCESS_QUERY_INFORMATION, false, pe->th32ProcessID);
if (! process_handle) {
- char pid_string[16];
- _snprintf_s(pid_string, sizeof(pid_string), _TRUNCATE, "%lu", pe->th32ProcessID);
+ TCHAR pid_string[16];
+ _sntprintf_s(pid_string, _countof(pid_string), _TRUNCATE, _T("%lu"), pe->th32ProcessID);
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OPENPROCESS_FAILED, pid_string, service->name, error_string(GetLastError()), 0);
return 2;
}
processes so this function returns only true if at least one thread was
successfully prodded.
*/
-int kill_threads(char *service_name, kill_t *k) {
+int kill_threads(TCHAR *service_name, kill_t *k) {
int ret = 0;
/* Get a snapshot of all threads in the system. */
if (service->stop_method & NSSM_STOP_METHOD_WINDOW) {
EnumWindows((WNDENUMPROC) kill_window, (LPARAM) &k);
if (k.signalled) {
- if (! await_shutdown(service, __FUNCTION__, service->kill_window_delay)) return 1;
+ if (! await_shutdown(service, _T(__FUNCTION__), service->kill_window_delay)) return 1;
}
}
*/
if (service->stop_method & NSSM_STOP_METHOD_THREADS) {
if (kill_threads(service->name, &k)) {
- if (! await_shutdown(service, __FUNCTION__, service->kill_threads_delay)) return 1;
+ if (! await_shutdown(service, _T(__FUNCTION__), service->kill_threads_delay)) return 1;
}
}
}
/* Wait for process to exit. */
- if (await_shutdown(service, __FUNCTION__, service->kill_console_delay)) ret = 6;
+ if (await_shutdown(service, _T(__FUNCTION__), service->kill_console_delay)) ret = 6;
return ret;
}
/* Shouldn't happen unless the service failed to start. */
if (! pid) return;
- char pid_string[16], code[16];
- _snprintf_s(pid_string, sizeof(pid_string), _TRUNCATE, "%lu", pid);
- _snprintf_s(code, sizeof(code), _TRUNCATE, "%lu", exitcode);
+ TCHAR pid_string[16], code[16];
+ _sntprintf_s(pid_string, _countof(pid_string), _TRUNCATE, _T("%lu"), pid);
+ _sntprintf_s(code, _countof(code), _TRUNCATE, _T("%lu"), exitcode);
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_KILLING, service->name, pid_string, code, 0);
/* Get a snapshot of all processes in the system. */
return;
}
- char ppid_string[16];
- _snprintf_s(ppid_string, sizeof(ppid_string), _TRUNCATE, "%lu", ppid);
+ TCHAR ppid_string[16];
+ _sntprintf_s(ppid_string, _countof(ppid_string), _TRUNCATE, _T("%lu"), ppid);
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_KILL_PROCESS_TREE, pid_string, ppid_string, service->name, 0);
if (! kill_process(service, process_handle, pid, exitcode)) {
/* Maybe it already died. */
int get_process_creation_time(HANDLE, FILETIME *);
int get_process_exit_time(HANDLE, FILETIME *);
-int check_parent(char *, PROCESSENTRY32 *, unsigned long, FILETIME *, FILETIME *);
+int check_parent(TCHAR *, PROCESSENTRY32 *, unsigned long, FILETIME *, FILETIME *);
int CALLBACK kill_window(HWND, LPARAM);
int kill_threads(nssm_service_t *, kill_t *);
int kill_console(nssm_service_t *);
#include "nssm.h"\r
\r
-extern const char *exit_action_strings[];\r
+extern const TCHAR *exit_action_strings[];\r
\r
int create_messages() {\r
HKEY key;\r
\r
- char registry[KEY_LENGTH];\r
- if (_snprintf_s(registry, sizeof(registry), _TRUNCATE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", NSSM) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "eventlog registry", "create_messages()", 0);\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (_sntprintf_s(registry, _countof(registry), _TRUNCATE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s"), NSSM) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("eventlog registry"), _T("create_messages()"), 0);\r
return 1;\r
}\r
\r
}\r
\r
/* Get path of this program */\r
- char path[MAX_PATH];\r
- GetModuleFileName(0, path, MAX_PATH);\r
+ TCHAR path[MAX_PATH];\r
+ GetModuleFileName(0, path, _countof(path));\r
\r
/* Try to register the module but don't worry so much on failure */\r
- RegSetValueEx(key, "EventMessageFile", 0, REG_SZ, (const unsigned char *) path, (unsigned long) strlen(path) + 1);\r
+ RegSetValueEx(key, _T("EventMessageFile"), 0, REG_SZ, (const unsigned char *) path, (unsigned long) (_tcslen(path) + 1) * sizeof(TCHAR));\r
unsigned long types = EVENTLOG_INFORMATION_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_ERROR_TYPE;\r
- RegSetValueEx(key, "TypesSupported", 0, REG_DWORD, (const unsigned char *) &types, sizeof(types));\r
+ RegSetValueEx(key, _T("TypesSupported"), 0, REG_DWORD, (const unsigned char *) &types, sizeof(types));\r
\r
return 0;\r
}\r
\r
int create_parameters(nssm_service_t *service) {\r
/* Get registry */\r
- char registry[KEY_LENGTH];\r
- if (_snprintf_s(registry, sizeof(registry), _TRUNCATE, NSSM_REGISTRY, service->name) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "NSSM_REGISTRY", "create_parameters()", 0);\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (_sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY, service->name) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("NSSM_REGISTRY"), _T("create_parameters()"), 0);\r
return 1;\r
}\r
\r
\r
/* Environment */\r
if (service->env) {\r
- if (RegSetValueEx(key, NSSM_REG_ENV, 0, REG_MULTI_SZ, (const unsigned char *) service->env, (unsigned long) service->envlen) != ERROR_SUCCESS) {\r
+ if (RegSetValueEx(key, NSSM_REG_ENV, 0, REG_MULTI_SZ, (const unsigned char *) service->env, (unsigned long) service->envlen * sizeof(TCHAR)) != ERROR_SUCCESS) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, NSSM_REG_ENV, error_string(GetLastError()), 0);\r
}\r
}\r
if (service->env_extra) {\r
- if (RegSetValueEx(key, NSSM_REG_ENV_EXTRA, 0, REG_MULTI_SZ, (const unsigned char *) service->env_extra, (unsigned long) service->env_extralen) != ERROR_SUCCESS) {\r
+ if (RegSetValueEx(key, NSSM_REG_ENV_EXTRA, 0, REG_MULTI_SZ, (const unsigned char *) service->env_extra, (unsigned long) service->env_extralen * sizeof(TCHAR)) != ERROR_SUCCESS) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, NSSM_REG_ENV_EXTRA, error_string(GetLastError()), 0);\r
}\r
}\r
return 0;\r
}\r
\r
-int create_exit_action(char *service_name, const char *action_string) {\r
+int create_exit_action(TCHAR *service_name, const TCHAR *action_string) {\r
/* Get registry */\r
- char registry[KEY_LENGTH];\r
- if (_snprintf_s(registry, sizeof(registry), _TRUNCATE, NSSM_REGISTRY "\\%s", service_name, NSSM_REG_EXIT) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "NSSM_REG_EXIT", "create_exit_action()", 0);\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (_sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY _T("\\%s"), service_name, NSSM_REG_EXIT) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("NSSM_REG_EXIT"), _T("create_exit_action()"), 0);\r
return 1;\r
}\r
\r
}\r
\r
/* Create the default value */\r
- if (RegSetValueEx(key, 0, 0, REG_SZ, (const unsigned char *) action_string, (unsigned long) strlen(action_string) + 1) != ERROR_SUCCESS) {\r
+ if (RegSetValueEx(key, 0, 0, REG_SZ, (const unsigned char *) action_string, (unsigned long) (_tcslen(action_string) + 1) * sizeof(TCHAR)) != ERROR_SUCCESS) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, NSSM_REG_EXIT, error_string(GetLastError()), 0);\r
RegCloseKey(key);\r
return 3;\r
return 0;\r
}\r
\r
-int set_environment(char *service_name, HKEY key, char *value, char **env, unsigned long *envlen) {\r
+int set_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, unsigned long *envlen) {\r
unsigned long type = REG_MULTI_SZ;\r
\r
/* Dummy test to find buffer size */\r
/* Previously initialised? */\r
if (*env) HeapFree(GetProcessHeap(), 0, *env);\r
\r
- *env = (char *) HeapAlloc(GetProcessHeap(), 0, *envlen);\r
+ *env = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, *envlen);\r
if (! *env) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, "set_environment()", 0);\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("set_environment()"), 0);\r
return 3;\r
}\r
\r
return 0;\r
}\r
\r
-int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, bool sanitise, bool must_exist) {\r
- unsigned char *buffer = (unsigned char *) HeapAlloc(GetProcessHeap(), 0, datalen);\r
+int expand_parameter(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise, bool must_exist) {\r
+ TCHAR *buffer = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, datalen);\r
if (! buffer) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, "expand_parameter()", 0);\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("expand_parameter()"), 0);\r
return 1;\r
}\r
\r
unsigned long type = REG_EXPAND_SZ;\r
unsigned long buflen = datalen;\r
\r
- unsigned long ret = RegQueryValueEx(key, value, 0, &type, buffer, &buflen);\r
+ unsigned long ret = RegQueryValueEx(key, value, 0, &type, (unsigned char *) buffer, &buflen);\r
if (ret != ERROR_SUCCESS) {\r
unsigned long error = GetLastError();\r
HeapFree(GetProcessHeap(), 0, buffer);\r
}\r
\r
/* Paths aren't allowed to contain quotes. */\r
- if (sanitise) PathUnquoteSpaces((LPSTR) buffer);\r
+ if (sanitise) PathUnquoteSpaces(buffer);\r
\r
/* Technically we shouldn't expand environment strings from REG_SZ values */\r
if (type != REG_EXPAND_SZ) {\r
return 0;\r
}\r
\r
- ret = ExpandEnvironmentStrings((char *) buffer, data, datalen);\r
+ ret = ExpandEnvironmentStrings((TCHAR *) buffer, data, datalen);\r
if (! ret || ret > datalen) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_EXPANDENVIRONMENTSTRINGS_FAILED, buffer, error_string(GetLastError()), 0);\r
HeapFree(GetProcessHeap(), 0, buffer);\r
return 0;\r
}\r
\r
-int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, bool sanitise) {\r
+int expand_parameter(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise) {\r
return expand_parameter(key, value, data, datalen, sanitise, true);\r
}\r
\r
Returns: 0 if it was set.\r
1 on error.\r
*/\r
-int set_expand_string(HKEY key, char *value, char *string) {\r
- if (RegSetValueEx(key, value, 0, REG_EXPAND_SZ, (const unsigned char *) string, (unsigned long) strlen(string) + 1) == ERROR_SUCCESS) return 0;\r
+int set_expand_string(HKEY key, TCHAR *value, TCHAR *string) {\r
+ if (RegSetValueEx(key, value, 0, REG_EXPAND_SZ, (const unsigned char *) string, (unsigned long) (_tcslen(string) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS) return 0;\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, value, error_string(GetLastError()), 0);\r
return 1;\r
}\r
Returns: 0 if it was set.\r
1 on error.\r
*/\r
-int set_number(HKEY key, char *value, unsigned long number) {\r
+int set_number(HKEY key, TCHAR *value, unsigned long number) {\r
if (RegSetValueEx(key, value, 0, REG_DWORD, (const unsigned char *) &number, sizeof(number)) == ERROR_SUCCESS) return 0;\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, value, error_string(GetLastError()), 0);\r
return 1;\r
-1 if none was found and must_exist is true.\r
-2 otherwise.\r
*/\r
-int get_number(HKEY key, char *value, unsigned long *number, bool must_exist) {\r
+int get_number(HKEY key, TCHAR *value, unsigned long *number, bool must_exist) {\r
unsigned long type = REG_DWORD;\r
unsigned long number_len = sizeof(unsigned long);\r
\r
return -2;\r
}\r
\r
-int get_number(HKEY key, char *value, unsigned long *number) {\r
+int get_number(HKEY key, TCHAR *value, unsigned long *number) {\r
return get_number(key, value, number, true);\r
}\r
\r
-void override_milliseconds(char *service_name, HKEY key, char *value, unsigned long *buffer, unsigned long default_value, unsigned long event) {\r
+void override_milliseconds(TCHAR *service_name, HKEY key, TCHAR *value, unsigned long *buffer, unsigned long default_value, unsigned long event) {\r
unsigned long type = REG_DWORD;\r
unsigned long buflen = sizeof(unsigned long);\r
bool ok = false;\r
if (ret != ERROR_SUCCESS) {\r
if (ret != ERROR_FILE_NOT_FOUND) {\r
if (type != REG_DWORD) {\r
- char milliseconds[16];\r
- _snprintf_s(milliseconds, sizeof(milliseconds), _TRUNCATE, "%lu", default_value);\r
+ TCHAR milliseconds[16];\r
+ _sntprintf_s(milliseconds, _countof(milliseconds), _TRUNCATE, _T("%lu"), default_value);\r
log_event(EVENTLOG_WARNING_TYPE, event, service_name, value, milliseconds, 0);\r
}\r
else log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0);\r
unsigned long ret;\r
\r
/* Get registry */\r
- char registry[KEY_LENGTH];\r
- if (_snprintf_s(registry, sizeof(registry), _TRUNCATE, NSSM_REGISTRY, service->name) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "NSSM_REGISTRY", "get_parameters()", 0);\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (_sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY, service->name) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("NSSM_REGISTRY"), _T("get_parameters()"), 0);\r
return 1;\r
}\r
\r
\r
/* Try to get startup directory - may fail and we fall back to a default */\r
if (expand_parameter(key, NSSM_REG_DIR, service->dir, sizeof(service->dir), true) || ! service->dir[0]) {\r
- /* Our buffers are defined to be long enough for this to be safe */\r
- size_t i;\r
- for (i = strlen(service->exe); i && service->exe[i] != '\\' && service->exe[i] != '/'; i--);\r
- if (i) {\r
- memmove(service->dir, service->exe, i);\r
- service->dir[i] = '\0';\r
- }\r
- else {\r
+ _sntprintf_s(service->dir, _countof(service->dir), _TRUNCATE, _T("%s"), service->exe);\r
+ strip_basename(service->dir);\r
+ if (service->dir[0] == _T('\0')) {\r
/* Help! */\r
ret = GetWindowsDirectory(service->dir, sizeof(service->dir));\r
if (! ret || ret > sizeof(service->dir)) {\r
if (service->env) {\r
/* Append extra variables to configured variables. */\r
unsigned long envlen = service->envlen + service->env_extralen - 1;\r
- char *env = (char *) HeapAlloc(GetProcessHeap(), 0, envlen);\r
+ TCHAR *env = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, envlen);\r
if (env) {\r
- memmove(env, service->env, service->envlen - 1);\r
- memmove(env + service->envlen - 1, service->env_extra, service->env_extralen);\r
+ memmove(env, service->env, service->envlen - sizeof(TCHAR));\r
+ /* envlen is in bytes. */\r
+ memmove(env + (service->envlen / sizeof(TCHAR)) - 1, service->env_extra, service->env_extralen);\r
\r
HeapFree(GetProcessHeap(), 0, service->env);\r
service->env = env;\r
service->envlen = envlen;\r
}\r
- else log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "environment", "get_parameters()", 0);\r
+ else log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("get_parameters()"), 0);\r
}\r
else {\r
/* Append extra variables to our environment. */\r
- char *env, *s;\r
+ TCHAR *env, *s;\r
size_t envlen, len;\r
\r
env = service->env_extra;\r
len = 0;\r
while (*env) {\r
- envlen = strlen(env) + 1;\r
- for (s = env; *s && *s != '='; s++);\r
- if (*s == '=') *s++ = '\0';\r
+ envlen = _tcslen(env) + 1;\r
+ for (s = env; *s && *s != _T('='); s++);\r
+ if (*s == _T('=')) *s++ = _T('\0');\r
if (! SetEnvironmentVariable(env, s)) log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_SETENVIRONMENTVARIABLE_FAILED, env, s, error_string(GetLastError()));\r
env += envlen;\r
}\r
return 0;\r
}\r
\r
-int get_exit_action(char *service_name, unsigned long *ret, unsigned char *action, bool *default_action) {\r
+int get_exit_action(TCHAR *service_name, unsigned long *ret, TCHAR *action, bool *default_action) {\r
/* Are we returning the default action or a status-specific one? */\r
*default_action = ! ret;\r
\r
/* Get registry */\r
- char registry[KEY_LENGTH];\r
- if (_snprintf_s(registry, sizeof(registry), _TRUNCATE, NSSM_REGISTRY "\\%s", service_name, NSSM_REG_EXIT) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "NSSM_REG_EXIT", "get_exit_action()", 0);\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (_sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY _T("\\%s"), service_name, NSSM_REG_EXIT) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("NSSM_REG_EXIT"), _T("get_exit_action()"), 0);\r
return 1;\r
}\r
\r
unsigned long type = REG_SZ;\r
unsigned long action_len = ACTION_LEN;\r
\r
- char code[64];\r
- if (! ret) code[0] = '\0';\r
- else if (_snprintf_s(code, sizeof(code), _TRUNCATE, "%lu", *ret) < 0) {\r
+ TCHAR code[16];\r
+ if (! ret) code[0] = _T('\0');\r
+ else if (_sntprintf_s(code, _countof(code), _TRUNCATE, _T("%lu"), *ret) < 0) {\r
RegCloseKey(key);\r
return get_exit_action(service_name, 0, action, default_action);\r
}\r
- if (RegQueryValueEx(key, code, 0, &type, action, &action_len) != ERROR_SUCCESS) {\r
+ if (RegQueryValueEx(key, code, 0, &type, (unsigned char *) action, &action_len) != ERROR_SUCCESS) {\r
RegCloseKey(key);\r
/* Try again with * as the key if an exit code was defined */\r
if (ret) return get_exit_action(service_name, 0, action, default_action);\r
#ifndef REGISTRY_H\r
#define REGISTRY_H\r
\r
-#define NSSM_REGISTRY "SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters"\r
-#define NSSM_REG_EXE "Application"\r
-#define NSSM_REG_FLAGS "AppParameters"\r
-#define NSSM_REG_DIR "AppDirectory"\r
-#define NSSM_REG_ENV "AppEnvironment"\r
-#define NSSM_REG_ENV_EXTRA "AppEnvironmentExtra"\r
-#define NSSM_REG_EXIT "AppExit"\r
-#define NSSM_REG_THROTTLE "AppThrottle"\r
-#define NSSM_REG_STOP_METHOD_SKIP "AppStopMethodSkip"\r
-#define NSSM_REG_KILL_CONSOLE_GRACE_PERIOD "AppStopMethodConsole"\r
-#define NSSM_REG_KILL_WINDOW_GRACE_PERIOD "AppStopMethodWindow"\r
-#define NSSM_REG_KILL_THREADS_GRACE_PERIOD "AppStopMethodThreads"\r
-#define NSSM_REG_STDIN "AppStdin"\r
-#define NSSM_REG_STDOUT "AppStdout"\r
-#define NSSM_REG_STDERR "AppStderr"\r
-#define NSSM_REG_STDIO_SHARING "ShareMode"\r
-#define NSSM_REG_STDIO_DISPOSITION "CreationDisposition"\r
-#define NSSM_REG_STDIO_FLAGS "FlagsAndAttributes"\r
+#define NSSM_REGISTRY _T("SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters")\r
+#define NSSM_REG_EXE _T("Application")\r
+#define NSSM_REG_FLAGS _T("AppParameters")\r
+#define NSSM_REG_DIR _T("AppDirectory")\r
+#define NSSM_REG_ENV _T("AppEnvironment")\r
+#define NSSM_REG_ENV_EXTRA _T("AppEnvironmentExtra")\r
+#define NSSM_REG_EXIT _T("AppExit")\r
+#define NSSM_REG_THROTTLE _T("AppThrottle")\r
+#define NSSM_REG_STOP_METHOD_SKIP _T("AppStopMethodSkip")\r
+#define NSSM_REG_KILL_CONSOLE_GRACE_PERIOD _T("AppStopMethodConsole")\r
+#define NSSM_REG_KILL_WINDOW_GRACE_PERIOD _T("AppStopMethodWindow")\r
+#define NSSM_REG_KILL_THREADS_GRACE_PERIOD _T("AppStopMethodThreads")\r
+#define NSSM_REG_STDIN _T("AppStdin")\r
+#define NSSM_REG_STDOUT _T("AppStdout")\r
+#define NSSM_REG_STDERR _T("AppStderr")\r
+#define NSSM_REG_STDIO_SHARING _T("ShareMode")\r
+#define NSSM_REG_STDIO_DISPOSITION _T("CreationDisposition")\r
+#define NSSM_REG_STDIO_FLAGS _T("FlagsAndAttributes")\r
#define NSSM_STDIO_LENGTH 29\r
\r
int create_messages();\r
int create_parameters(nssm_service_t *);\r
-int create_exit_action(char *, const char *);\r
-int set_environment(char *, HKEY, char *, char **, unsigned long *);\r
-int expand_parameter(HKEY, char *, char *, unsigned long, bool, bool);\r
-int expand_parameter(HKEY, char *, char *, unsigned long, bool);\r
-int set_expand_string(HKEY, char *, char *);\r
-int set_number(HKEY, char *, unsigned long);\r
-int get_number(HKEY, char *, unsigned long *, bool);\r
-int get_number(HKEY, char *, unsigned long *);\r
-void override_milliseconds(char *, HKEY, char *, unsigned long *, unsigned long, unsigned long);\r
+int create_exit_action(TCHAR *, const TCHAR *);\r
+int set_environment(TCHAR *, HKEY, TCHAR *, TCHAR **, unsigned long *);\r
+int expand_parameter(HKEY, TCHAR *, TCHAR *, unsigned long, bool, bool);\r
+int expand_parameter(HKEY, TCHAR *, TCHAR *, unsigned long, bool);\r
+int set_expand_string(HKEY, TCHAR *, TCHAR *);\r
+int set_number(HKEY, TCHAR *, unsigned long);\r
+int get_number(HKEY, TCHAR *, unsigned long *, bool);\r
+int get_number(HKEY, TCHAR *, unsigned long *);\r
+void override_milliseconds(TCHAR *, HKEY, TCHAR *, unsigned long *, unsigned long, unsigned long);\r
int get_parameters(nssm_service_t *, STARTUPINFO *);\r
-int get_exit_action(char *, unsigned long *, unsigned char *, bool *);\r
+int get_exit_action(TCHAR *, unsigned long *, TCHAR *, bool *);\r
\r
#endif\r
\r
extern imports_t imports;\r
\r
-const char *exit_action_strings[] = { "Restart", "Ignore", "Exit", "Suicide", 0 };\r
+const TCHAR *exit_action_strings[] = { _T("Restart"), _T("Ignore"), _T("Exit"), _T("Suicide"), 0 };\r
\r
static inline int throttle_milliseconds(unsigned long throttle) {\r
/* pow() operates on doubles. */\r
/* Allocate and zero memory for a service. */\r
nssm_service_t *alloc_nssm_service() {\r
nssm_service_t *service = (nssm_service_t *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(nssm_service_t));\r
- if (! service) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "service", "alloc_nssm_service()", 0);\r
+ if (! service) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("alloc_nssm_service()"), 0);\r
return service;\r
}\r
\r
}\r
\r
/* About to install the service */\r
-int pre_install_service(int argc, char **argv) {\r
+int pre_install_service(int argc, TCHAR **argv) {\r
/* Show the dialogue box if we didn't give the service name and path */\r
if (argc < 2) return nssm_gui(IDD_INSTALL, argv[0]);\r
\r
nssm_service_t *service = alloc_nssm_service();\r
if (! service) {\r
- print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, "service", "pre_install_service()");\r
+ print_message(stderr, NSSM_EVENT_OUT_OF_MEMORY, _T("service"), _T("pre_install_service()"));\r
return 1;\r
}\r
\r
set_nssm_service_defaults(service);\r
- memmove(service->name, argv[0], strlen(argv[0]));\r
- memmove(service->exe, argv[1], strlen(argv[1]));\r
+ _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]);\r
+ _sntprintf_s(service->exe, _countof(service->exe), _TRUNCATE, _T("%s"), argv[1]);\r
\r
/* Arguments are optional */\r
size_t flagslen = 0;\r
size_t s = 0;\r
int i;\r
- for (i = 2; i < argc; i++) flagslen += strlen(argv[i]) + 1;\r
+ for (i = 2; i < argc; i++) flagslen += _tcslen(argv[i]) + 1;\r
if (! flagslen) flagslen = 1;\r
+ if (flagslen > _countof(service->flags)) {\r
+ print_message(stderr, NSSM_MESSAGE_FLAGS_TOO_LONG);\r
+ return 2;\r
+ }\r
\r
- /*\r
- This probably isn't UTF8-safe and should use std::string or something\r
- but it's been broken for the best part of a decade and due for a rewrite\r
- anyway so it'll do as a quick-'n'-dirty fix. Note that we don't free\r
- the flags buffer but as the program exits that isn't a big problem.\r
- */\r
for (i = 2; i < argc; i++) {\r
- size_t len = strlen(argv[i]);\r
- memmove(service->flags + s, argv[i], len);\r
+ size_t len = _tcslen(argv[i]);\r
+ memmove(service->flags + s, argv[i], len * sizeof(TCHAR));\r
s += len;\r
- if (i < argc - 1) service->flags[s++] = ' ';\r
+ if (i < argc - 1) service->flags[s++] = _T(' ');\r
}\r
\r
/* Work out directory name */\r
- memmove(service->dir, service->exe, sizeof(service->dir));\r
+ _sntprintf_s(service->dir, _countof(service->dir), _TRUNCATE, _T("%s"), service->exe);\r
strip_basename(service->dir);\r
\r
int ret = install_service(service);\r
}\r
\r
/* About to remove the service */\r
-int pre_remove_service(int argc, char **argv) {\r
+int pre_remove_service(int argc, TCHAR **argv) {\r
/* Show dialogue box if we didn't pass service name and "confirm" */\r
if (argc < 2) return nssm_gui(IDD_REMOVE, argv[0]);\r
- if (str_equiv(argv[1], "confirm")) {\r
+ if (str_equiv(argv[1], _T("confirm"))) {\r
nssm_service_t *service = alloc_nssm_service();\r
- memmove(service->name, argv[0], strlen(argv[0]));\r
+ _sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]);\r
int ret = remove_service(service);\r
cleanup_nssm_service(service);\r
return ret;\r
}\r
\r
/* Get path of this program */\r
- char path[MAX_PATH];\r
+ TCHAR path[MAX_PATH];\r
GetModuleFileName(0, path, MAX_PATH);\r
\r
/* Construct command */\r
- char command[CMD_LENGTH];\r
- size_t pathlen = strlen(path);\r
+ TCHAR command[CMD_LENGTH];\r
+ size_t pathlen = _tcslen(path);\r
if (pathlen + 1 >= VALUE_LENGTH) {\r
print_message(stderr, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
return 3;\r
}\r
- if (_snprintf_s(command, sizeof(command), _TRUNCATE, "\"%s\"", path) < 0) {\r
+ if (_sntprintf_s(command, sizeof(command), _TRUNCATE, _T("\"%s\""), path) < 0) {\r
print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
return 4;\r
}\r
}\r
\r
/* Service initialisation */\r
-void WINAPI service_main(unsigned long argc, char **argv) {\r
+void WINAPI service_main(unsigned long argc, TCHAR **argv) {\r
nssm_service_t *service = alloc_nssm_service();\r
if (! service) return;\r
\r
- if (_snprintf_s(service->name, sizeof(service->name), _TRUNCATE, "%s", argv[0]) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "service->name", "service_main()", 0);\r
+ if (_sntprintf_s(service->name, _countof(service->name), _TRUNCATE, _T("%s"), argv[0]) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("service->name"), _T("service_main()"), 0);\r
return;\r
}\r
\r
/* Set service status to started */\r
int ret = start_service(service);\r
if (ret) {\r
- char code[16];\r
- _snprintf_s(code, sizeof(code), _TRUNCATE, "%d", ret);\r
+ TCHAR code[16];\r
+ _sntprintf_s(code, _countof(code), _TRUNCATE, _T("%d"), ret);\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_START_SERVICE_FAILED, service->exe, service->name, ret, 0);\r
return ret;\r
}\r
return 0;\r
}\r
\r
-char *service_control_text(unsigned long control) {\r
+TCHAR *service_control_text(unsigned long control) {\r
switch (control) {\r
/* HACK: there is no SERVICE_CONTROL_START constant */\r
- case 0: return "START";\r
- case SERVICE_CONTROL_STOP: return "STOP";\r
- case SERVICE_CONTROL_SHUTDOWN: return "SHUTDOWN";\r
- case SERVICE_CONTROL_PAUSE: return "PAUSE";\r
- case SERVICE_CONTROL_CONTINUE: return "CONTINUE";\r
- case SERVICE_CONTROL_INTERROGATE: return "INTERROGATE";\r
+ case 0: return _T("START");\r
+ case SERVICE_CONTROL_STOP: return _T("STOP");\r
+ case SERVICE_CONTROL_SHUTDOWN: return _T("SHUTDOWN");\r
+ case SERVICE_CONTROL_PAUSE: return _T("PAUSE");\r
+ case SERVICE_CONTROL_CONTINUE: return _T("CONTINUE");\r
+ case SERVICE_CONTROL_INTERROGATE: return _T("INTERROGATE");\r
default: return 0;\r
}\r
}\r
\r
-void log_service_control(char *service_name, unsigned long control, bool handled) {\r
- char *text = service_control_text(control);\r
+void log_service_control(TCHAR *service_name, unsigned long control, bool handled) {\r
+ TCHAR *text = service_control_text(control);\r
unsigned long event;\r
\r
if (! text) {\r
/* "0x" + 8 x hex + NULL */\r
- text = (char *) HeapAlloc(GetProcessHeap(), 0, 11);\r
+ text = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, 11 * sizeof(TCHAR));\r
if (! text) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "control code", "log_service_control()", 0);\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("control code"), _T("log_service_control()"), 0);\r
return;\r
}\r
- if (_snprintf_s(text, 11, _TRUNCATE, "0x%08x", control) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "control code", "log_service_control()", 0);\r
+ if (_sntprintf_s(text, 11, _TRUNCATE, _T("0x%08x"), control) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("control code"), _T("log_service_control()"), 0);\r
HeapFree(GetProcessHeap(), 0, text);\r
return;\r
}\r
}\r
\r
/* Launch executable with arguments */\r
- char cmd[CMD_LENGTH];\r
- if (_snprintf_s(cmd, sizeof(cmd), _TRUNCATE, "\"%s\" %s", service->exe, service->flags) < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, "command line", "start_service", 0);\r
+ TCHAR cmd[CMD_LENGTH];\r
+ if (_sntprintf_s(cmd, _countof(cmd), _TRUNCATE, _T("\"%s\" %s"), service->exe, service->flags) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("command line"), _T("start_service"), 0);\r
close_output_handles(&si);\r
return stop_service(service, 2, true, true);\r
}\r
\r
bool inherit_handles = false;\r
if (si.dwFlags & STARTF_USESTDHANDLES) inherit_handles = true;\r
- if (! CreateProcess(0, cmd, 0, 0, inherit_handles, 0, service->env, service->dir, &si, &pi)) {\r
+ unsigned long flags = 0;\r
+#ifdef UNICODE\r
+ flags |= CREATE_UNICODE_ENVIRONMENT;\r
+#endif\r
+ if (! CreateProcess(0, cmd, 0, 0, inherit_handles, flags, service->env, service->dir, &si, &pi)) {\r
unsigned long error = GetLastError();\r
if (error == ERROR_INVALID_PARAMETER && service->env) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEPROCESS_FAILED_INVALID_ENVIRONMENT, service->name, service->exe, NSSM_REG_ENV, 0);\r
else log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEPROCESS_FAILED, service->name, service->exe, error_string(error), 0);\r
*/\r
unsigned long delay = service->throttle_delay;\r
if (delay > NSSM_SERVICE_STATUS_DEADLINE) {\r
- char delay_milliseconds[16];\r
- _snprintf_s(delay_milliseconds, sizeof(delay_milliseconds), _TRUNCATE, "%lu", delay);\r
- char deadline_milliseconds[16];\r
- _snprintf_s(deadline_milliseconds, sizeof(deadline_milliseconds), _TRUNCATE, "%lu", NSSM_SERVICE_STATUS_DEADLINE);\r
+ TCHAR delay_milliseconds[16];\r
+ _sntprintf_s(delay_milliseconds, _countof(delay_milliseconds), _TRUNCATE, _T("%lu"), delay);\r
+ TCHAR deadline_milliseconds[16];\r
+ _sntprintf_s(deadline_milliseconds, _countof(deadline_milliseconds), _TRUNCATE, _T("%lu"), NSSM_SERVICE_STATUS_DEADLINE);\r
log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_STARTUP_DELAY_TOO_LONG, service->name, delay_milliseconds, NSSM, deadline_milliseconds, 0);\r
delay = NSSM_SERVICE_STATUS_DEADLINE;\r
}\r
\r
/* Check exit code */\r
unsigned long exitcode = 0;\r
- char code[16];\r
+ TCHAR code[16];\r
GetExitCodeProcess(service->process_handle, &exitcode);\r
if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
CloseHandle(service->process_handle);\r
tree. See below for the possible values of the why argument.\r
*/\r
if (! why) {\r
- _snprintf_s(code, sizeof(code), _TRUNCATE, "%lu", exitcode);\r
+ _sntprintf_s(code, _countof(code), _TRUNCATE, _T("%lu"), exitcode);\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_ENDED_SERVICE, service->exe, service->name, code, 0);\r
}\r
\r
\r
/* What action should we take? */\r
int action = NSSM_EXIT_RESTART;\r
- unsigned char action_string[ACTION_LEN];\r
+ TCHAR action_string[ACTION_LEN];\r
bool default_action;\r
if (! get_exit_action(service->name, &exitcode, action_string, &default_action)) {\r
for (int i = 0; exit_action_strings[i]; i++) {\r
- if (! _strnicmp((const char *) action_string, exit_action_strings[i], ACTION_LEN)) {\r
+ if (! _tcsnicmp((const TCHAR *) action_string, exit_action_strings[i], ACTION_LEN)) {\r
action = i;\r
break;\r
}\r
\r
if (service->throttle > 7) service->throttle = 8;\r
\r
- char threshold[8], milliseconds[8];\r
- _snprintf_s(threshold, sizeof(threshold), _TRUNCATE, "%lu", service->throttle_delay);\r
- _snprintf_s(milliseconds, sizeof(milliseconds), _TRUNCATE, "%lu", ms);\r
+ TCHAR threshold[8], milliseconds[8];\r
+ _sntprintf_s(threshold, _countof(threshold), _TRUNCATE, _T("%lu"), service->throttle_delay);\r
+ _sntprintf_s(milliseconds, _countof(milliseconds), _TRUNCATE, _T("%lu"), ms);\r
log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service->name, threshold, milliseconds, 0);\r
\r
if (use_critical_section) EnterCriticalSection(&service->throttle_section);\r
0 if the wait completed.\r
-1 on error.\r
*/\r
-int await_shutdown(nssm_service_t *service, char *function_name, unsigned long timeout) {\r
+int await_shutdown(nssm_service_t *service, TCHAR *function_name, unsigned long timeout) {\r
unsigned long interval;\r
unsigned long waithint;\r
unsigned long ret;\r
unsigned long waited;\r
- char interval_milliseconds[16];\r
- char timeout_milliseconds[16];\r
- char waited_milliseconds[16];\r
- char *function = function_name;\r
+ TCHAR interval_milliseconds[16];\r
+ TCHAR timeout_milliseconds[16];\r
+ TCHAR waited_milliseconds[16];\r
+ TCHAR *function = function_name;\r
\r
/* Add brackets to function name. */\r
- size_t funclen = strlen(function_name) + 3;\r
- char *func = (char *) HeapAlloc(GetProcessHeap(), 0, funclen);\r
+ size_t funclen = _tcslen(function_name) + 3;\r
+ TCHAR *func = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, funclen * sizeof(TCHAR));\r
if (func) {\r
- if (_snprintf_s(func, funclen, _TRUNCATE, "%s()", function_name) > -1) function = func;\r
+ if (_sntprintf_s(func, funclen, _TRUNCATE, _T("%s()"), function_name) > -1) function = func;\r
}\r
\r
- _snprintf_s(timeout_milliseconds, sizeof(timeout_milliseconds), _TRUNCATE, "%lu", timeout);\r
+ _sntprintf_s(timeout_milliseconds, _countof(timeout_milliseconds), _TRUNCATE, _T("%lu"), timeout);\r
\r
waithint = service->status.dwWaitHint;\r
waited = 0;\r
SetServiceStatus(service->status_handle, &service->status);\r
\r
if (waited) {\r
- _snprintf_s(waited_milliseconds, sizeof(waited_milliseconds), _TRUNCATE, "%lu", waited);\r
- _snprintf_s(interval_milliseconds, sizeof(interval_milliseconds), _TRUNCATE, "%lu", interval);\r
+ _sntprintf_s(waited_milliseconds, _countof(waited_milliseconds), _TRUNCATE, _T("%lu"), waited);\r
+ _sntprintf_s(interval_milliseconds, _countof(interval_milliseconds), _TRUNCATE, _T("%lu"), interval);\r
log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_AWAITING_SHUTDOWN, function, service->name, waited_milliseconds, interval_milliseconds, timeout_milliseconds, 0);\r
}\r
\r
#define ACTION_LEN 16\r
\r
typedef struct {\r
- char name[SERVICE_NAME_LENGTH];\r
- char exe[EXE_LENGTH];\r
- char flags[VALUE_LENGTH];\r
- char dir[MAX_PATH];\r
- char *env;\r
+ TCHAR name[SERVICE_NAME_LENGTH];\r
+ TCHAR exe[EXE_LENGTH];\r
+ TCHAR flags[VALUE_LENGTH];\r
+ TCHAR dir[MAX_PATH];\r
+ TCHAR *env;\r
unsigned long envlen;\r
- char *env_extra;\r
+ TCHAR *env_extra;\r
unsigned long env_extralen;\r
- char stdin_path[MAX_PATH];\r
+ TCHAR stdin_path[MAX_PATH];\r
unsigned long stdin_sharing;\r
unsigned long stdin_disposition;\r
unsigned long stdin_flags;\r
- char stdout_path[MAX_PATH];\r
+ TCHAR stdout_path[MAX_PATH];\r
unsigned long stdout_sharing;\r
unsigned long stdout_disposition;\r
unsigned long stdout_flags;\r
- char stderr_path[MAX_PATH];\r
+ TCHAR stderr_path[MAX_PATH];\r
unsigned long stderr_sharing;\r
unsigned long stderr_disposition;\r
unsigned long stderr_flags;\r
FILETIME exit_time;\r
} nssm_service_t;\r
\r
-void WINAPI service_main(unsigned long, char **);\r
-char *service_control_text(unsigned long);\r
-void log_service_control(char *, unsigned long, bool);\r
+void WINAPI service_main(unsigned long, TCHAR **);\r
+TCHAR *service_control_text(unsigned long);\r
+void log_service_control(TCHAR *, unsigned long, bool);\r
unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);\r
\r
nssm_service_t *alloc_nssm_service();\r
void set_nssm_service_defaults(nssm_service_t *);\r
void cleanup_nssm_service(nssm_service_t *);\r
SC_HANDLE open_service_manager();\r
-int pre_install_service(int, char **);\r
-int pre_remove_service(int, char **);\r
+int pre_install_service(int, TCHAR **);\r
+int pre_remove_service(int, TCHAR **);\r
int install_service(nssm_service_t *);\r
int remove_service(nssm_service_t *);\r
void set_service_recovery(nssm_service_t *);\r
int stop_service(nssm_service_t *, unsigned long, bool, bool);\r
void CALLBACK end_service(void *, unsigned char);\r
void throttle_restart(nssm_service_t *);\r
-int await_shutdown(nssm_service_t *, char *, unsigned long);\r
+int await_shutdown(nssm_service_t *, TCHAR *, unsigned long);\r
\r
#endif\r