X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=nssm.cpp;h=a60c3784ff4fffea7862aee852e943fc496396ca;hb=cba3331a303deccf228fec50f30a87ed9ec784ce;hp=1ee38bdb9db12d67c4a60ad753b20a464992cf57;hpb=d835729cc86c54b1ecde6ffce737c41aa8d3f840;p=nssm.git diff --git a/nssm.cpp b/nssm.cpp index 1ee38bd..a60c378 100644 --- a/nssm.cpp +++ b/nssm.cpp @@ -2,6 +2,7 @@ extern unsigned long tls_index; extern bool is_admin; +extern imports_t imports; /* String function */ int str_equiv(const char *a, const char *b) { @@ -12,6 +13,16 @@ int str_equiv(const char *a, const char *b) { } } +/* Remove basename of a path. */ +void strip_basename(char *buffer) { + size_t len = strlen(buffer); + size_t i; + for (i = len; i && buffer[i] != '\\' && buffer[i] != '/'; i--); + /* X:\ is OK. */ + if (i && buffer[i-1] == ':') i++; + buffer[i] = '\0'; +} + /* How to use me correctly */ int usage(int ret) { print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE); @@ -69,6 +80,9 @@ int main(int argc, char **argv) { This will save time when running with no arguments from a command prompt. */ if (_fileno(stdin) < 0) { + /* Set up function pointers. */ + if (get_imports()) exit(111); + /* Start service magic */ SERVICE_TABLE_ENTRY table[] = { { NSSM, service_main }, { 0, 0 } }; if (! StartServiceCtrlDispatcher(table)) { @@ -76,6 +90,7 @@ int main(int argc, char **argv) { /* User probably ran nssm with no argument */ if (error == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) exit(usage(1)); log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_DISPATCHER_FAILED, error_string(error), 0); + free_imports(); exit(100); } }