Remove statefile option
This commit is contained in:
13
src/main.c
13
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);
|
||||
|
||||
64
src/state.c
64
src/state.c
@@ -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);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
int state_create (const char *);
|
||||
void state_send (int, const char *, const char *);
|
||||
Reference in New Issue
Block a user