}
}
+static bool stop_tincd(void) {
+ if(!connect_tincd(true)) {
+ return false;
+ }
+
+ sendline(fd, "%d %d", CONTROL, REQ_STOP);
+
+ while(recvline(fd, line, sizeof(line))) {
+ // wait for tincd to close the connection...
+ }
+
+ close(fd);
+ pid = 0;
+ fd = -1;
+
+ return true;
+}
+
#ifdef HAVE_MINGW
static bool remove_service(void) {
SC_HANDLE manager = NULL;
service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
if(!service) {
- fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError()));
+ if(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) {
+ success = stop_tincd();
+ } else {
+ fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError()));
+ }
+
goto exit;
}
return false;
}
-#ifdef HAVE_MINGW
unsigned long arg = 0;
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
}
}
-#endif
-
if(connect(fd, res->ai_addr, res->ai_addrlen) < 0) {
if(verbose) {
fprintf(stderr, "Cannot connect to %s port %s: %s\n", host, port, sockstrerror(sockerrno));
return 1;
}
-#ifndef HAVE_MINGW
+#ifdef HAVE_MINGW
+ return remove_service();
+#else
- if(!connect_tincd(true)) {
+ if(!stop_tincd()) {
if(pid) {
if(kill(pid, SIGTERM)) {
fprintf(stderr, "Could not send TERM signal to process with PID %d: %s\n", pid, strerror(errno));
return 1;
}
- sendline(fd, "%d %d", CONTROL, REQ_STOP);
-
- while(recvline(fd, line, sizeof(line))) {
- // Wait for tincd to close the connection...
- }
-
-#else
-
- if(!remove_service()) {
- return 1;
- }
-
-#endif
- close(fd);
- pid = 0;
- fd = -1;
-
return 0;
+#endif
}
static int cmd_restart(int argc, char *argv[]) {