Compare commits

..

3 Commits

Author SHA1 Message Date
angt
a78089ba10 Version 0.0.5 2015-11-23 12:13:42 +01:00
angt
128aaae368 Add daemon option (only one fork) 2015-11-23 12:12:28 +01:00
angt
230c9fa26a Little fix and cleanup 2015-11-21 19:09:21 +01:00
2 changed files with 20 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
AC_PREREQ([2.65])
AC_INIT([glorytun], [0.0.4], [https://github.com/angt/glorytun/issues],
AC_INIT([glorytun], [0.0.5], [https://github.com/angt/glorytun/issues],
[glorytun], [https://github.com/angt/glorytun])
AC_CONFIG_SRCDIR([src/common.h])
AC_CONFIG_AUX_DIR([build-aux])

View File

@@ -655,6 +655,7 @@ int main (int argc, char **argv)
{ "multiqueue", NULL, option_option },
{ "keepalive", ka_opts, option_option },
{ "buffer-size", &buffer_size, option_long },
{ "daemon", NULL, option_option },
{ "debug", NULL, option_option },
{ "version", NULL, option_option },
{ NULL },
@@ -723,6 +724,20 @@ int main (int argc, char **argv)
return 1;
}
if (option_is_set(opts, "daemon")) {
switch (fork()) {
case -1:
perror("fork");
return 1;
case 0:
if (setsid()==-1)
perror("setsid");
break;
default:
_exit(0);
}
}
while (!gt_close) {
sock.fd = listener?sk_accept(fd):sk_create(ai, sk_connect);
@@ -773,7 +788,7 @@ int main (int argc, char **argv)
while (1) {
if (gt_close)
stop_loop = 1;
stop_loop |= 1;
if (stop_loop) {
if (((stop_loop&(1<<2)) || !buffer_read_size(&sock.write)) &&
@@ -799,6 +814,9 @@ int main (int argc, char **argv)
return 1;
}
FD_CLR(sock.fd, &wfds);
FD_CLR(tun.fd, &wfds);
#ifdef TCP_INFO
struct timeval now;
gettimeofday(&now, NULL);
@@ -848,9 +866,6 @@ int main (int argc, char **argv)
gt_encrypt(&ctx, &sock.write, &tun.read);
if (FD_ISSET(sock.fd, &wfds))
FD_CLR(sock.fd, &wfds);
if (buffer_read_size(&sock.write)) {
ssize_t r = fd_write(sock.fd, sock.write.read,
buffer_read_size(&sock.write));
@@ -889,9 +904,6 @@ int main (int argc, char **argv)
goto restart;
}
if (FD_ISSET(tun.fd, &wfds))
FD_CLR(tun.fd, &wfds);
while (1) {
size_t size = buffer_read_size(&tun.write);
ssize_t ip_size = ip_get_size(tun.write.read, size);