]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: services: extend list_services() to dump to stdout
authorWilly Tarreau <w@1wt.eu>
Tue, 29 Mar 2022 13:10:44 +0000 (15:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Mar 2022 16:01:37 +0000 (18:01 +0200)
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
src/stream.c

index 6d28c52cdc69f1319109be46c47c7322011a32d5..a2b7d91932d8d79d3382e1841d2bd5d45a50a886 100644 (file)
@@ -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);
+               }
        }
 }
 
index 3135b7300162e7dbe28194beda591d874d36381d..ab08eca6485bd0e6d2a3dc4d52baeba1bd76a3f0 100644 (file)
@@ -3072,21 +3072,27 @@ struct action_kw *service_find(const char *kw)
        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");
 }