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 <rogier777@gmail.com>, but reworked enough by
$SELF that it isn't the same thing anymore.
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;
}
}
if((!serve) && (!servers||!servers->len)) {
- g_message("No configured exports; quitting.");
+ if(err)
+ g_message("No configured exports; quitting.");
exit(EXIT_FAILURE);
}
if (!dontfork)