From 16685b8d05cc70f064aef5020bb6656e74466d90 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 22 Feb 2016 14:45:18 -0800 Subject: [PATCH] Split out rand --- adsbus/Makefile | 8 ++++++-- adsbus/adsbus.c | 6 +++--- adsbus/common.c | 17 +---------------- adsbus/common.h | 7 ------- adsbus/rand.c | 22 ++++++++++++++++++++++ adsbus/rand.h | 5 +++++ 6 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 adsbus/rand.c create mode 100644 adsbus/rand.h diff --git a/adsbus/Makefile b/adsbus/Makefile index f48b412..75cdaaa 100644 --- a/adsbus/Makefile +++ b/adsbus/Makefile @@ -3,6 +3,10 @@ CFLAGS ?= -Wall -Werror -O4 -g --std=gnu11 --pedantic-errors -fPIE -pie -fstack- LDFLAGS ?= $(CFLAGS) -Wl,-z,relro -Wl,-z,now LIBS ?= -luuid -ljansson +OBJ_NETWORK = receive.o send.o incoming.o outgoing.o +OBJ_PROTOCOL = airspy_adsb.o beast.o json.o raw.o stats.o +OBJ_UTIL = rand.o wakeup.o opts.o common.o + all: adsbus clean: @@ -11,5 +15,5 @@ clean: %.o: %.c *.h $(CC) -c $(CFLAGS) $< -o $@ -adsbus: adsbus.o receive.o send.o incoming.o outgoing.o airspy_adsb.o beast.o json.o raw.o stats.o wakeup.o opts.o common.o - $(CC) $(LDFLAGS) -o adsbus adsbus.o receive.o send.o incoming.o outgoing.o airspy_adsb.o beast.o json.o raw.o stats.o wakeup.o opts.o common.o $(LIBS) +adsbus: adsbus.o $(OBJ_NETWORK) $(OBJ_PROTOCOL) $(OBJ_UTIL) + $(CC) $(LDFLAGS) -o adsbus adsbus.o $(OBJ_NETWORK) $(OBJ_PROTOCOL) $(OBJ_UTIL) $(LIBS) diff --git a/adsbus/adsbus.c b/adsbus/adsbus.c index 8824206..838a869 100644 --- a/adsbus/adsbus.c +++ b/adsbus/adsbus.c @@ -5,9 +5,6 @@ #include #include -#include "common.h" -#include "wakeup.h" - #include "incoming.h" #include "outgoing.h" @@ -18,7 +15,10 @@ #include "json.h" #include "stats.h" +#include "rand.h" #include "opts.h" +#include "common.h" +#include "wakeup.h" static void print_usage(const char *name) { fprintf(stderr, diff --git a/adsbus/common.c b/adsbus/common.c index 5c85d03..71b6846 100644 --- a/adsbus/common.c +++ b/adsbus/common.c @@ -12,6 +12,7 @@ #include #include "common.h" +#include "rand.h" #include "wakeup.h" static char server_id[UUID_LEN]; @@ -220,22 +221,6 @@ void uuid_gen(char *out) { } -static int rand_fd; - -void rand_init() { - rand_fd = open("/dev/urandom", O_RDONLY); - assert(rand_fd >= 0); -} - -void rand_cleanup() { - assert(!close(rand_fd)); -} - -void rand_fill(void *value, size_t size) { - assert(read(rand_fd, value, size) == size); -} - - #define RETRY_MIN_MS 2000 #define RETRY_MAX_MS 60000 uint32_t retry_get_delay_ms(uint32_t attempt) { diff --git a/adsbus/common.h b/adsbus/common.h index 285db73..7427d82 100644 --- a/adsbus/common.h +++ b/adsbus/common.h @@ -93,13 +93,6 @@ void hex_from_int(char *, uint64_t, size_t); void uuid_gen(char *); -///////// rand - -void rand_init(); -void rand_cleanup(); -void rand_fill(void *, size_t); - - ///////// retry timing void retry_init(); diff --git a/adsbus/rand.c b/adsbus/rand.c new file mode 100644 index 0000000..c916224 --- /dev/null +++ b/adsbus/rand.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +#include "rand.h" + +static int rand_fd; + +void rand_init() { + rand_fd = open("/dev/urandom", O_RDONLY); + assert(rand_fd >= 0); +} + +void rand_cleanup() { + assert(!close(rand_fd)); +} + +void rand_fill(void *value, size_t size) { + assert(read(rand_fd, value, size) == size); +} diff --git a/adsbus/rand.h b/adsbus/rand.h new file mode 100644 index 0000000..88d92e0 --- /dev/null +++ b/adsbus/rand.h @@ -0,0 +1,5 @@ +#pragma once + +void rand_init(); +void rand_cleanup(); +void rand_fill(void *, size_t);