Remove statefile option

This commit is contained in:
Adrien Gallouët
2016-12-20 08:49:43 +00:00
parent 5934e3b94d
commit 89f8379c73
4 changed files with 3 additions and 82 deletions

View File

@@ -16,9 +16,7 @@ glorytun_SOURCES = \
src/tun.c \ src/tun.c \
src/tun.h \ src/tun.h \
src/db.c \ src/db.c \
src/db.h \ src/db.h
src/state.c \
src/state.h
glorytun_CFLAGS += -I$(srcdir)/mud glorytun_CFLAGS += -I$(srcdir)/mud
glorytun_SOURCES += \ glorytun_SOURCES += \

View File

@@ -4,7 +4,6 @@
#include "db.h" #include "db.h"
#include "ip.h" #include "ip.h"
#include "option.h" #include "option.h"
#include "state.h"
#include "str.h" #include "str.h"
#include "tun.h" #include "tun.h"
@@ -30,7 +29,6 @@ static struct {
volatile sig_atomic_t quit; volatile sig_atomic_t quit;
volatile sig_atomic_t info; volatile sig_atomic_t info;
int timeout; int timeout;
int state_fd;
} gt; } gt;
static void static void
@@ -203,7 +201,7 @@ gt_setup_secretkey(struct mud *mud, char *keyfile)
return -1; return -1;
gt_tohex(buf, sizeof(buf), key, size); gt_tohex(buf, sizeof(buf), key, size);
state_send(gt.state_fd, "SECRETKEY", buf); gt_print("secret key: %s\n", buf);
return 0; return 0;
} }
@@ -253,7 +251,6 @@ main(int argc, char **argv)
char *dev = NULL; char *dev = NULL;
char *keyfile = NULL; char *keyfile = NULL;
char *statefile = NULL;
long mtu = 1450; long mtu = 1450;
@@ -279,7 +276,6 @@ main(int argc, char **argv)
{ "mtu", &mtu, option_long }, { "mtu", &mtu, option_long },
{ "mtu-auto", NULL, option_option }, { "mtu-auto", NULL, option_option },
{ "keyfile", &keyfile, option_str }, { "keyfile", &keyfile, option_str },
{ "statefile", &statefile, option_str },
{ "timeout", &gt.timeout, option_long }, { "timeout", &gt.timeout, option_long },
{ "time-tolerance", &time_tolerance, option_long }, { "time-tolerance", &time_tolerance, option_long },
{ "v4only", NULL, option_option }, { "v4only", NULL, option_option },
@@ -333,11 +329,6 @@ main(int argc, char **argv)
gt_log("couldn't create ICMP socket\n"); 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; char *tun_name = NULL;
int tun_fd = tun_create(dev, &tun_name); int tun_fd = tun_create(dev, &tun_name);
@@ -408,7 +399,7 @@ main(int argc, char **argv)
fd_set_nonblock(mud_fd); fd_set_nonblock(mud_fd);
state_send(gt.state_fd, "INITIALIZED", tun_name); gt_log("running...\n");
fd_set rfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);

View File

@@ -1,64 +0,0 @@
#include "common.h"
#include "state.h"
#include "str.h"
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
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);
}

View File

@@ -1,4 +0,0 @@
#pragma once
int state_create (const char *);
void state_send (int, const char *, const char *);