#ifndef NSSM_H\r
#define NSSM_H\r
\r
+/*\r
+ MSDN says, basically, that the maximum length of a path is 260 characters,\r
+ which is represented by the constant MAX_PATH. Except when it isn't.\r
+\r
+ The maximum length of a directory path is MAX_PATH - 12 because it must be\r
+ possible to create a file in 8.3 format under any valid directory.\r
+\r
+ Unicode versions of filesystem API functions accept paths up to 32767\r
+ characters if the first four (wide) characters are L"\\?\" and each component\r
+ of the path, separated by L"\", does not exceed the value of\r
+ lpMaximumComponentLength returned by GetVolumeInformation(), which is\r
+ probably 255. But might not be.\r
+\r
+ Relative paths are always limited to MAX_PATH because the L"\\?\" prefix\r
+ is not valid for a relative path.\r
+\r
+ Note that we don't care about the last two paragraphs because we're only\r
+ concerned with allocating buffers big enough to store valid paths. If the\r
+ user tries to store invalid paths they will fit in the buffers but the\r
+ application will fail. The reason for the failure will end up in the\r
+ event log and the user will realise the mistake.\r
+\r
+ So that's that cleared up, then.\r
+*/\r
+#ifdef UNICODE\r
+#define PATH_LENGTH 32767\r
+#else\r
+#define PATH_LENGTH MAX_PATH\r
+#endif\r
+#define DIR_LENGTH PATH_LENGTH - 12\r
+\r
#define _WIN32_WINNT 0x0500\r
+#include <fcntl.h>\r
+#include <io.h>\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 "account.h"\r
+#include "console.h"\r
+#include "env.h"\r
#include "event.h"\r
+#include "imports.h"\r
#include "messages.h"\r
+#include "process.h"\r
#include "registry.h"\r
-#include "service.h"\r
+#include "settings.h"\r
+#include "io.h"\r
#include "gui.h"\r
\r
-int str_equiv(const char *, const char *);\r
+int str_equiv(const TCHAR *, const TCHAR *);\r
+void strip_basename(TCHAR *);\r
+int str_number(const TCHAR *, unsigned long *, TCHAR **);\r
+int str_number(const TCHAR *, unsigned long *);\r
+int num_cpus();\r
+int usage(int);\r
+\r
+#define NSSM _T("NSSM")\r
+#ifdef _WIN64\r
+#define NSSM_ARCHITECTURE _T("64-bit")\r
+#else\r
+#define NSSM_ARCHITECTURE _T("32-bit")\r
+#endif\r
+#ifdef _DEBUG\r
+#define NSSM_DEBUG _T(" debug")\r
+#else\r
+#define NSSM_DEBUG _T("")\r
+#endif\r
+#define NSSM_CONFIGURATION NSSM_ARCHITECTURE NSSM_DEBUG\r
+#include "version.h"\r
\r
-#define NSSM "nssm"\r
-#define NSSM_VERSION "2.5"\r
-#define NSSM_DATE "2010-09-25"\r
-#define NSSM_RUN "run"\r
+/*\r
+ Throttle the restart of the service if it stops before this many\r
+ milliseconds have elapsed since startup. Override in registry.\r
+*/\r
+#define NSSM_RESET_THROTTLE_RESTART 1500\r
\r
/*\r
- MSDN says the commandline in CreateProcess() is limited to 32768 characters\r
- and the application name to MAX_PATH.\r
- A registry key is limited to 255 characters.\r
- A registry value is limited to 16383 characters.\r
- Therefore we limit the service name to accommodate the path under HKLM.\r
+ How many milliseconds to wait for the application to die after sending\r
+ a Control-C event to its console. Override in registry.\r
+*/\r
+#define NSSM_KILL_CONSOLE_GRACE_PERIOD 1500\r
+/*\r
+ How many milliseconds to wait for the application to die after posting to\r
+ its windows' message queues. Override in registry.\r
*/\r
-#define EXE_LENGTH MAX_PATH\r
-#define CMD_LENGTH 32768\r
-#define KEY_LENGTH 255\r
-#define VALUE_LENGTH 16383\r
-#define SERVICE_NAME_LENGTH KEY_LENGTH - 55\r
+#define NSSM_KILL_WINDOW_GRACE_PERIOD 1500\r
+/*\r
+ How many milliseconds to wait for the application to die after posting to\r
+ its threads' message queues. Override in registry.\r
+*/\r
+#define NSSM_KILL_THREADS_GRACE_PERIOD 1500\r
+\r
+/* How many milliseconds to pause after rotating logs. */\r
+#define NSSM_ROTATE_DELAY 0\r
+\r
+/* Margin of error for service status wait hints in milliseconds. */\r
+#define NSSM_WAITHINT_MARGIN 2000\r
+\r
+/* Methods used to try to stop the application. */\r
+#define NSSM_STOP_METHOD_CONSOLE (1 << 0)\r
+#define NSSM_STOP_METHOD_WINDOW (1 << 1)\r
+#define NSSM_STOP_METHOD_THREADS (1 << 2)\r
+#define NSSM_STOP_METHOD_TERMINATE (1 << 3)\r
+\r
+/* Startup types. */\r
+#define NSSM_STARTUP_AUTOMATIC 0\r
+#define NSSM_STARTUP_DELAYED 1\r
+#define NSSM_STARTUP_MANUAL 2\r
+#define NSSM_STARTUP_DISABLED 3\r
+\r
+/* Exit actions. */\r
+#define NSSM_EXIT_RESTART 0\r
+#define NSSM_EXIT_IGNORE 1\r
+#define NSSM_EXIT_REALLY 2\r
+#define NSSM_EXIT_UNCLEAN 3\r
+#define NSSM_NUM_EXIT_ACTIONS 4\r
+\r
+/* Process priority. */\r
+#define NSSM_REALTIME_PRIORITY 0\r
+#define NSSM_HIGH_PRIORITY 1\r
+#define NSSM_ABOVE_NORMAL_PRIORITY 2\r
+#define NSSM_NORMAL_PRIORITY 3\r
+#define NSSM_BELOW_NORMAL_PRIORITY 4\r
+#define NSSM_IDLE_PRIORITY 5\r
+\r
+/* How many milliseconds to wait before updating service status. */\r
+#define NSSM_SERVICE_STATUS_DEADLINE 20000\r
+\r
+/* User-defined service controls can be in the range 128-255. */\r
+#define NSSM_SERVICE_CONTROL_START 0\r
+#define NSSM_SERVICE_CONTROL_ROTATE 128\r
\r
#endif\r