aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-12-05 11:21:15 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-12-05 11:21:15 +0200
commit7d9e36f5b5ce1175afcb1f65184b8b2029a2d6a8 (patch)
treebca2ae6c71547d677e32f2494c9a4369644cb9e0 /src
parent1f75cee8eefea039697affb0ab43e3ccb5357861 (diff)
downloadpies-7d9e36f5b5ce1175afcb1f65184b8b2029a2d6a8.tar.gz
pies-7d9e36f5b5ce1175afcb1f65184b8b2029a2d6a8.tar.bz2
Accept full facility.priority in std{out,err} syslog statement.
* src/pies.c (string_to_syslog_facility): Take additional length argument. (string_to_syslog_fp): New function. (_cb_redir): Accept full facility.priority specification. * src/piesctl.c: Remove legacy redirector support.
Diffstat (limited to 'src')
-rw-r--r--src/pies.c58
-rw-r--r--src/piesctl.c10
2 files changed, 41 insertions, 27 deletions
diff --git a/src/pies.c b/src/pies.c
index 4c25c5f..355612f 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -876,7 +876,7 @@ string_to_syslog_priority (const char *key, int *pres)
}
int
-string_to_syslog_facility (const char *key, int *pres)
+string_to_syslog_facility (const char *key, int len, int *pres)
{
static struct tokendef tokdef_fac[] = {
{"auth", LOG_AUTH},
@@ -906,7 +906,40 @@ string_to_syslog_facility (const char *key, int *pres)
{NULL}
};
- return strtotok_ci (tokdef_fac, key, pres);
+ return len == 0
+ ? strtotok_ci (tokdef_fac, key, pres)
+ : strtotok_len_ci (tokdef_fac, key, len, pres);
+}
+
+static int
+string_to_syslog_fp (const char *str, grecs_locus_t *locus, int *pres)
+{
+ size_t len = strcspn (str, ".");
+ int f = pies_log_facility, p = LOG_ERR;
+
+ if (string_to_syslog_facility (str, len, &f) == 0)
+ {
+ if (str[len])
+ {
+ if (string_to_syslog_priority (str + len + 1, &p))
+ {
+ grecs_error (locus, 0, "%s", _("unknown syslog priority"));
+ return 1;
+ }
+ }
+ }
+ else if (str[len])
+ {
+ grecs_error (locus, 0, "%s", _("unknown syslog facility"));
+ return 1;
+ }
+ else if (string_to_syslog_priority (str, &p))
+ {
+ grecs_error (locus, 0, "%s", _("unknown syslog priority"));
+ return 1;
+ }
+ *pres = f | p;
+ return 0;
}
static int
@@ -931,7 +964,7 @@ cb_syslog_facility (enum grecs_callback_command cmd,
else
*(int *) varptr = n;
}
- else if (string_to_syslog_facility (str, varptr))
+ else if (string_to_syslog_facility (str, 0, varptr))
grecs_error (locus, 0, _("unknown syslog facility %s"), str);
return 0;
}
@@ -961,12 +994,8 @@ _cb_redir (enum grecs_callback_command cmd,
break;
}
rp->type = redir_syslog;
- if (string_to_syslog_priority (value->v.string, &rp->v.prio))
- {
- grecs_error (locus, 0, _("unknown syslog priority %s"),
- value->v.string);
- return 1;
- }
+ if (string_to_syslog_fp (value->v.string, locus, &rp->v.prio))
+ return 1;
break;
case GRECS_TYPE_ARRAY:
@@ -995,14 +1024,9 @@ _cb_redir (enum grecs_callback_command cmd,
break;
case redir_syslog:
- if (string_to_syslog_priority (value->v.arg.v[1]->v.string,
- &rp->v.prio))
- {
- grecs_error (locus, 0,
- _("unknown syslog priority %s"),
- value->v.arg.v[1]->v.string);
- return 1;
- }
+ if (string_to_syslog_fp (value->v.arg.v[1]->v.string,
+ locus, &rp->v.prio))
+ return 1;
break;
case redir_file:
diff --git a/src/piesctl.c b/src/piesctl.c
index d790ab2..58f9ad2 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -1075,10 +1075,6 @@ print_comp (FILE *fp, struct json_value *v, size_t n)
else
fbuf[fidx++] = '-';
}
- else if (strcmp (type, "redirector") == 0)
- {
- fbuf[fidx++] = 'R';
- }
else if (strcmp (type, "command") == 0)
{
fbuf[fidx++] = 'E';
@@ -1125,12 +1121,6 @@ print_comp (FILE *fp, struct json_value *v, size_t n)
}
}
}
- else if (strcmp (type, "redirector") == 0)
- {
- p = getval (v, "PID", json_number, 0);
- if (p)
- fprintf (fp, "%10.0f ", p->v.n);
- }
else if (strcmp (type, "command") == 0)
{
p = getval (v, "command", json_string, 0);

Return to:

Send suggestions and report system problems to the System administrator.