From 5eb1f2fb4486f654adb9d7888ff7477d48bbd004 Mon Sep 17 00:00:00 2001 From: Wouter Verhelst Date: Wed, 6 Mar 2013 11:50:16 +0100 Subject: [PATCH] Clarify error handling. While working with nbd-server, I tried to allow the clients to fetch a list of exports. After including the following in the generic section of /etc/nbd-server/config: [generic] # other lines ... allowlist nbd-server refused to start, complaining there were no configured exports, even though there were: nass0:root ~ 17 # nbd-server -d ** Message: No configured exports; quitting. Obviously, the line should read 'allowlist = 1', but It would be helpful if nbd-server detected the error, and complained about that instead of (apparently) ignoring the rest of the config file, and issuing the confusing complaint about no configured exports. I also tried 'allowlist = yes'. In that case it gives a descriptive message, although it still confusingly and incorrectly complains that there are no exports: nass0:root ~ 14 # nbd-server -d ** (process:3482): WARNING **: Could not parse config file: Could not parse allowlist in group generic: Key file contains key 'allowlist' which has a value that cannot be interpreted. ** Message: No configured exports; quitting. The cause seems to be that g_key_file_load_from_file fails not only if the file cannot be found or read, but also if it contains syntax errors. Original patch by Rogier , but reworked enough by $SELF that it isn't the same thing anymore. --- nbd-server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nbd-server.c b/nbd-server.c index e905281..9408a5b 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -905,7 +905,8 @@ GArray* parse_cfile(gchar* f, struct generic_conf *const genconf, GError** e) { retval = g_array_new(FALSE, TRUE, sizeof(SERVER)); if(!g_key_file_load_from_file(cfile, f, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &err)) { - g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_NOTFOUND, "Could not open config file %s.", f); + g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_NOTFOUND, "Could not open config file %s: %s", + f, err->message); g_key_file_free(cfile); return retval; } @@ -2774,7 +2775,8 @@ int main(int argc, char *argv[]) { } if((!serve) && (!servers||!servers->len)) { - g_message("No configured exports; quitting."); + if(err) + g_message("No configured exports; quitting."); exit(EXIT_FAILURE); } if (!dontfork) -- 2.34.1