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".
diff --git a/src/haproxy.c b/src/haproxy.c
index 6d28c52..a2b7d91 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1827,6 +1827,7 @@
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 @@
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 3135b73..ab08eca 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -3072,21 +3072,27 @@
return action_lookup(&service_keywords, kw);
}
-/* Lists the known services on <out> */
+/* Lists the known services on <out>. If <out> 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");
}