fix: keep pool info error messages

This commit is contained in:
ngn 2024-08-08 16:08:38 +03:00
parent 7e7cd68a1e
commit ae83552e96
4 changed files with 32 additions and 5 deletions

View File

@ -150,6 +150,8 @@ typedef enum lm_error {
LM_ERR_ExtractOldChdirFail = 148,
LM_ERR_MPTPAcceptFail = 149,
LM_ERR_MPTPListenFail = 150,
LM_ERR_PoolInfoBadName = 151,
LM_ERR_PoolInfoUnknown = 152,
} lm_error_t;
typedef struct lm_error_desc {

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-08 15:34+0300\n"
"POT-Creation-Date: 2024-08-08 16:08+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -642,3 +642,13 @@ msgstr ""
#, c-format
msgid "failed to listen the MPTP socket: %s"
msgstr ""
#: src/error.c:170
#, c-format
msgid "pool name (%s) doesn't match with: %s"
msgstr ""
#: src/error.c:171
#, c-format
msgid "unknown key in the configuration: %s"
msgstr ""

View File

@ -167,6 +167,8 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_ExtractOldChdirFail, .desc = _("failed to change directory back from root during extraction")},
{.code = LM_ERR_MPTPAcceptFail, .desc = _("failed to accept the MPTP connection: %s") },
{.code = LM_ERR_MPTPListenFail, .desc = _("failed to listen the MPTP socket: %s") },
{.code = LM_ERR_PoolInfoBadName, .desc = _("pool name (%s) doesn't match with: %s") },
{.code = LM_ERR_PoolInfoUnknown, .desc = _("unknown key in the configuration: %s") },
};
char *fmt = NULL;

View File

@ -12,17 +12,26 @@ int lm_pool_info_handler(void *data, const char *_section, const char *_key, con
char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key;
lm_pool_t *pool = data;
if (!eq(pool->name, section))
if (!eq(pool->name, section)){
pdebug(__func__, "pool name (%s) doesn't match: %s", pool->name, section);
lm_error_set(LM_ERR_PoolInfoBadName, pool->name, section);
return 0;
}
if (eq(key, POOL_INFO_SIZE))
pool->info.size = atol(value);
else if (eq(key, POOL_INFO_MAINTAINER))
pool->info.maintainer = strdup(value);
else if (eq(key, POOL_INFO_PUBKEY))
pool->info.pubkey = strdup(value);
else
else{
pdebug(__func__, "pool info contains unknown key: %s", key);
lm_error_set(LM_ERR_PoolInfoUnknown, key);
return 0;
}
return 1;
}
@ -45,7 +54,10 @@ bool lm_pool_info_load(lm_pool_t *pool) {
return false;
}
lm_error_clear();
if (ini_parse(pool->info_file, lm_pool_info_handler, pool) < 0) {
if(lm_error() == LM_ERR_NoError)
lm_error_set(LM_ERR_PoolInfoBad);
return false;
}
@ -53,6 +65,7 @@ bool lm_pool_info_load(lm_pool_t *pool) {
if(pool->info.size <= 0 ||
pool->info.pubkey == NULL ||
pool->info.maintainer == NULL){
if(lm_error() == LM_ERR_NoError)
lm_error_set(LM_ERR_PoolInfoBad);
return false;
}