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_ExtractOldChdirFail = 148,
LM_ERR_MPTPAcceptFail = 149, LM_ERR_MPTPAcceptFail = 149,
LM_ERR_MPTPListenFail = 150, LM_ERR_MPTPListenFail = 150,
LM_ERR_PoolInfoBadName = 151,
LM_ERR_PoolInfoUnknown = 152,
} lm_error_t; } lm_error_t;
typedef struct lm_error_desc { typedef struct lm_error_desc {

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -642,3 +642,13 @@ msgstr ""
#, c-format #, c-format
msgid "failed to listen the MPTP socket: %s" msgid "failed to listen the MPTP socket: %s"
msgstr "" 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_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_MPTPAcceptFail, .desc = _("failed to accept the MPTP connection: %s") },
{.code = LM_ERR_MPTPListenFail, .desc = _("failed to listen the MPTP socket: %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; 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; char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key;
lm_pool_t *pool = data; 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; return 0;
}
if (eq(key, POOL_INFO_SIZE)) if (eq(key, POOL_INFO_SIZE))
pool->info.size = atol(value); pool->info.size = atol(value);
else if (eq(key, POOL_INFO_MAINTAINER)) else if (eq(key, POOL_INFO_MAINTAINER))
pool->info.maintainer = strdup(value); pool->info.maintainer = strdup(value);
else if (eq(key, POOL_INFO_PUBKEY)) else if (eq(key, POOL_INFO_PUBKEY))
pool->info.pubkey = strdup(value); 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 0;
}
return 1; return 1;
} }
@ -45,15 +54,19 @@ bool lm_pool_info_load(lm_pool_t *pool) {
return false; return false;
} }
lm_error_clear();
if (ini_parse(pool->info_file, lm_pool_info_handler, pool) < 0) { if (ini_parse(pool->info_file, lm_pool_info_handler, pool) < 0) {
lm_error_set(LM_ERR_PoolInfoBad); if(lm_error() == LM_ERR_NoError)
lm_error_set(LM_ERR_PoolInfoBad);
return false; return false;
} }
if(pool->info.size <= 0 || if(pool->info.size <= 0 ||
pool->info.pubkey == NULL || pool->info.pubkey == NULL ||
pool->info.maintainer == NULL){ pool->info.maintainer == NULL){
lm_error_set(LM_ERR_PoolInfoBad); if(lm_error() == LM_ERR_NoError)
lm_error_set(LM_ERR_PoolInfoBad);
return false; return false;
} }