X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=d1df07beefbd803b0b53122aab0088bd1e485dd7;hb=483c5dcfb43719e5fd50902641252e28a04fd74e;hp=ebd2e1301887caca3d913f509726cfbdea136a2c;hpb=303dd1e70219a7542921f6e63d9391ab326d434f;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index ebd2e130..d1df07be 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -76,7 +76,7 @@ static void usage(bool status) { " start Start tincd.\n" " stop Stop tincd.\n" " restart Restart tincd.\n" - " reload Reload configuration of running tincd.\n" + " reload Partially reload configuration of running tincd.\n" " pid Show PID of currently running tincd.\n" " generate-keys [bits] Generate new RSA and ECDSA public/private keypairs.\n" " generate-rsa-keys [bits] Generate a new RSA public/private keypair.\n" @@ -90,7 +90,6 @@ static void usage(bool status) { " purge Purge unreachable nodes\n" " debug N Set debug level\n" " retry Retry all outgoing connections\n" - " reload Partial reload of configuration\n" " disconnect NODE Close meta connection with NODE\n" #ifdef HAVE_CURSES " top Show real-time statistics\n" @@ -139,6 +138,12 @@ static bool parse_options(int argc, char **argv) { } } + if(!netname) { + netname = getenv("NETNAME"); + if(netname) + netname = xstrdup(netname); + } + return true; } @@ -482,7 +487,42 @@ void pcap(int fd, FILE *out) { } } -int main(int argc, char *argv[], char *envp[]) { +#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\n", 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[]) { int fd; int result; char host[128]; @@ -534,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; } @@ -622,11 +679,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; }