diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-06-04 10:11:55 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-06-04 10:11:55 +0200 |
commit | 78a23a4d5ab27c8af26c0e232c099a0c16907649 (patch) | |
tree | 7abfec64bdb1c639faca541512e95b6f3bfa9aad | |
parent | 22e4551cb007312ef808669aa70cad10a7657136 (diff) |
xio: add ioexact operations
Break this out so that we only need to have sigint non-static where
it is really needed.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r-- | astraceroute.c | 2 | ||||
-rw-r--r-- | ct_client.c | 1 | ||||
-rw-r--r-- | ct_server.c | 1 | ||||
-rw-r--r-- | ct_usermgmt.c | 1 | ||||
-rw-r--r-- | curvetun.c | 1 | ||||
-rw-r--r-- | curvetun/Makefile | 1 | ||||
-rw-r--r-- | flowtop.c | 4 | ||||
-rw-r--r-- | ifpps.c | 6 | ||||
-rw-r--r-- | ioexact.c | 53 | ||||
-rw-r--r-- | ioexact.h | 7 | ||||
-rw-r--r-- | netsniff-ng.c | 5 | ||||
-rw-r--r-- | trafgen.c | 6 | ||||
-rw-r--r-- | xio.c | 48 | ||||
-rw-r--r-- | xio.h | 8 |
14 files changed, 70 insertions, 74 deletions
diff --git a/astraceroute.c b/astraceroute.c index 4b1aada..d526bfa 100644 --- a/astraceroute.c +++ b/astraceroute.c @@ -64,7 +64,7 @@ struct proto_ops { int latitude); }; -sig_atomic_t sigint = 0; +static sig_atomic_t sigint = 0; static int assemble_ipv4(uint8_t *packet, size_t len, int ttl, int proto, const struct ctx *ctx, const struct sockaddr *dst, diff --git a/ct_client.c b/ct_client.c index f51371f..9ca72df 100644 --- a/ct_client.c +++ b/ct_client.c @@ -33,6 +33,7 @@ #include "curve.h" #include "xmalloc.h" #include "corking.h" +#include "ioexact.h" #include "curvetun.h" #include "ct_servmgmt.h" #include "ct_usermgmt.h" diff --git a/ct_server.c b/ct_server.c index 534b60f..8aed17f 100644 --- a/ct_server.c +++ b/ct_server.c @@ -34,6 +34,7 @@ #include "xmalloc.h" #include "curvetun.h" #include "curve.h" +#include "ioexact.h" #include "corking.h" #include "cpus.h" #include "built_in.h" diff --git a/ct_usermgmt.c b/ct_usermgmt.c index 6dc7f35..e21675f 100644 --- a/ct_usermgmt.c +++ b/ct_usermgmt.c @@ -18,6 +18,7 @@ #include "ct_usermgmt.h" #include "locking.h" #include "xmalloc.h" +#include "ioexact.h" #include "xio.h" #include "str.h" #include "curvetun.h" @@ -29,6 +29,7 @@ #include "die.h" #include "str.h" #include "cookie.h" +#include "ioexact.h" #include "xmalloc.h" #include "curvetun.h" #include "curve.h" diff --git a/curvetun/Makefile b/curvetun/Makefile index 62f7a51..3d60064 100644 --- a/curvetun/Makefile +++ b/curvetun/Makefile @@ -13,6 +13,7 @@ curvetun-objs = xmalloc.o \ rnd.o \ curve.o \ cookie.o \ + ioexact.o \ cpusched.o \ ct_usermgmt.o \ ct_servmgmt.o \ @@ -77,10 +77,8 @@ struct flow_list { #define INCLUDE_ICMP (1 << 5) #define INCLUDE_SCTP (1 << 6) -volatile sig_atomic_t sigint = 0; - +static volatile sig_atomic_t sigint = 0; static int what = INCLUDE_IPV4 | INCLUDE_IPV6 | INCLUDE_TCP, show_src = 0; - static struct flow_list flow_list; static const char *short_options = "vhTUsDIS46u"; @@ -52,14 +52,10 @@ struct cpu_hit { long long unsigned int irqs_rel, irqs_abs; }; -volatile sig_atomic_t sigint = 0; - +static volatile sig_atomic_t sigint = 0; static struct ifstat stats_old, stats_new, stats_delta; - static struct cpu_hit *cpu_hits; - static int stats_loop = 0; - static WINDOW *stats_screen = NULL; static const char *short_options = "d:t:n:vhclp"; diff --git a/ioexact.c b/ioexact.c new file mode 100644 index 0000000..1600784 --- /dev/null +++ b/ioexact.c @@ -0,0 +1,53 @@ +#include <errno.h> +#include <unistd.h> +#include <signal.h> + +#include "ioexact.h" + +extern volatile sig_atomic_t sigint; + +ssize_t read_exact(int fd, void *buf, size_t len, int mayexit) +{ + ssize_t num = 0, written; + + while (len > 0 && !sigint) { + if ((written = read(fd, buf, len)) < 0) { + if (errno == EAGAIN && num > 0) + continue; + if (mayexit) + return -1; + else + continue; + } + if (!written) + return 0; + len -= written; + buf += written; + num += written; + } + + return num; +} + +ssize_t write_exact(int fd, void *buf, size_t len, int mayexit) +{ + ssize_t num = 0, written; + + while (len > 0 && !sigint) { + if ((written = write(fd, buf, len)) < 0) { + if (errno == EAGAIN && num > 0) + continue; + if (mayexit) + return -1; + else + continue; + } + if (!written) + return 0; + len -= written; + buf += written; + num += written; + } + + return num; +} diff --git a/ioexact.h b/ioexact.h new file mode 100644 index 0000000..6234e8e --- /dev/null +++ b/ioexact.h @@ -0,0 +1,7 @@ +#ifndef IOEXACT_H +#define IOEXACT_H + +extern ssize_t read_exact(int fd, void *buf, size_t len, int mayexit); +extern ssize_t write_exact(int fd, void *buf, size_t len, int mayexit); + +#endif /* IOEXACT_H */ diff --git a/netsniff-ng.c b/netsniff-ng.c index ed3d659..40580b8 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -56,8 +56,7 @@ struct ctx { uid_t uid; gid_t gid; uint32_t link_type, magic; }; -volatile sig_atomic_t sigint = 0; - +static volatile sig_atomic_t sigint = 0; static volatile bool next_dump = false; static const char *short_options = "d:i:o:rf:MJt:S:k:n:b:HQmcsqXlvhF:RGAP:Vu:g:T:DB"; @@ -100,9 +99,7 @@ static const struct option long_options[] = { }; static int tx_sock; - static struct itimerval itimer; - static unsigned long frame_count_max = 0, interval = TX_KERNEL_PULL_INT; #define __pcap_io pcap_ops[ctx->pcap] @@ -62,7 +62,7 @@ struct cpu_stats { sig_atomic_t state; }; -sig_atomic_t sigint = 0; +static sig_atomic_t sigint = 0; struct packet *packets = NULL; size_t plen = 0; @@ -97,13 +97,9 @@ static const struct option long_options[] = { }; static int sock; - static struct itimerval itimer; - static unsigned long interval = TX_KERNEL_PULL_INT; - static struct cpu_stats *stats; - unsigned int seed; #define CPU_STATS_STATE_CFG 1 @@ -109,51 +109,3 @@ ssize_t write_or_die(int fd, const void *buf, size_t len) return ret; } - -extern volatile sig_atomic_t sigint; - -ssize_t read_exact(int fd, void *buf, size_t len, int mayexit) -{ - ssize_t num = 0, written; - - while (len > 0 && !sigint) { - if ((written = read(fd, buf, len)) < 0) { - if (errno == EAGAIN && num > 0) - continue; - if (mayexit) - return -1; - else - continue; - } - if (!written) - return 0; - len -= written; - buf += written; - num += written; - } - - return num; -} - -ssize_t write_exact(int fd, void *buf, size_t len, int mayexit) -{ - ssize_t num = 0, written; - - while (len > 0 && !sigint) { - if ((written = write(fd, buf, len)) < 0) { - if (errno == EAGAIN && num > 0) - continue; - if (mayexit) - return -1; - else - continue; - } - if (!written) - return 0; - len -= written; - buf += written; - num += written; - } - - return num; -} @@ -1,9 +1,3 @@ -/* - * netsniff-ng - the packet sniffing beast - * Copyright 2009, 2010 Daniel Borkmann. - * Subject to the GPL, version 2. - */ - #ifndef XIO_H #define XIO_H @@ -14,7 +8,5 @@ extern int tun_open_or_die(char *name, int type); extern void pipe_or_die(int pipefd[2], int flags); extern ssize_t read_or_die(int fd, void *buf, size_t count); extern ssize_t write_or_die(int fd, const void *buf, size_t count); -extern ssize_t read_exact(int fd, void *buf, size_t len, int mayexit); -extern ssize_t write_exact(int fd, void *buf, size_t len, int mayexit); #endif /* XIO_H */ |