]> git.meshlink.io Git - meshlink/blobdiff - src/tincctl.c
Let tincctl use the NETNAME environment variable if no -n option is given.
[meshlink] / src / tincctl.c
index a7f6185f0716b93164763854b43f8c5c774cffae..d1df07beefbd803b0b53122aab0088bd1e485dd7 100644 (file)
@@ -138,6 +138,12 @@ static bool parse_options(int argc, char **argv) {
                }
        }
 
+       if(!netname) {
+               netname = getenv("NETNAME");
+               if(netname)
+                       netname = xstrdup(netname);
+       }
+
        return true;
 }
 
@@ -516,7 +522,7 @@ static bool remove_service(void) {
 }
 #endif
 
-int main(int argc, char *argv[], char *envp[]) {
+int main(int argc, char *argv[]) {
        int fd;
        int result;
        char host[128];
@@ -568,9 +574,26 @@ int main(int argc, char *argv[], char *envp[]) {
        }
 
        if(!strcasecmp(argv[optind], "start")) {
-               argv[optind] = NULL;
-               execve(SBINDIR "/tincd", argv, envp);
-               fprintf(stderr, "Could not start tincd: %s", strerror(errno));
+               int i, j;
+               char *c;
+               char *slash = strrchr(argv[0], '/');
+#ifdef HAVE_MINGW
+               if ((c = strrchr(argv[0], '\\')) > slash)
+                       slash = c;
+#endif
+               if (slash++) {
+                       c = xmalloc((slash - argv[0]) + sizeof("tincd"));
+                       sprintf(c, "%.*stincd", (int)(slash - argv[0]), argv[0]);
+               }
+               else
+                       c = "tincd";
+               argv[0] = c;
+               for(i = j = 1; argv[i]; ++i)
+                       if (i != optind && strcmp(argv[i], "--") != 0)
+                               argv[j++] = argv[i];
+               argv[j] = NULL;
+               execvp(c, argv);
+               fprintf(stderr, "Could not start %s: %s\n", c, strerror(errno));
                return 1;
        }