]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: services: alphabetically sort service names
authorWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 10:12:44 +0000 (12:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 10:12:44 +0000 (12:12 +0200)
Note that we cannot reuse dump_act_rules() because the output format
may be adjusted depending on the call place (this is also used from
haproxy -vv). The principle is the same however.

src/stream.c

index ab08eca6485bd0e6d2a3dc4d52baeba1bd76a3f0..8acce8075c4fb9871ff07d8de80add47ee5d1d93 100644 (file)
@@ -3077,20 +3077,30 @@ struct action_kw *service_find(const char *kw)
  */
 void list_services(FILE *out)
 {
+       const struct action_kw *akwp, *akwn;
        struct action_kw_list *kw_list;
        int found = 0;
        int i;
 
        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;
-                       if (out)
-                               fprintf(out, " %s", kw_list->kw[i].kw);
-                       else
-                               printf("%s\n", kw_list->kw[i].kw);
+
+       for (akwn = akwp = NULL;; akwp = akwn) {
+               list_for_each_entry(kw_list, &service_keywords, list) {
+                       for (i = 0; kw_list->kw[i].kw != NULL; i++) {
+                               if (strordered(akwp ? akwp->kw : NULL,
+                                              kw_list->kw[i].kw,
+                                              akwn != akwp ? akwn->kw : NULL))
+                                       akwn = &kw_list->kw[i];
+                               found = 1;
+                       }
                }
+               if (akwn == akwp)
+                       break;
+               if (out)
+                       fprintf(out, " %s", akwn->kw);
+               else
+                       printf("%s\n", akwn->kw);
        }
        if (!found && out)
                fprintf(out, " none\n");