From 5fcc100d911327f2c81befa8e082f70c6b2db34a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 29 Mar 2022 15:10:44 +0200 Subject: [PATCH] MINOR: services: extend list_services() to dump to stdout When no output stream is passed, stdout is used with one entry per line, and this is called from dump_registered_services() when passed the class "svc". --- src/haproxy.c | 6 ++++++ src/stream.c | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index 6d28c52cdc..a2b7d91932 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1827,6 +1827,7 @@ static void dump_registered_keywords(void) printf("all: list all keywords\n"); printf("cfg: configuration keywords\n"); printf("flt: filter names\n"); + printf("svc: service names\n"); continue; } else if (strcmp(kwd_dump, "all") == 0) { @@ -1842,6 +1843,11 @@ static void dump_registered_keywords(void) printf("# List of registered filter names:\n"); flt_dump_kws(NULL); } + + if (all || strcmp(kwd_dump, "svc") == 0) { + printf("# List of registered service names:\n"); + list_services(NULL); + } } } diff --git a/src/stream.c b/src/stream.c index 3135b73001..ab08eca648 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3072,21 +3072,27 @@ struct action_kw *service_find(const char *kw) return action_lookup(&service_keywords, kw); } -/* Lists the known services on */ +/* Lists the known services on . If is null, emit them on stdout one + * per line. + */ void list_services(FILE *out) { struct action_kw_list *kw_list; int found = 0; int i; - fprintf(out, "Available services :"); + if (out) + fprintf(out, "Available services :"); list_for_each_entry(kw_list, &service_keywords, list) { for (i = 0; kw_list->kw[i].kw != NULL; i++) { found = 1; - fprintf(out, " %s", kw_list->kw[i].kw); + if (out) + fprintf(out, " %s", kw_list->kw[i].kw); + else + printf("%s\n", kw_list->kw[i].kw); } } - if (!found) + if (!found && out) fprintf(out, " none\n"); } -- 2.47.3