SC_HANDLE manager = NULL;
SC_HANDLE service = NULL;
SERVICE_STATUS status = {0};
+ bool success = false;
manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(!manager) {
fprintf(stderr, "Could not open service manager: %s\n", winerror(GetLastError()));
- return false;
+ goto exit;
}
service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
if(!service) {
fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError()));
- return false;
+ goto exit;
}
if(!ControlService(service, SERVICE_CONTROL_STOP, &status)) {
if(!DeleteService(service)) {
fprintf(stderr, "Could not remove %s service: %s\n", identname, winerror(GetLastError()));
- return false;
+ goto exit;
}
- fprintf(stderr, "%s service removed\n", identname);
+ success = true;
- return true;
+exit:
+
+ if(service) {
+ CloseServiceHandle(service);
+ }
+
+ if(manager) {
+ CloseServiceHandle(manager);
+ }
+
+ if(success) {
+ fprintf(stderr, "%s service removed\n", identname);
+ }
+
+ return success;
}
#endif
#endif
// Pass all log messages from the umbilical to stderr.
- // A nul-byte right before closure means tincd started succesfully.
+ // A nul-byte right before closure means tincd started successfully.
bool failure = true;
char buf[1024];
ssize_t len;
}
}
- /* Change "add" into "set" for variables that do not allow multiple occurences.
+ /* Change "add" into "set" for variables that do not allow multiple occurrences.
Turn on warnings when it seems variables might be removed unintentionally. */
if(action == 1 && !(variables[i].type & VAR_MULTIPLE)) {