]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: return the next srv instance on free_server
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 25 Aug 2021 13:03:46 +0000 (15:03 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 25 Aug 2021 13:29:19 +0000 (15:29 +0200)
As a convenience, return the next server instance from servers list on
free_server.

This is particularily useful when using this function on the servers
list without having to save of the next pointer before calling it.

include/haproxy/server.h
src/proxy.c
src/server.c

index c39b0e3c0a46ec339ef3c32cf3ecaa5e69db16ae..767764880858a3599f9c1beaeeac1df5a05dbd28 100644 (file)
@@ -59,7 +59,7 @@ int srv_set_addr_via_libc(struct server *srv, int *err_code);
 int srv_init_addr(void);
 struct server *cli_find_server(struct appctx *appctx, char *arg);
 struct server *new_server(struct proxy *proxy);
-void free_server(struct server *srv);
+struct server *free_server(struct server *srv);
 int srv_init_per_thr(struct server *srv);
 
 /* functions related to server name resolution */
index 87999ad5d3b9bdc62e09d452f12fe90761406259..5d701866bbf19dbeef42852add7219944079c903 100644 (file)
@@ -130,7 +130,7 @@ static void free_stick_rules(struct list *rules)
 
 void free_proxy(struct proxy *p)
 {
-       struct server *s,*s_next;
+       struct server *s;
        struct cap_hdr *h,*h_next;
        struct listener *l,*l_next;
        struct bind_conf *bind_conf, *bind_back;
@@ -289,11 +289,9 @@ void free_proxy(struct proxy *p)
 
        s = p->srv;
        while (s) {
-               s_next = s->next;
                list_for_each_entry(srvdf, &server_deinit_list, list)
                        srvdf->fct(s);
-               free_server(s);
-               s = s_next;
+               s = free_server(s);
        }/* end while(s) */
 
        list_for_each_entry_safe(l, l_next, &p->conf.listeners, by_fe) {
index 7cec4ce47312e6f7adaaf1d468a1ec88408274ea..583cce7f5b61e54799c583ba0696055ee04ccbb2 100644 (file)
@@ -2213,11 +2213,18 @@ static uint srv_release_dynsrv(struct server *srv)
 /* Deallocate a server <srv> and its member. <srv> must be allocated. For
  * dynamic servers, its refcount is decremented first. The free operations are
  * conducted only if the refcount is nul, unless the process is stopping.
+ *
+ * As a convenience, <srv.next> is returned if srv is not NULL. It may be useful
+ * when calling free_server on the list of servers.
  */
-void free_server(struct server *srv)
+struct server *free_server(struct server *srv)
 {
+       struct server *next = NULL;
+
        if (!srv)
-               return;
+               goto end;
+
+       next = srv->next;
 
        /* For dynamic servers, decrement the reference counter. Only free the
         * server when reaching zero.
@@ -2225,7 +2232,7 @@ void free_server(struct server *srv)
        if (likely(!(global.mode & MODE_STOPPING))) {
                if (srv->flags & SRV_F_DYNAMIC) {
                        if (srv_release_dynsrv(srv))
-                               return;
+                               goto end;
                }
        }
 
@@ -2255,6 +2262,9 @@ void free_server(struct server *srv)
 
        free(srv);
        srv = NULL;
+
+ end:
+       return next;
 }
 
 /* Remove a server <srv> from a tracking list if <srv> is tracking another