aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;