diff --git a/Makefile.am b/Makefile.am index 15fa780..783bc3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,9 +16,7 @@ glorytun_SOURCES = \ src/tun.c \ src/tun.h \ src/db.c \ - src/db.h \ - src/state.c \ - src/state.h + src/db.h glorytun_CFLAGS += -I$(srcdir)/mud glorytun_SOURCES += \ diff --git a/src/main.c b/src/main.c index bd1f14a..097550f 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,6 @@ #include "db.h" #include "ip.h" #include "option.h" -#include "state.h" #include "str.h" #include "tun.h" @@ -30,7 +29,6 @@ static struct { volatile sig_atomic_t quit; volatile sig_atomic_t info; int timeout; - int state_fd; } gt; static void @@ -203,7 +201,7 @@ gt_setup_secretkey(struct mud *mud, char *keyfile) return -1; gt_tohex(buf, sizeof(buf), key, size); - state_send(gt.state_fd, "SECRETKEY", buf); + gt_print("secret key: %s\n", buf); return 0; } @@ -253,7 +251,6 @@ main(int argc, char **argv) char *dev = NULL; char *keyfile = NULL; - char *statefile = NULL; long mtu = 1450; @@ -279,7 +276,6 @@ main(int argc, char **argv) { "mtu", &mtu, option_long }, { "mtu-auto", NULL, option_option }, { "keyfile", &keyfile, option_str }, - { "statefile", &statefile, option_str }, { "timeout", >.timeout, option_long }, { "time-tolerance", &time_tolerance, option_long }, { "v4only", NULL, option_option }, @@ -333,11 +329,6 @@ main(int argc, char **argv) gt_log("couldn't create ICMP socket\n"); } - gt.state_fd = state_create(statefile); - - if (statefile && gt.state_fd == -1) - return 1; - char *tun_name = NULL; int tun_fd = tun_create(dev, &tun_name); @@ -408,7 +399,7 @@ main(int argc, char **argv) fd_set_nonblock(mud_fd); - state_send(gt.state_fd, "INITIALIZED", tun_name); + gt_log("running...\n"); fd_set rfds; FD_ZERO(&rfds); diff --git a/src/state.c b/src/state.c deleted file mode 100644 index ea9609b..0000000 --- a/src/state.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "common.h" - -#include "state.h" -#include "str.h" - -#include -#include -#include - -int -state_create(const char *filename) -{ - if (str_empty(filename)) - return -1; - - int fd = open(filename, O_WRONLY); - - if (fd == -1) { - if (errno != EINTR) - perror("open"); - return -1; - } - - struct stat st = {0}; - - if (fstat(fd, &st) == -1) { - perror("fstat"); - close(fd); - return -1; - } - - if (!S_ISFIFO(st.st_mode)) { - gt_log("`%s' is not a fifo\n", filename); - close(fd); - return -1; - } - - return fd; -} - -void -state_send(int fd, const char *state, const char *info) -{ - if (str_empty(state)) - return; - - if (fd == -1) { - gt_print("%s %s\n", state, info); - return; - } - - const char *strs[] = {state, " ", info, "\n"}; - char *str = str_cat(strs, COUNT(strs)); - - if (!str) { - perror("str_cat"); - return; - } - - if (write(fd, str, str_len(str)) == -1 && errno != EINTR) - perror("write"); - - free(str); -} diff --git a/src/state.h b/src/state.h deleted file mode 100644 index dd014ca..0000000 --- a/src/state.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -int state_create (const char *); -void state_send (int, const char *, const char *);