]> git.meshlink.io Git - meshlink/commitdiff
"tincctl stop" now removes the tinc service on Windows.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 17 Jul 2011 17:23:52 +0000 (19:23 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 17 Jul 2011 17:23:52 +0000 (19:23 +0200)
src/process.c
src/tincctl.c

index 0584da675816b9c38fededdb081e07cdf826c49f..a7d0f260ec448a07850c861e66b23fcb698afbca 100644 (file)
@@ -53,7 +53,7 @@ static SC_HANDLE service = NULL;
 static SERVICE_STATUS status = {0};
 static SERVICE_STATUS_HANDLE statushandle = 0;
 
-bool install_service(void) {
+static bool install_service(void) {
        char command[4096] = "\"";
        char **argp;
        bool space;
@@ -113,35 +113,6 @@ bool install_service(void) {
        return true;
 }
 
-bool remove_service(void) {
-       manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-       if(!manager) {
-               logger(LOG_ERR, "Could not open service manager: %s", winerror(GetLastError()));
-               return false;
-       }
-
-       service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
-
-       if(!service) {
-               logger(LOG_ERR, "Could not open %s service: %s", identname, winerror(GetLastError()));
-               return false;
-       }
-
-       if(!ControlService(service, SERVICE_CONTROL_STOP, &status))
-               logger(LOG_ERR, "Could not stop %s service: %s", identname, winerror(GetLastError()));
-       else
-               logger(LOG_INFO, "%s service stopped", identname);
-
-       if(!DeleteService(service)) {
-               logger(LOG_ERR, "Could not remove %s service: %s", identname, winerror(GetLastError()));
-               return false;
-       }
-
-       logger(LOG_INFO, "%s service removed", identname);
-
-       return true;
-}
-
 DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
        switch(request) {
                case SERVICE_CONTROL_INTERROGATE:
index ebd2e1301887caca3d913f509726cfbdea136a2c..f7f23c145266817f7f764f93f5e102cd425aa439 100644 (file)
@@ -482,6 +482,41 @@ void pcap(int fd, FILE *out) {
        }
 }
 
+#ifdef HAVE_MINGW
+static bool remove_service(void) {
+       SC_HANDLE manager = NULL;
+       SC_HANDLE service = NULL;
+       SERVICE_STATUS status = {0};
+
+       manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+       if(!manager) {
+               fprintf(stderr, "Could not open service manager: %s\n", winerror(GetLastError()));
+               return false;
+       }
+
+       service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
+
+       if(!service) {
+               fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError()));
+               return false;
+       }
+
+       if(!ControlService(service, SERVICE_CONTROL_STOP, &status))
+               fprintf(stderr, "Could not stop %s service: %s\n", identname, winerror(GetLastError()));
+       else
+               fprintf(stderr, "%s service stopped", identname);
+
+       if(!DeleteService(service)) {
+               fprintf(stderr, "Could not remove %s service: %s\n", identname, winerror(GetLastError()));
+               return false;
+       }
+
+       fprintf(stderr, "%s service removed\n", identname);
+
+       return true;
+}
+#endif
+
 int main(int argc, char *argv[], char *envp[]) {
        int fd;
        int result;
@@ -622,11 +657,16 @@ int main(int argc, char *argv[], char *envp[]) {
        }
 
        if(!strcasecmp(argv[optind], "stop")) {
+#ifndef HAVE_MINGW
                sendline(fd, "%d %d", CONTROL, REQ_STOP);
                if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_STOP || result) {
                        fprintf(stderr, "Could not stop tinc daemon\n");
                        return 1;
                }
+#else
+               if(!remove_service())
+                       return 1;
+#endif
                return 0;
        }