From 8f1d81eefbfe61330a62642893b7e35ce0c3398a Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 11 Jul 2015 02:45:24 +0200
Subject: degesch: add an option to save config on quit
---
degesch.c | 50 ++++++++++++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/degesch.c b/degesch.c
index 6a25c18..0b709bb 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1578,6 +1578,10 @@ static struct config_schema g_config_behaviour[] =
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off",
.on_change = on_config_logging_change },
+ { .name = "save_on_quit",
+ .comment = "Save configuration before quitting",
+ .type = CONFIG_ITEM_BOOLEAN,
+ .default_ = "on" },
{}
};
@@ -6306,6 +6310,30 @@ dump_matching_options
}
}
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+static void
+save_configuration (struct app_context *ctx)
+{
+ struct str data;
+ str_init (&data);
+ serialize_configuration (ctx, &data);
+
+ struct error *e = NULL;
+ char *filename = write_configuration_file (&data, &e);
+ str_free (&data);
+
+ if (!filename)
+ {
+ log_global_error (ctx,
+ "#s: #s", "Saving configuration failed", e->message);
+ error_free (e);
+ }
+ else
+ log_global_status (ctx, "Configuration written to `#s'", filename);
+ free (filename);
+}
+
// --- Server management -------------------------------------------------------
static bool
@@ -6782,27 +6810,10 @@ handle_command_set (struct handler_args *a)
static bool
handle_command_save (struct handler_args *a)
{
- struct app_context *ctx = a->ctx;
if (*a->arguments)
return false;
- struct str data;
- str_init (&data);
- serialize_configuration (ctx, &data);
-
- struct error *e = NULL;
- char *filename = write_configuration_file (&data, &e);
- str_free (&data);
-
- if (!filename)
- {
- log_global_error (ctx,
- "#s: #s", "Saving configuration failed", e->message);
- error_free (e);
- }
- else
- log_global_status (ctx, "Configuration written to `#s'", filename);
- free (filename);
+ save_configuration (a->ctx);
return true;
}
@@ -9011,6 +9022,9 @@ main (int argc, char *argv[])
while (ctx.polling)
poller_run (&ctx.poller);
+ if (get_config_boolean (ctx.config.root, "behaviour.save_on_quit"))
+ save_configuration (&ctx);
+
app_context_free (&ctx);
free_terminal ();
return EXIT_SUCCESS;
--
cgit v1.2.3-70-g09d2