]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] support a global jobs counter
authorWilly Tarreau <w@1wt.eu>
Tue, 31 Aug 2010 13:39:26 +0000 (15:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Aug 2010 13:39:26 +0000 (15:39 +0200)
This counter is incremented for each incoming connection and each active
listener, and is used to prevent haproxy from stopping upon SIGUSR1. It
will thus be possible for some tasks in increment this counter in order
to prevent haproxy from dying until they have completed their job.

include/types/global.h
src/cfgparse.c
src/haproxy.c
src/proxy.c
src/session.c
src/stream_sock.c

index 12ba8d42c5a80c783937a986204ae633f47c0ea8..fdc1516323a1541a8352b6ccee029c227438690e 100644 (file)
@@ -101,7 +101,8 @@ extern char *progname;          /* program name */
 extern int  pid;                /* current process id */
 extern int  relative_pid;       /* process id starting at 1 */
 extern int  actconn;            /* # of active sessions */
-extern int listeners;
+extern int  listeners;
+extern int  jobs;               /* # of active jobs */
 extern char trash[BUFSIZE];
 extern char *swap_buffer;
 extern int nb_oldpids;          /* contains the number of old pids found */
index 258942ebf88db5844b74c723a1757a53a9b4bfcd..14171ce9fd43f42e1c2b3d2fd0906e65d0195357 100644 (file)
@@ -267,6 +267,7 @@ static int str2listener(char *str, struct proxy *curproxy)
                                tcpv4_add_listener(l);
                        }
 
+                       jobs++;
                        listeners++;
                } /* end for(port) */
        } /* end while(next) */
index 0bbed6f662404f737d2db09220ff391a1292f9bb..3ceb3980b2fe3d15832ce7b08571c791d848b22f 100644 (file)
@@ -124,6 +124,7 @@ struct global global = {
 /*********************************************************************/
 
 int stopping;  /* non zero means stopping in progress */
+int jobs = 0;   /* number of active jobs (conns, listeners, active tasks, ...) */
 
 /* Here we store informations about the pids of the processes we may pause
  * or kill. We will send them a signal every 10 ms until we can bind to all
@@ -920,8 +921,8 @@ void run_poll_loop()
                 * numbers of proxies. */
                maintain_proxies(&next);
 
-               /* stop when there's no connection left and we don't allow them anymore */
-               if (!actconn && listeners == 0)
+               /* stop when there's nothing left to do */
+               if (jobs == 0)
                        break;
 
                /* The poller will ensure it returns around <next> */
index 346d0b3e306d7e91beb4be9fc985bfa19ca68e42..f25216c0eab9233f6ed994daeff608cda585e6d9 100644 (file)
@@ -615,6 +615,7 @@ void stop_proxy(struct proxy *p)
                if (l->state >= LI_ASSIGNED) {
                        delete_listener(l);
                        listeners--;
+                       jobs--;
                }
        }
        p->state = PR_STSTOPPED;
index 0574c0ba5a26e0ab4663163d3da2e1f9c1c695b2..dd130e0258910a2d4fb74e594105ec245d39a3bb 100644 (file)
@@ -1999,6 +1999,7 @@ struct task *process_session(struct task *t)
        if (s->flags & SN_BE_ASSIGNED)
                s->be->beconn--;
        actconn--;
+       jobs--;
        s->listener->nbconn--;
        if (s->listener->state == LI_FULL &&
            s->listener->nbconn < s->listener->maxconn) {
index 1a824bd71b7f974367edbd09ac9ef8fa177bf045..d72d0e5a5195591564594277b75f835cee004ff4 100644 (file)
@@ -1191,6 +1191,7 @@ int stream_sock_accept(int fd)
                        goto out_close;
                }
 
+               jobs++;
                actconn++;
                totalconn++;
                l->nbconn++;
@@ -1207,12 +1208,14 @@ int stream_sock_accept(int fd)
                                EV_FD_CLR(fd, DIR_RD);
                                p->state = PR_STIDLE;
                        }
+                       jobs--;
                        actconn--;
                        l->nbconn--;
                        goto out_close;
                }
                else if (unlikely(ret == 0)) {
                        /* ignore this connection */
+                       jobs--;
                        actconn--;
                        l->nbconn--;
                        close(cfd);