From 113e3c7bcc73e847e600922f4807012380b51642 Mon Sep 17 00:00:00 2001 From: Felix Palmen Date: Fri, 26 Jul 2024 11:25:21 +0200 Subject: [PATCH] Config: Detect errors writing to file Print an error message telling the user no configuration will be persisted when unable to write the config file. --- src/bin/xmoji/config.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/xmoji/config.c b/src/bin/xmoji/config.c index 6411534..126760d 100644 --- a/src/bin/xmoji/config.c +++ b/src/bin/xmoji/config.c @@ -100,10 +100,18 @@ Config *Config_create(const char *path) self->reading = 0; EmojiHistory_deserialize(self->history, ConfigFile_get(self->cfg, keys[CFG_HISTORY])); - ConfigFile_write(self->cfg); - PSC_Event_register(ConfigFile_changed(self->cfg), self, filechanged, 0); - PSC_Event_register(EmojiHistory_changed(self->history), self, - historychanged, 0); + if (ConfigFile_write(self->cfg) >= 0) + { + PSC_Event_register(ConfigFile_changed(self->cfg), self, + filechanged, 0); + PSC_Event_register(EmojiHistory_changed(self->history), self, + historychanged, 0); + } + else + { + PSC_Log_fmt(PSC_L_ERROR, "Cannot write to `%s', giving up. Runtime " + "configuration will NOT be persisted.", self->cfgfile); + } return self; }