}\r
\r
int main(int argc, char **argv) {\r
- /* Require an argument since users may try to run nssm directly */\r
- if (argc == 1) exit(usage(1));\r
-\r
/* Elevate */\r
- if (str_equiv(argv[1], "install") || str_equiv(argv[1], "remove")) {\r
- if (check_admin(argv[1])) exit(100);\r
- }\r
+ if (argc > 1) {\r
+ if (str_equiv(argv[1], "install") || str_equiv(argv[1], "remove")) {\r
+ if (check_admin(argv[1])) exit(100);\r
+ }\r
\r
- /* Valid commands are install or remove */\r
- if (str_equiv(argv[1], "install")) {\r
- exit(pre_install_service(argc - 2, argv + 2));\r
+ /* Valid commands are install or remove */\r
+ if (str_equiv(argv[1], "install")) {\r
+ exit(pre_install_service(argc - 2, argv + 2));\r
+ }\r
+ if (str_equiv(argv[1], "remove")) {\r
+ exit(pre_remove_service(argc - 2, argv + 2));\r
+ }\r
}\r
- if (str_equiv(argv[1], "remove")) {\r
- exit(pre_remove_service(argc - 2, argv + 2));\r
- }\r
- /* Undocumented: "run" is used to actually do service stuff */\r
- if (! str_equiv(argv[1], NSSM_RUN)) exit(usage(2));\r
\r
/* Thread local storage for error message buffer */\r
tls_index = TlsAlloc();\r
/* Start service magic */\r
SERVICE_TABLE_ENTRY table[] = { { NSSM, service_main }, { 0, 0 } };\r
if (! StartServiceCtrlDispatcher(table)) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DISPATCHER_FAILED, error_string(GetLastError()), 0);\r
- return 100;\r
+ unsigned long error = GetLastError();\r
+ /* User probably ran nssm with no argument */\r
+ if (error == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) exit(usage(1));\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DISPATCHER_FAILED, error_string(error), 0);\r
+ exit(100);\r
}\r
\r
/* And nothing more to do */\r
- return 0;\r
+ exit(0);\r
}\r
\r
/* Construct command */\r
char command[CMD_LENGTH];\r
- size_t runlen = strlen(NSSM_RUN);\r
size_t pathlen = strlen(path);\r
- if (pathlen + runlen + 2 >= VALUE_LENGTH) {\r
+ if (pathlen + 1 >= VALUE_LENGTH) {\r
fprintf(stderr, "The full path to " NSSM " is too long!\n");\r
return 3;\r
}\r
- if (_snprintf(command, sizeof(command), "\"%s\" %s", path, NSSM_RUN) < 0) {\r
+ if (_snprintf(command, sizeof(command), "\"%s\"", path) < 0) {\r
fprintf(stderr, "Out of memory for ImagePath!\n");\r
return 4;\r
}\r