summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-07-19 15:13:37 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-07-19 15:13:37 +0100
commita7094cffbcbd14fdba7d0ab6e0c7057a8857a674 (patch)
tree923f90f104ff8860410cf5ae9e9c73e11f5a4344
parentf8147b9736d4385c02b5f27b497c90806a9e9d96 (diff)
Make tun_fd variable static
tun functions use global state in tun.c anyway. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--latency.c4
-rw-r--r--tun.c10
-rw-r--r--tun.h6
3 files changed, 9 insertions, 11 deletions
diff --git a/latency.c b/latency.c
index 1c91761..69176d5 100644
--- a/latency.c
+++ b/latency.c
@@ -92,7 +92,7 @@ main(int argc, char **argv)
setuid(0);
}
- tun_fd = tun_setup();
+ tun_setup();
if (ruid != euid)
setuid(ruid);
@@ -105,6 +105,6 @@ main(int argc, char **argv)
setup_signals();
- handle_tun(tun_fd);
+ handle_tun();
return EXIT_SUCCESS;
}
diff --git a/tun.c b/tun.c
index 6b4eac0..7333350 100644
--- a/tun.c
+++ b/tun.c
@@ -20,7 +20,7 @@
#include "latency.h"
#include "utils.h"
-int tun_fd = -1;
+static int tun_fd = -1;
/**
* @param dev name of interface. MUST have enough
@@ -52,7 +52,7 @@ static int tun_alloc(char *dev, int flags)
return fd;
}
-int tun_setup(void)
+void tun_setup(void)
{
char tun_name[IFNAMSIZ];
int fd;
@@ -79,7 +79,7 @@ int tun_setup(void)
setpriority(PRIO_PROCESS, 0, -20);
- return fd;
+ tun_fd = fd;
}
#define MIN_PKT_LEN 2000u
@@ -216,7 +216,7 @@ bytes2time(int64_t bytes)
}
void
-handle_tun(int fd)
+handle_tun(void)
{
packet_t *pkt;
pthread_t writer;
@@ -233,7 +233,7 @@ handle_tun(int fd)
uint32_t num_packets = 0;
while (!term && (pkt = alloc_packet())) {
- int len = read(fd, pkt->data, MIN_PKT_LEN);
+ int len = read(tun_fd, pkt->data, MIN_PKT_LEN);
if (len < 0)
break;
diff --git a/tun.h b/tun.h
index 68ccf73..818ed8a 100644
--- a/tun.h
+++ b/tun.h
@@ -1,5 +1,3 @@
-extern int tun_fd;
+void tun_setup(void);
-int tun_setup(void);
-
-void handle_tun(int tun_fd);
+void handle_tun(void);