Switch to standard logging framework
This commit is contained in:
@@ -13,7 +13,7 @@ ADSBUS_TEST_FLAGS ?= --stdin --stdout=airspy_adsb --stdout=beast --stdout=json -
|
||||
OBJ_TRANSPORT = exec.o file.o incoming.o outgoing.o
|
||||
OBJ_FLOW = flow.o receive.o send.o send_receive.o
|
||||
OBJ_PROTOCOL = airspy_adsb.o beast.o json.o proto.o raw.o stats.o
|
||||
OBJ_UTIL = asyncaddrinfo.o buf.o hex.o list.o opts.o packet.o peer.o rand.o resolve.o server.o socket.o uuid.o wakeup.o
|
||||
OBJ_UTIL = asyncaddrinfo.o buf.o hex.o list.o log.o opts.o packet.o peer.o rand.o resolve.o server.o socket.o uuid.o wakeup.o
|
||||
OBJ_PROTO = adsb.pb-c.o
|
||||
|
||||
all: adsbus
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "hex.h"
|
||||
#include "incoming.h"
|
||||
#include "json.h"
|
||||
#include "log.h"
|
||||
#include "opts.h"
|
||||
#include "outgoing.h"
|
||||
#include "peer.h"
|
||||
@@ -176,6 +177,8 @@ static void reopen(int fd, char *path, int flags) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_init();
|
||||
|
||||
hex_init();
|
||||
rand_init();
|
||||
resolve_init();
|
||||
@@ -218,9 +221,11 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
peer_cleanup();
|
||||
|
||||
log_cleanup();
|
||||
|
||||
assert(!close(STDIN_FILENO));
|
||||
assert(!close(STDOUT_FILENO));
|
||||
assert(!close(STDERR_FILENO));
|
||||
close(STDERR_FILENO); // 2>&1 breaks this
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buf.h"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
@@ -11,6 +10,7 @@
|
||||
#include "buf.h"
|
||||
#include "flow.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "peer.h"
|
||||
#include "uuid.h"
|
||||
#include "wakeup.h"
|
||||
@@ -35,7 +35,7 @@ static void exec_del(struct exec *exec) {
|
||||
flow_ref_dec(exec->flow);
|
||||
|
||||
if (exec->child > 0) {
|
||||
fprintf(stderr, "E %s: Sending SIGTERM to child process %d\n", exec->id, exec->child);
|
||||
log_write('E', exec->id, "Sending SIGTERM to child process %d", exec->child);
|
||||
// Racy with the process terminating, so don't assert on it
|
||||
kill(exec->child, SIGTERM);
|
||||
assert(waitpid(exec->child, NULL, 0) == exec->child);
|
||||
@@ -51,20 +51,20 @@ static void exec_close_handler(struct peer *peer) {
|
||||
assert(waitpid(exec->child, &status, WNOHANG) == exec->child);
|
||||
exec->child = -1;
|
||||
if (WIFEXITED(status)) {
|
||||
fprintf(stderr, "E %s: Client exited with status %d\n", exec->id, WEXITSTATUS(status));
|
||||
log_write('E', exec->id, "Client exited with status %d", WEXITSTATUS(status));
|
||||
} else {
|
||||
assert(WIFSIGNALED(status));
|
||||
fprintf(stderr, "E %s: Client exited with signal %d\n", exec->id, WTERMSIG(status));
|
||||
log_write('E', exec->id, "Client exited with signal %d", WTERMSIG(status));
|
||||
}
|
||||
uint32_t delay = wakeup_get_retry_delay_ms(1);
|
||||
fprintf(stderr, "E %s: Will retry in %ds\n", exec->id, delay / 1000);
|
||||
log_write('E', exec->id, "Will retry in %ds", delay / 1000);
|
||||
exec->peer.event_handler = exec_spawn_wrapper;
|
||||
wakeup_add((struct peer *) exec, delay);
|
||||
}
|
||||
|
||||
static void exec_parent(struct exec *exec, pid_t child, int fd) {
|
||||
exec->child = child;
|
||||
fprintf(stderr, "E %s: Child started as process %d\n", exec->id, exec->child);
|
||||
log_write('E', exec->id, "Child started as process %d", exec->child);
|
||||
|
||||
exec->peer.event_handler = exec_close_handler;
|
||||
if (!flow_new_send_hello(fd, exec->flow, exec->passthrough, (struct peer *) exec)) {
|
||||
@@ -91,7 +91,7 @@ static void __attribute__ ((noreturn)) exec_child(const struct exec *exec, int f
|
||||
}
|
||||
|
||||
static void exec_spawn(struct exec *exec) {
|
||||
fprintf(stderr, "E %s: Executing: %s\n", exec->id, exec->command);
|
||||
log_write('E', exec->id, "Executing: %s", exec->id, exec->command);
|
||||
int fds[2];
|
||||
assert(!socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds));
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -11,6 +10,7 @@
|
||||
|
||||
#include "flow.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "peer.h"
|
||||
#include "receive.h"
|
||||
#include "send.h"
|
||||
@@ -67,14 +67,14 @@ static void file_del(struct file *file) {
|
||||
|
||||
static void file_retry(struct file *file) {
|
||||
uint32_t delay = wakeup_get_retry_delay_ms(file->attempt++);
|
||||
fprintf(stderr, "F %s: Will retry in %ds\n", file->id, delay / 1000);
|
||||
log_write('F', file->id, "Will retry in %ds", delay / 1000);
|
||||
file->peer.event_handler = file_open_wrapper;
|
||||
wakeup_add((struct peer *) file, delay);
|
||||
}
|
||||
|
||||
static void file_handle_close(struct peer *peer) {
|
||||
struct file *file = (struct file *) peer;
|
||||
fprintf(stderr, "F %s: File closed: %s\n", file->id, file->path);
|
||||
log_write('F', file->id, "File closed: %s", file->path);
|
||||
|
||||
if (file->retry) {
|
||||
file_retry(file);
|
||||
@@ -84,10 +84,10 @@ static void file_handle_close(struct peer *peer) {
|
||||
}
|
||||
|
||||
static void file_open(struct file *file) {
|
||||
fprintf(stderr, "F %s: Opening file: %s\n", file->id, file->path);
|
||||
log_write('F', file->id, "Opening file: %s", file->path);
|
||||
int fd = open(file->path, file->flags | O_CLOEXEC, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "F %s: Error opening file: %s\n", file->id, strerror(errno));
|
||||
log_write('F', file->id, "Error opening file: %s", strerror(errno));
|
||||
file_retry(file);
|
||||
return;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ static void file_open(struct file *file) {
|
||||
file->peer.event_handler = file_handle_close;
|
||||
file->attempt = 0;
|
||||
if (!flow_new_send_hello(fd, file->flow, file->passthrough, (struct peer *) file)) {
|
||||
fprintf(stderr, "F %s: Error writing greeting\n", file->id);
|
||||
log_write('F', file->id, "Error writing greeting");
|
||||
file_retry(file);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "buf.h"
|
||||
#include "flow.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "peer.h"
|
||||
#include "resolve.h"
|
||||
#include "socket.h"
|
||||
@@ -36,7 +36,7 @@ static void incoming_resolve_wrapper(struct peer *);
|
||||
|
||||
static void incoming_retry(struct incoming *incoming) {
|
||||
uint32_t delay = wakeup_get_retry_delay_ms(incoming->attempt++);
|
||||
fprintf(stderr, "I %s: Will retry in %ds\n", incoming->id, delay / 1000);
|
||||
log_write('I', incoming->id, "Will retry in %ds", delay / 1000);
|
||||
incoming->peer.event_handler = incoming_resolve_wrapper;
|
||||
wakeup_add((struct peer *) incoming, delay);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ static void incoming_handler(struct peer *peer) {
|
||||
|
||||
int fd = accept4(incoming->peer.fd, &peer_addr, &peer_addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "I %s: Failed to accept new connection on %s/%s: %s\n", incoming->id, incoming->node, incoming->service, strerror(errno));
|
||||
log_write('I', incoming->id, "Failed to accept new connection on %s/%s: %s", incoming->node, incoming->service, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,8 +58,7 @@ static void incoming_handler(struct peer *peer) {
|
||||
assert(getnameinfo(&peer_addr, peer_addrlen, peer_hbuf, sizeof(peer_hbuf), peer_sbuf, sizeof(peer_sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
assert(getnameinfo(&local_addr, local_addrlen, local_hbuf, sizeof(local_hbuf), local_sbuf, sizeof(local_sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
|
||||
fprintf(stderr, "I %s: New incoming connection on %s/%s (%s/%s) from %s/%s\n",
|
||||
incoming->id,
|
||||
log_write('I', incoming->id, "New incoming connection on %s/%s (%s/%s) from %s/%s",
|
||||
incoming->node, incoming->service,
|
||||
local_hbuf, local_sbuf,
|
||||
peer_hbuf, peer_sbuf);
|
||||
@@ -67,7 +66,7 @@ static void incoming_handler(struct peer *peer) {
|
||||
flow_socket_connected(fd, incoming->flow);
|
||||
|
||||
if (!flow_new_send_hello(fd, incoming->flow, incoming->passthrough, NULL)) {
|
||||
fprintf(stderr, "I %s: Error writing greeting\n", incoming->id);
|
||||
log_write('I', incoming->id, "Error writing greeting");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +88,7 @@ static void incoming_listen(struct peer *peer) {
|
||||
struct addrinfo *addrs;
|
||||
int err = resolve_result(peer, &addrs);
|
||||
if (err) {
|
||||
fprintf(stderr, "I %s: Failed to resolve %s/%s: %s\n", incoming->id, incoming->node, incoming->service, gai_strerror(err));
|
||||
log_write('I', incoming->id, "Failed to resolve %s/%s: %s", incoming->node, incoming->service, gai_strerror(err));
|
||||
incoming_retry(incoming);
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +97,7 @@ static void incoming_listen(struct peer *peer) {
|
||||
for (addr = addrs; addr; addr = addr->ai_next) {
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
assert(getnameinfo(addr->ai_addr, addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
fprintf(stderr, "I %s: Listening on %s/%s...\n", incoming->id, hbuf, sbuf);
|
||||
log_write('I', incoming->id, "Listening on %s/%s...", hbuf, sbuf);
|
||||
|
||||
incoming->peer.fd = socket(addr->ai_family, addr->ai_socktype | SOCK_CLOEXEC, addr->ai_protocol);
|
||||
assert(incoming->peer.fd >= 0);
|
||||
@@ -106,7 +105,7 @@ static void incoming_listen(struct peer *peer) {
|
||||
socket_pre_bind(incoming->peer.fd);
|
||||
|
||||
if (bind(incoming->peer.fd, addr->ai_addr, addr->ai_addrlen) != 0) {
|
||||
fprintf(stderr, "I %s: Failed to bind to %s/%s: %s\n", incoming->id, hbuf, sbuf, strerror(errno));
|
||||
log_write('I', incoming->id, "Failed to bind to %s/%s: %s", hbuf, sbuf, strerror(errno));
|
||||
assert(!close(incoming->peer.fd));
|
||||
continue;
|
||||
}
|
||||
@@ -122,7 +121,7 @@ static void incoming_listen(struct peer *peer) {
|
||||
freeaddrinfo(addrs);
|
||||
|
||||
if (addr == NULL) {
|
||||
fprintf(stderr, "I %s: Failed to bind any addresses for %s/%s...\n", incoming->id, incoming->node, incoming->service);
|
||||
log_write('I', incoming->id, "Failed to bind any addresses for %s/%s...", incoming->node, incoming->service);
|
||||
incoming_retry(incoming);
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +132,7 @@ static void incoming_listen(struct peer *peer) {
|
||||
}
|
||||
|
||||
static void incoming_resolve(struct incoming *incoming) {
|
||||
fprintf(stderr, "I %s: Resolving %s/%s...\n", incoming->id, incoming->node, incoming->service);
|
||||
log_write('I', incoming->id, "Resolving %s/%s...", incoming->node, incoming->service);
|
||||
incoming->peer.event_handler = incoming_listen;
|
||||
resolve((struct peer *) incoming, incoming->node, incoming->service, AI_PASSIVE);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jansson.h>
|
||||
|
||||
|
||||
30
adsbus/log.c
Normal file
30
adsbus/log.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
|
||||
static FILE *log_stream = NULL;
|
||||
|
||||
void log_init() {
|
||||
log_stream = fdopen(STDERR_FILENO, "a");
|
||||
assert(log_stream);
|
||||
setlinebuf(log_stream);
|
||||
}
|
||||
|
||||
void log_cleanup() {
|
||||
assert(!fclose(log_stream));
|
||||
}
|
||||
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||
void log_write(char type, const uint8_t *id, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
assert(fprintf(log_stream, "%c %s: ", type, id) > 0);
|
||||
assert(vfprintf(log_stream, fmt, ap) > 0);
|
||||
assert(fprintf(log_stream, "\n") == 1);
|
||||
va_end(ap);
|
||||
}
|
||||
7
adsbus/log.h
Normal file
7
adsbus/log.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void log_init(void);
|
||||
void log_cleanup(void);
|
||||
void log_write(char, const uint8_t *, const char *, ...);
|
||||
@@ -1,16 +1,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "buf.h"
|
||||
#include "flow.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "peer.h"
|
||||
#include "resolve.h"
|
||||
#include "socket.h"
|
||||
@@ -40,7 +40,7 @@ static void outgoing_resolve_wrapper(struct peer *);
|
||||
|
||||
static void outgoing_retry(struct outgoing *outgoing) {
|
||||
uint32_t delay = wakeup_get_retry_delay_ms(++outgoing->attempt);
|
||||
fprintf(stderr, "O %s: Will retry in %ds\n", outgoing->id, delay / 1000);
|
||||
log_write('O', outgoing->id, "Will retry in %ds", delay / 1000);
|
||||
outgoing->peer.event_handler = outgoing_resolve_wrapper;
|
||||
wakeup_add((struct peer *) outgoing, delay);
|
||||
}
|
||||
@@ -48,14 +48,14 @@ static void outgoing_retry(struct outgoing *outgoing) {
|
||||
static void outgoing_connect_next(struct outgoing *outgoing) {
|
||||
if (outgoing->addr == NULL) {
|
||||
freeaddrinfo(outgoing->addrs);
|
||||
fprintf(stderr, "O %s: Can't connect to any addresses of %s/%s\n", outgoing->id, outgoing->node, outgoing->service);
|
||||
log_write('O', outgoing->id, "Can't connect to any addresses of %s/%s", outgoing->node, outgoing->service);
|
||||
outgoing_retry(outgoing);
|
||||
return;
|
||||
}
|
||||
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
assert(getnameinfo(outgoing->addr->ai_addr, outgoing->addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
fprintf(stderr, "O %s: Connecting to %s/%s...\n", outgoing->id, hbuf, sbuf);
|
||||
log_write('O', outgoing->id, "Connecting to %s/%s...", hbuf, sbuf);
|
||||
|
||||
outgoing->peer.fd = socket(outgoing->addr->ai_family, outgoing->addr->ai_socktype | SOCK_NONBLOCK | SOCK_CLOEXEC, outgoing->addr->ai_protocol);
|
||||
assert(outgoing->peer.fd >= 0);
|
||||
@@ -82,7 +82,7 @@ static void outgoing_disconnect_handler(struct peer *peer) {
|
||||
if (outgoing->peer.fd != -1) {
|
||||
assert(!close(outgoing->peer.fd));
|
||||
}
|
||||
fprintf(stderr, "O %s: Peer disconnected; reconnecting...\n", outgoing->id);
|
||||
log_write('O', outgoing->id, "Peer disconnected; reconnecting...");
|
||||
outgoing_retry(outgoing);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
||||
assert(getnameinfo(outgoing->addr->ai_addr, outgoing->addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
switch (result) {
|
||||
case 0:
|
||||
fprintf(stderr, "O %s: Connected to %s/%s\n", outgoing->id, hbuf, sbuf);
|
||||
log_write('O', outgoing->id, "Connected to %s/%s", hbuf, sbuf);
|
||||
freeaddrinfo(outgoing->addrs);
|
||||
outgoing->attempt = 0;
|
||||
int fd = outgoing->peer.fd;
|
||||
@@ -108,7 +108,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "O %s: Can't connect to %s/%s: %s\n", outgoing->id, hbuf, sbuf, strerror(result));
|
||||
log_write('O', outgoing->id, "Can't connect to %s/%s: %s", hbuf, sbuf, strerror(result));
|
||||
assert(!close(outgoing->peer.fd));
|
||||
outgoing->peer.fd = -1;
|
||||
outgoing->addr = outgoing->addr->ai_next;
|
||||
@@ -122,7 +122,7 @@ static void outgoing_resolve_handler(struct peer *peer) {
|
||||
struct outgoing *outgoing = (struct outgoing *) peer;
|
||||
int err = resolve_result(peer, &outgoing->addrs);
|
||||
if (err) {
|
||||
fprintf(stderr, "O %s: Failed to resolve %s/%s: %s\n", outgoing->id, outgoing->node, outgoing->service, gai_strerror(err));
|
||||
log_write('O', outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err));
|
||||
outgoing_retry(outgoing);
|
||||
} else {
|
||||
outgoing->addr = outgoing->addrs;
|
||||
@@ -131,7 +131,7 @@ static void outgoing_resolve_handler(struct peer *peer) {
|
||||
}
|
||||
|
||||
static void outgoing_resolve(struct outgoing *outgoing) {
|
||||
fprintf(stderr, "O %s: Resolving %s/%s...\n", outgoing->id, outgoing->node, outgoing->service);
|
||||
log_write('O', outgoing->id, "Resolving %s/%s...", outgoing->node, outgoing->service);
|
||||
outgoing->peer.event_handler = outgoing_resolve_handler;
|
||||
resolve((struct peer *) outgoing, outgoing->node, outgoing->service, 0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "server.h"
|
||||
#include "uuid.h"
|
||||
#include "wakeup.h"
|
||||
@@ -22,7 +22,7 @@ static bool peer_shutdown_flag = false;
|
||||
static struct list_head peer_always_trigger_head = LIST_HEAD_INIT(peer_always_trigger_head);
|
||||
|
||||
static void peer_shutdown_handler(struct peer *peer) {
|
||||
fprintf(stderr, "X %s: Shutting down\n", server_id);
|
||||
log_write('X', server_id, "Shutting down");
|
||||
assert(!close(peer->fd));
|
||||
free(peer);
|
||||
peer_shutdown_flag = true;
|
||||
@@ -96,13 +96,13 @@ void peer_call(struct peer *peer) {
|
||||
}
|
||||
|
||||
void peer_loop() {
|
||||
fprintf(stderr, "X %s: Starting event loop\n", server_id);
|
||||
log_write('X', server_id, "Starting event loop");
|
||||
while (!peer_shutdown_flag) {
|
||||
if (!(peer_count_in + peer_count_out_in)) {
|
||||
fprintf(stderr, "X %s: No remaining inputs\n", server_id);
|
||||
log_write('X', server_id, "No remaining inputs");
|
||||
peer_shutdown(0);
|
||||
} else if (!(peer_count_out + peer_count_out_in)) {
|
||||
fprintf(stderr, "X %s: No remaining outputs\n", server_id);
|
||||
log_write('X', server_id, "No remaining outputs");
|
||||
peer_shutdown(0);
|
||||
}
|
||||
#define MAX_EVENTS 10
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buf.h"
|
||||
#include "log.h"
|
||||
#include "packet.h"
|
||||
#include "server.h"
|
||||
#include "uuid.h"
|
||||
@@ -145,12 +145,12 @@ static bool proto_parse_header(AdsbHeader *header, struct packet *packet, struct
|
||||
state->rssi_max = header->rssi_max;
|
||||
|
||||
if (!strcmp(header->server_id, (const char *) server_id)) {
|
||||
fprintf(stderr, "R %s: Attempt to receive proto data from our own server ID (%s); loop!\n", packet->source_id, server_id);
|
||||
log_write('R', packet->source_id, "Attempt to receive proto data from our own server ID (%s); loop!", server_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
state->have_header = true;
|
||||
fprintf(stderr, "R %s: Connected to server ID: %s\n", packet->source_id, header->server_id);
|
||||
log_write('R', packet->source_id, "Connected to server ID: %s", header->server_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "buf.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "flow.h"
|
||||
#include "json.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "packet.h"
|
||||
#include "peer.h"
|
||||
#include "proto.h"
|
||||
@@ -92,7 +93,7 @@ static bool receive_autodetect_parse(struct receive *receive, struct packet *pac
|
||||
|
||||
for (size_t i = 0; i < NUM_PARSERS; i++) {
|
||||
if (parsers[i].parse(buf, packet, state)) {
|
||||
fprintf(stderr, "R %s: Detected input format %s\n", receive->id, parsers[i].name);
|
||||
log_write('R', receive->id, "Detected input format: %s", parsers[i].name);
|
||||
receive->parser_wrapper = receive_parse_wrapper;
|
||||
receive->parser = parsers[i].parse;
|
||||
return true;
|
||||
@@ -105,7 +106,7 @@ static bool receive_autodetect_parse(struct receive *receive, struct packet *pac
|
||||
}
|
||||
|
||||
static void receive_del(struct receive *receive) {
|
||||
fprintf(stderr, "R %s: Connection closed\n", receive->id);
|
||||
log_write('R', receive->id, "Connection closed");
|
||||
peer_count_in--;
|
||||
peer_epoll_del((struct peer *) receive);
|
||||
assert(!close(receive->peer.fd));
|
||||
@@ -134,14 +135,14 @@ static void receive_read(struct peer *peer) {
|
||||
continue;
|
||||
}
|
||||
if (++packet.hops > receive_max_hops) {
|
||||
fprintf(stderr, "R %s: Packet exceeded hop limit (%u > %u); dropping. You may have a loop in your configuration.\n", receive->id, packet.hops, receive_max_hops);
|
||||
log_write('R', receive->id, "Packet exceeded hop limit (%u > %u); dropping. You may have a loop in your configuration.", packet.hops, receive_max_hops);
|
||||
continue;
|
||||
}
|
||||
send_write(&packet);
|
||||
}
|
||||
|
||||
if (receive->buf.length == BUF_LEN_MAX) {
|
||||
fprintf(stderr, "R %s: Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.\n", receive->id);
|
||||
log_write('R', receive->id, "Input buffer overrun. This probably means that adsbus doesn't understand the protocol that this source is speaking.");
|
||||
receive_del(receive);
|
||||
return;
|
||||
}
|
||||
@@ -166,7 +167,7 @@ static void receive_new(int fd, void __attribute__((unused)) *passthrough, struc
|
||||
|
||||
peer_epoll_add((struct peer *) receive, EPOLLIN);
|
||||
|
||||
fprintf(stderr, "R %s: New receive connection\n", receive->id);
|
||||
log_write('R', receive->id, "New receive connection");
|
||||
}
|
||||
|
||||
void receive_init() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "flow.h"
|
||||
#include "json.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "packet.h"
|
||||
#include "peer.h"
|
||||
#include "proto.h"
|
||||
@@ -89,7 +90,7 @@ static struct serializer {
|
||||
#define NUM_SERIALIZERS (sizeof(serializers) / sizeof(*serializers))
|
||||
|
||||
static void send_del(struct send *send) {
|
||||
fprintf(stderr, "S %s (%s): Connection closed\n", send->id, send->serializer->name);
|
||||
log_write('S', send->id, "Connection closed");
|
||||
peer_count_out--;
|
||||
peer_epoll_del((struct peer *) send);
|
||||
assert(!close(send->peer.fd));
|
||||
@@ -121,7 +122,7 @@ static void send_new(int fd, void *passthrough, struct peer *on_close) {
|
||||
|
||||
peer_epoll_add((struct peer *) send, 0);
|
||||
|
||||
fprintf(stderr, "S %s (%s): New send connection\n", send->id, serializer->name);
|
||||
log_write('S', send->id, "New send connection: %s", serializer->name);
|
||||
}
|
||||
|
||||
void send_init() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "server.h"
|
||||
|
||||
uint8_t server_id[UUID_LEN];
|
||||
@@ -9,5 +8,5 @@ char server_version[] = "https://github.com/flamingcowtv/adsb-tools#1";
|
||||
|
||||
void server_init() {
|
||||
uuid_gen(server_id);
|
||||
fprintf(stderr, "X %s: Server start\n", server_id);
|
||||
log_write('X', server_id, "Server start");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
Reference in New Issue
Block a user