check for daemon pid existence before trying to connect to the control socket, and...
[tinc] / src / tincctl.c
index f41e030..39a11d3 100644 (file)
@@ -718,6 +718,13 @@ bool connect_tincd(bool verbose) {
        }
 
        fclose(f);
+       if ((pid == 0) || (kill(pid, 0) && (errno == ESRCH))) {
+               fprintf(stderr, "Could not find tincd running at pid %d\n", pid);
+               /* clean up the stale socket and pid file */
+               unlink(pidfilename);
+               unlink(unixsocketname);
+               return false;
+       }
 
 #ifndef HAVE_MINGW
        struct sockaddr_un sa;
@@ -2517,6 +2524,7 @@ static int cmd_verify(int argc, char *argv[]) {
        }
 
        *newline++ = '\0';
+       size_t skip = newline - data;
 
        char signer[MAX_STRING_SIZE] = "";
        char sig[MAX_STRING_SIZE] = "";
@@ -2543,6 +2551,8 @@ static int cmd_verify(int argc, char *argv[]) {
        memcpy(data + len, trailer, trailer_len);
        free(trailer);
 
+       newline = data + skip;
+
        char fname[PATH_MAX];
        snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, node);
        FILE *fp = fopen(fname, "r");