Add --detach. Add multi-pass flag parsing that lets us get things in the right order.
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <jansson.h>
|
||||
#include <protobuf-c/protobuf-c.h>
|
||||
|
||||
#include "build.h"
|
||||
#include "log.h"
|
||||
#include "opts.h"
|
||||
#include "uuid.h"
|
||||
|
||||
#include "server.h"
|
||||
@@ -11,9 +16,31 @@
|
||||
|
||||
uint8_t server_id[UUID_LEN];
|
||||
char server_version[] = "https://github.com/flamingcowtv/adsb-tools#1";
|
||||
static opts_group server_opts;
|
||||
|
||||
static char log_module = 'X';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void server_init() {
|
||||
uuid_gen(server_id);
|
||||
LOG(server_id, "Server start:");
|
||||
@@ -26,4 +53,6 @@ void server_init() {
|
||||
LOG(server_id, "\tbuild_datetime: %s", __DATE__ " " __TIME__);
|
||||
LOG(server_id, "\tbuild_username: %s", USERNAME);
|
||||
LOG(server_id, "\tbuild_hostname: %s", HOSTNAME);
|
||||
|
||||
opts_call(server_opts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user