From bae4398a619e69c045993a03654c1a333fb0e95d Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 15 Feb 2016 21:22:23 +0000 Subject: [PATCH] Assign an ID to each backend. --- Makefile | 3 ++- adsbus.c | 1 - backend.c | 17 ++++++++++++----- backend.h | 1 + common.h | 5 +++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1682c95..6dbd941 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CC ?= clang CFLAGS ?= -Wall -Werror -O4 -g --std=gnu11 --pedantic-errors LDFLAGS ?= -Wall -O4 +LIBS ?= -luuid all: adsbus @@ -11,4 +12,4 @@ clean: $(CC) -c $(CFLAGS) $< -o $@ adsbus: adsbus.o backend.o airspy_adsb.o common.o - $(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o airspy_adsb.o common.o + $(CC) $(LDFLAGS) -o adsbus adsbus.o backend.o airspy_adsb.o common.o $(LIBS) diff --git a/adsbus.c b/adsbus.c index 457c416..08aa1fa 100644 --- a/adsbus.c +++ b/adsbus.c @@ -84,7 +84,6 @@ int main(int argc, char *argv[]) { for (int i = 0, j = optind; i < nbackends && j < argc; i++, j += 2) { backend_init(&backends[i]); if (!backend_connect(argv[j], argv[j + 1], &backends[i], epoll_fd)) { - fprintf(stderr, "Unable to connect to %s %s\n", argv[j], argv[j + 1]); return EXIT_FAILURE; } } diff --git a/backend.c b/backend.c index f8c1763..3b6f9e0 100644 --- a/backend.c +++ b/backend.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "airspy_adsb.h" #include "backend.h" @@ -30,6 +31,12 @@ void backend_init(struct backend *backend) { bool backend_connect(char *node, char *service, struct backend *backend, int epoll_fd) { assert(backend->type == PEER_BACKEND); + { + uuid_t uuid; + uuid_generate(uuid); + uuid_unparse(uuid, backend->id); + } + struct addrinfo *addrs; { @@ -40,7 +47,7 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo int gai_err = getaddrinfo(node, service, &hints, &addrs); if (gai_err) { - fprintf(stderr, "getaddrinfo(%s %s): %s\n", node, service, gai_strerror(gai_err)); + fprintf(stderr, "%s: getaddrinfo(%s %s): %s\n", backend->id, node, service, gai_strerror(gai_err)); return false; } } @@ -63,13 +70,13 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo if (addr == NULL) { freeaddrinfo(addrs); - fprintf(stderr, "Can't connect to %s %s\n", node, service); + fprintf(stderr, "%s: Can't connect to %s %s\n", backend->id, node, service); return false; } char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; if (getnameinfo(addr->ai_addr, addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0) { - fprintf(stderr, "Connected to %s %s\n", hbuf, sbuf); + fprintf(stderr, "%s: Connected to %s %s\n", backend->id, hbuf, sbuf); } } @@ -93,7 +100,7 @@ bool backend_connect(char *node, char *service, struct backend *backend, int epo bool backend_read(struct backend *backend) { if (buf_fill(&backend->buf, backend->fd) < 0) { - fprintf(stderr, "Connection closed by backend\n"); + fprintf(stderr, "%s: Connection closed by backend\n", backend->id); return false; } @@ -102,7 +109,7 @@ bool backend_read(struct backend *backend) { } if (backend->buf.length == BUF_LEN_MAX) { - fprintf(stderr, "Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.\n"); + fprintf(stderr, "%s: Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.\n", backend->id); return false; } return true; diff --git a/backend.h b/backend.h index e4bff89..8bad0a7 100644 --- a/backend.h +++ b/backend.h @@ -8,6 +8,7 @@ struct backend; typedef bool (*parser)(struct backend *, struct packet *); struct backend { enum peer_type type; + char id[UUID_LEN]; int fd; struct buf buf; char parser_state[PARSER_STATE_LEN]; diff --git a/common.h b/common.h index 4d83171..7ea384c 100644 --- a/common.h +++ b/common.h @@ -54,3 +54,8 @@ struct packet { void hex_init(); void hex_to_bin(char *, char *, size_t); uint64_t hex_to_int(char *, size_t); + + +///////// misc + +#define UUID_LEN 37