aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-11 02:45:24 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-11 03:29:52 +0200
commit8f1d81eefbfe61330a62642893b7e35ce0c3398a (patch)
tree3a63af99aa36ef4bb7b25b3e592ca1b84d7fcec8 /degesch.c
parent0a657a0294b67deebf4fc8d95e9e9220339c1036 (diff)
downloadxK-8f1d81eefbfe61330a62642893b7e35ce0c3398a.tar.gz
xK-8f1d81eefbfe61330a62642893b7e35ce0c3398a.tar.xz
xK-8f1d81eefbfe61330a62642893b7e35ce0c3398a.zip
degesch: add an option to save config on quit
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c50
1 files 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;