]> git.meshlink.io Git - meshlink/commitdiff
Start a tinc service if it already exists.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 1 Nov 2009 14:57:28 +0000 (15:57 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 1 Nov 2009 14:57:28 +0000 (15:57 +0100)
src/process.c

index 01ebe494ba7c79b0ab2cc62cb0b5c2454da2537f..6d0e499aa5fddbf7aa031ffa8301028f3ef3670b 100644 (file)
@@ -103,13 +103,18 @@ bool install_service(void) {
                        command, NULL, NULL, NULL, NULL, NULL);
        
        if(!service) {
-               logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(GetLastError()));
-               return false;
+               DWORD lasterror = GetLastError();
+               logger(LOG_ERR, "Could not create %s service: %s", identname, winerror(lasterror));
+               if(lasterror != ERROR_SERVICE_EXISTS)
+                       return false;
        }
 
-       ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description);
-
-       logger(LOG_INFO, "%s service installed", identname);
+       if(service) {
+               ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &description);
+               logger(LOG_INFO, "%s service installed", identname);
+       } else {
+               service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
+       }
 
        if(!StartService(service, 0, NULL))
                logger(LOG_WARNING, "Could not start %s service: %s", identname, winerror(GetLastError()));