aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-25 14:17:58 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-25 14:17:58 +0300
commit68d0e67d55882d1298bb0bf89c954c0ff2b1b823 (patch)
tree1564dbf75cd293204adb0628718bf0f01107e97b
parent4db1e89561d23564a1ab30c009cf4d3a9f41cb4a (diff)
downloadwydawca-68d0e67d55882d1298bb0bf89c954c0ff2b1b823.tar.gz
wydawca-68d0e67d55882d1298bb0bf89c954c0ff2b1b823.tar.bz2
Fix string expansion.
* modules/mailutils/mod_mailutils.c (mail_stats): Handle NULL value. * src/triplet.c (try_timer_var): Don't exit on errors. Handle timer:spool:X:Y properly. (wy_expand_string): Don't exit on errors. Improve error reporting. * src/wydawca.c (wy_stat_expansion): Return after successful expansion.
-rw-r--r--modules/mailutils/mod_mailutils.c8
-rw-r--r--src/triplet.c82
-rw-r--r--src/wydawca.c4
3 files changed, 54 insertions, 40 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c
index a924cdb..00ea697 100644
--- a/modules/mailutils/mod_mailutils.c
+++ b/modules/mailutils/mod_mailutils.c
@@ -806,10 +806,10 @@ mail_stats(struct mailevt *evt)
return;
}
text = wy_expand_stats(tmpl);
-
- mail_send_message(admin_address, text, admin_stat_sign_key);
-
- free(text);
+ if (text) {
+ mail_send_message(admin_address, text, admin_stat_sign_key);
+ free(text);
+ }
}
void
diff --git a/src/triplet.c b/src/triplet.c
index 8ab2f1e..47be116 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -585,6 +585,17 @@ struct wy_varexp {
static void wy_ws_error(const char *fmt, ...);
+static inline void
+report_failed_string(char const *str, size_t len)
+{
+ if (len > 32)
+ wy_log(LOG_ERR, _("failed to expand string %16.16s...%16.16s"),
+ str, str + len - 16);
+ else
+ wy_log(LOG_ERR, _("failed to expand string %*.*s"),
+ (int) len, (int) len, str);
+}
+
static int
try_timer_var(char **retval, char const *var, size_t len)
{
@@ -599,36 +610,36 @@ try_timer_var(char **retval, char const *var, size_t len)
| WRDSF_NOCMD
| WRDSF_ERROR
| WRDSF_SHOWERR)) {
- wy_log(LOG_CRIT, _("failed to expand string %*.*s"),
- (int) len, (int) len, var);
- exit(EX_UNAVAILABLE);
- }
- if (strcmp(ws.ws_wordv[0], "timer") == 0) {
- int n = -1;
-
- if (ws.ws_wordc == 3) {
- if (strcmp(ws.ws_wordv[1], "wydawca") == 0)
- n = WY_TIMER_WYDAWCA;
- else if (strcmp(ws.ws_wordv[1], "triplet") == 0)
- n = WY_TIMER_TRIPLET;
- else if (strcmp(ws.ws_wordv[1], "spool") == 0)
- n = WY_TIMER_SPOOL;
- } else if (ws.ws_wordc == 4 && strcmp(ws.ws_wordv[1], "spool") == 0)
- n = spool_timer_id(ws.ws_wordv[1] + 6);
+ report_failed_string(var, len);
+ } else {
+ if (strcmp(ws.ws_wordv[0], "timer") == 0) {
+ int n = -1;
+
+ if (ws.ws_wordc == 3) {
+ if (strcmp(ws.ws_wordv[1], "wydawca") == 0)
+ n = WY_TIMER_WYDAWCA;
+ else if (strcmp(ws.ws_wordv[1], "triplet") == 0)
+ n = WY_TIMER_TRIPLET;
+ else if (strcmp(ws.ws_wordv[1], "spool") == 0)
+ n = WY_TIMER_SPOOL;
+ } else if (ws.ws_wordc == 4
+ && strcmp(ws.ws_wordv[1], "spool") == 0)
+ n = spool_timer_id(ws.ws_wordv[2]);
- if (n >= 0) {
- double (*tfn) (wydawca_timer_t) = NULL;
-
- if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "real") == 0)
- tfn = timer_get_real;
- else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "user") == 0)
- tfn = timer_get_user;
- else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "system") == 0)
- tfn = timer_get_system;
-
- if (tfn) {
- *retval = timer_format_time(tfn(get_thread_timer(n)));
- rc = WRDSE_OK;
+ if (n >= 0) {
+ double (*tfn) (wydawca_timer_t) = NULL;
+
+ if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "real") == 0)
+ tfn = timer_get_real;
+ else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "user") == 0)
+ tfn = timer_get_user;
+ else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "system") == 0)
+ tfn = timer_get_system;
+
+ if (tfn) {
+ *retval = timer_format_time(tfn(get_thread_timer(n)));
+ rc = WRDSE_OK;
+ }
}
}
}
@@ -721,19 +732,20 @@ wy_expand_string(char const *str, struct wy_varexp *varexp)
if (wordsplit(str, &ws,
WRDSF_OPTIONS
+ | WRDSF_ERROR
| WRDSF_ENV
| WRDSF_ENV_KV
| WRDSF_GETVAR
| WRDSF_CLOSURE
| WRDSF_NOCMD
| WRDSF_UNDEF
- | WRDSF_NOSPLIT | WRDSF_ERROR | WRDSF_SHOWERR)) {
- wy_log(LOG_CRIT, _("failed to expand string %s"), str);
- exit(EX_UNAVAILABLE);
+ | WRDSF_NOSPLIT | WRDSF_ERROR | WRDSF_SHOWERR) == 0) {
+ retval = ws.ws_wordv[0];
+ ws.ws_wordv[0] = NULL;
+ } else {
+ report_failed_string(str, strlen(str));
+ retval = NULL;
}
-
- retval = ws.ws_wordv[0];
- ws.ws_wordv[0] = NULL;
wordsplit_free(&ws);
return retval;
diff --git a/src/wydawca.c b/src/wydawca.c
index d7779bb..b7ccc7d 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -198,9 +198,11 @@ wy_stat_expansion(char **ret, char const *name, size_t len)
*ret = NULL;
if (grecs_asprintf(ret, &size, "%u", wy_get_stat_counter(i)))
return WRDSE_NOSPACE;
+ else
+ return WRDSE_OK;
}
}
- return WRDSE_OK;
+ return WRDSE_UNDEF;
}
void

Return to:

Send suggestions and report system problems to the System administrator.