2016-03-08 11:26:39 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2016-03-07 17:38:18 -08:00
|
|
|
#include <jansson.h>
|
|
|
|
|
#include <protobuf-c/protobuf-c.h>
|
2016-02-22 21:53:25 -08:00
|
|
|
|
2016-03-07 17:38:18 -08:00
|
|
|
#include "build.h"
|
2016-03-05 22:54:26 -08:00
|
|
|
#include "log.h"
|
2016-03-08 11:26:39 -08:00
|
|
|
#include "opts.h"
|
2016-03-07 17:38:18 -08:00
|
|
|
#include "uuid.h"
|
|
|
|
|
|
2016-02-22 21:53:25 -08:00
|
|
|
#include "server.h"
|
|
|
|
|
|
2016-03-07 17:38:18 -08:00
|
|
|
#pragma GCC diagnostic ignored "-Wdate-time"
|
|
|
|
|
|
2016-02-25 23:37:37 -08:00
|
|
|
uint8_t server_id[UUID_LEN];
|
2016-02-22 21:53:25 -08:00
|
|
|
char server_version[] = "https://github.com/flamingcowtv/adsb-tools#1";
|
2016-03-08 11:26:39 -08:00
|
|
|
static opts_group server_opts;
|
2016-02-22 21:53:25 -08:00
|
|
|
|
2016-03-07 17:02:24 -08:00
|
|
|
static char log_module = 'X';
|
|
|
|
|
|
2016-03-08 11:26:39 -08:00
|
|
|
static bool server_detach(const char __attribute__ ((unused)) *arg) {
|
|
|
|
|
LOG(server_id, "Detaching");
|
|
|
|
|
|
|
|
|
|
int ret = fork();
|
|
|
|
|
assert(ret >= 0);
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
// We are the parent
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG(server_id, "Background process ID: %u", getpid());
|
|
|
|
|
|
|
|
|
|
assert(setsid() >= 0);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void server_opts_add() {
|
|
|
|
|
opts_add("detach", NULL, server_detach, server_opts);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 21:53:25 -08:00
|
|
|
void server_init() {
|
|
|
|
|
uuid_gen(server_id);
|
2016-03-07 17:38:18 -08:00
|
|
|
LOG(server_id, "Server start:");
|
|
|
|
|
LOG(server_id, "\tgit_last_change: %s", GIT_LAST_CHANGE);
|
|
|
|
|
LOG(server_id, "\tgit_local_clean: %s", GIT_LOCAL_CLEAN ? "true" : "false");
|
|
|
|
|
LOG(server_id, "\tclang_version: %s", __clang_version__);
|
|
|
|
|
LOG(server_id, "\tglibc_version: %d.%d", __GLIBC__, __GLIBC_MINOR__);
|
|
|
|
|
LOG(server_id, "\tjansson_version: %s", JANSSON_VERSION);
|
|
|
|
|
LOG(server_id, "\tprotobuf-c_version: %s", PROTOBUF_C_VERSION);
|
|
|
|
|
LOG(server_id, "\tbuild_datetime: %s", __DATE__ " " __TIME__);
|
|
|
|
|
LOG(server_id, "\tbuild_username: %s", USERNAME);
|
|
|
|
|
LOG(server_id, "\tbuild_hostname: %s", HOSTNAME);
|
2016-03-08 11:26:39 -08:00
|
|
|
|
|
|
|
|
opts_call(server_opts);
|
2016-02-22 21:53:25 -08:00
|
|
|
}
|