Split out rand
This commit is contained in:
@@ -3,6 +3,10 @@ CFLAGS ?= -Wall -Werror -O4 -g --std=gnu11 --pedantic-errors -fPIE -pie -fstack-
|
|||||||
LDFLAGS ?= $(CFLAGS) -Wl,-z,relro -Wl,-z,now
|
LDFLAGS ?= $(CFLAGS) -Wl,-z,relro -Wl,-z,now
|
||||||
LIBS ?= -luuid -ljansson
|
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
|
all: adsbus
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@@ -11,5 +15,5 @@ clean:
|
|||||||
%.o: %.c *.h
|
%.o: %.c *.h
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
$(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
|
adsbus: adsbus.o $(OBJ_NETWORK) $(OBJ_PROTOCOL) $(OBJ_UTIL)
|
||||||
$(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)
|
$(CC) $(LDFLAGS) -o adsbus adsbus.o $(OBJ_NETWORK) $(OBJ_PROTOCOL) $(OBJ_UTIL) $(LIBS)
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "wakeup.h"
|
|
||||||
|
|
||||||
#include "incoming.h"
|
#include "incoming.h"
|
||||||
#include "outgoing.h"
|
#include "outgoing.h"
|
||||||
|
|
||||||
@@ -18,7 +15,10 @@
|
|||||||
#include "json.h"
|
#include "json.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
|
||||||
|
#include "rand.h"
|
||||||
#include "opts.h"
|
#include "opts.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "wakeup.h"
|
||||||
|
|
||||||
static void print_usage(const char *name) {
|
static void print_usage(const char *name) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "rand.h"
|
||||||
#include "wakeup.h"
|
#include "wakeup.h"
|
||||||
|
|
||||||
static char server_id[UUID_LEN];
|
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_MIN_MS 2000
|
||||||
#define RETRY_MAX_MS 60000
|
#define RETRY_MAX_MS 60000
|
||||||
uint32_t retry_get_delay_ms(uint32_t attempt) {
|
uint32_t retry_get_delay_ms(uint32_t attempt) {
|
||||||
|
|||||||
@@ -93,13 +93,6 @@ void hex_from_int(char *, uint64_t, size_t);
|
|||||||
void uuid_gen(char *);
|
void uuid_gen(char *);
|
||||||
|
|
||||||
|
|
||||||
///////// rand
|
|
||||||
|
|
||||||
void rand_init();
|
|
||||||
void rand_cleanup();
|
|
||||||
void rand_fill(void *, size_t);
|
|
||||||
|
|
||||||
|
|
||||||
///////// retry timing
|
///////// retry timing
|
||||||
|
|
||||||
void retry_init();
|
void retry_init();
|
||||||
|
|||||||
22
adsbus/rand.c
Normal file
22
adsbus/rand.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
5
adsbus/rand.h
Normal file
5
adsbus/rand.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void rand_init();
|
||||||
|
void rand_cleanup();
|
||||||
|
void rand_fill(void *, size_t);
|
||||||
Reference in New Issue
Block a user