X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=1cdcf586a2556511e8e1b27558b29f4080b1b02e;hb=07980b056c5371f8b6fdd50172f501be07155bdf;hp=5f24ae4d5d5771763025f34a45396a020afa06c3;hpb=e5e96882c3825cee81ff163490b2f39fad3192b8;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index 5f24ae4d..1cdcf586 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -714,8 +714,16 @@ static int cmd_start(int argc, char *argv[]) { static int cmd_stop(int argc, char *argv[]) { #ifndef HAVE_MINGW - if(!connect_tincd()) + if(!connect_tincd()) { + if(pid) { + if(kill(pid, SIGTERM)) + return 1; + fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid); + return 0; + } + return 1; + } 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) { @@ -1361,8 +1369,6 @@ static int cmd_init(int argc, char *argv[]) { return 1; } - char *hosts_dir = NULL; - xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); if(mkdir(hosts_dir, 0755) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno)); return 1; @@ -1379,9 +1385,24 @@ static int cmd_init(int argc, char *argv[]) { fclose(stdin); if(!rsa_keygen(2048) || !ecdsa_keygen()) - return false; + return 1; - return true; +#ifndef HAVE_MINGW + char *filename; + xasprintf(&filename, "%s" SLASH "tinc-up", confbase); + if(access(filename, F_OK)) { + FILE *f = fopen(filename, "w"); + if(!f) { + fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); + return 1; + } + fchmod(fileno(f), 0755); + fprintf(f, "#!/bin/sh\n\necho 'Unconfigured tinc-up script, please edit!'\n\n#ifconfig $INTERFACE netmask \n"); + fclose(f); + } +#endif + + return 0; }