summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-05-17 22:24:31 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-05-17 22:24:31 +0200
commita2b9f2c732232200fd4822e34d60d4c7f5ad37d2 (patch)
tree590e83f11ea568349e523256606b7fbf0148dd14
parentd8a3a034a13aaabe5877c6b3cdf73e0582e6425f (diff)
downloadfastd-a2b9f2c732232200fd4822e34d60d4c7f5ad37d2.tar
fastd-a2b9f2c732232200fd4822e34d60d4c7f5ad37d2.zip
Add daemon mode
-rw-r--r--src/config.c5
-rw-r--r--src/fastd.c5
-rw-r--r--src/fastd.h1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index f407239..d9397cc 100644
--- a/src/config.c
+++ b/src/config.c
@@ -88,6 +88,7 @@ static void default_config(fastd_config *conf) {
conf->on_disestablish = NULL;
conf->on_disestablish_dir = NULL;
+ conf->daemon = false;
conf->machine_readable = false;
conf->generate_key = false;
conf->show_key = false;
@@ -332,6 +333,7 @@ static void count_peers(fastd_context *ctx, fastd_config *conf) {
#define OPTIONS \
OPTION(usage, "--help" OR "-h", "Shows this help text") \
OPTION(version, "--version" OR "-v", "Shows the fastd version") \
+ OPTION(option_daemon, "--daemon" OR "-d", "Runs fastd in the background") \
OPTION_ARG(option_log_level, "--log-level", "error|warn|info|verbose|debug", "Sets the log level; default is info") \
OPTION_ARG(option_config, "--config" OR "-c", "<filename>", "Loads a config file") \
OPTION_ARG(option_config_peer, "--config-peer", "<filename>", "Loads a config file for a single peer") \
@@ -553,6 +555,9 @@ static void option_on_disestablish(fastd_context *ctx, fastd_config *conf, const
conf->on_disestablish_dir = get_current_dir_name();
}
+static void option_daemon(fastd_context *ctx, fastd_config *conf) {
+ conf->daemon = true;
+}
static void option_generate_key(fastd_context *ctx, fastd_config *conf) {
conf->generate_key = true;
conf->show_key = false;
diff --git a/src/fastd.c b/src/fastd.c
index 0ea9e26..e270a26 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -671,6 +671,11 @@ int main(int argc, char *argv[]) {
init_peers(&ctx);
+ if (conf.daemon) {
+ if (daemon(0, 1) < 0)
+ exit_errno(&ctx, "daemon");
+ }
+
on_up(&ctx);
while (!terminate) {
diff --git a/src/fastd.h b/src/fastd.h
index 6a503d8..564b9c5 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -154,6 +154,7 @@ struct _fastd_config {
char *on_disestablish;
char *on_disestablish_dir;
+ bool daemon;
bool machine_readable;
bool generate_key;
bool show_key;