]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: mworker: move IPC functions to mworker.c
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 1 Apr 2019 09:29:55 +0000 (11:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 1 Apr 2019 12:45:37 +0000 (14:45 +0200)
Move the following functions to mworker.c:

void mworker_accept_wrapper(int fd);
void mworker_pipe_register();

include/proto/mworker.h
src/haproxy.c
src/mworker.c

index 87cbdd4eb1866a5efebda104c14fbd4ad1882acc..25d8c8c7f7b7e90553056da246a91c741eaead07 100644 (file)
@@ -20,4 +20,7 @@ void mworker_env_to_proc_list();
 void mworker_block_signals();
 void mworker_unblock_signals();
 
+void mworker_accept_wrapper(int fd);
+void mworker_pipe_register();
+
 #endif /* PROTO_MWORKER_H_ */
index c9da06cd295bac236146107fa9017bec242b5ca6..f3209de9ce45bf6a18bceab4d93d17e8c2272e67 100644 (file)
@@ -2598,58 +2598,6 @@ void deinit(void)
 } /* end deinit() */
 
 
-
-/* This is a wrapper for the sockpair FD, It tests if the socket received an
- * EOF, if not, it calls listener_accept */
-void mworker_accept_wrapper(int fd)
-{
-       char c;
-       int ret;
-
-       while (1) {
-               ret = recv(fd, &c, 1, MSG_PEEK);
-               if (ret == -1) {
-                       if (errno == EINTR)
-                               continue;
-                       if (errno == EAGAIN) {
-                               fd_cant_recv(fd);
-                               return;
-                       }
-                       break;
-               } else if (ret > 0) {
-                       listener_accept(fd);
-                       return;
-               } else if (ret == 0) {
-                       /* At this step the master is down before
-                        * this worker perform a 'normal' exit.
-                        * So we want to exit with an error but
-                        * other threads could currently process
-                        * some stuff so we can't perform a clean
-                        * deinit().
-                        */
-                       exit(EXIT_FAILURE);
-               }
-       }
-       return;
-}
-
-/*
- * This function register the accept wrapper for the sockpair of the master worker
- */
-void mworker_pipe_register()
-{
-       /* The iocb should be already initialized with listener_accept */
-       if (fdtab[proc_self->ipc_fd[1]].iocb == mworker_accept_wrapper)
-               return;
-
-       fcntl(proc_self->ipc_fd[1], F_SETFL, O_NONBLOCK);
-       /* In multi-tread, we need only one thread to process
-        * events on the pipe with master
-        */
-       fd_insert(proc_self->ipc_fd[1], fdtab[proc_self->ipc_fd[1]].owner, mworker_accept_wrapper, 1);
-       fd_want_recv(proc_self->ipc_fd[1]);
-}
-
 /* Runs the polling loop */
 static void run_poll_loop()
 {
index da2323c7df216e8937aa84cdb1a430d3d3ba1f27..2631764986c1c4f4f4ae9f1ca2a22224b0e2cc3e 100644 (file)
  *
  */
 
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include <common/mini-clist.h>
 
+#include <proto/fd.h>
+#include <proto/listener.h>
 #include <proto/mworker.h>
 #include <proto/signal.h>
 
@@ -105,3 +110,58 @@ void mworker_unblock_signals()
 {
        haproxy_unblock_signals();
 }
+
+/* ----- IPC FD (sockpair) related ----- */
+
+/* This wrapper is called from the workers. It is registered instead of the
+ * normal listener_accept() so the worker can exit() when it detects that the
+ * master closed the IPC FD. If it's not a close, we just call the regular
+ * listener_accept() function */
+void mworker_accept_wrapper(int fd)
+{
+       char c;
+       int ret;
+
+       while (1) {
+               ret = recv(fd, &c, 1, MSG_PEEK);
+               if (ret == -1) {
+                       if (errno == EINTR)
+                               continue;
+                       if (errno == EAGAIN) {
+                               fd_cant_recv(fd);
+                               return;
+                       }
+                       break;
+               } else if (ret > 0) {
+                       listener_accept(fd);
+                       return;
+               } else if (ret == 0) {
+                       /* At this step the master is down before
+                        * this worker perform a 'normal' exit.
+                        * So we want to exit with an error but
+                        * other threads could currently process
+                        * some stuff so we can't perform a clean
+                        * deinit().
+                        */
+                       exit(EXIT_FAILURE);
+               }
+       }
+       return;
+}
+
+/*
+ * This function register the accept wrapper for the sockpair of the master worker
+ */
+void mworker_pipe_register()
+{
+       /* The iocb should be already initialized with listener_accept */
+       if (fdtab[proc_self->ipc_fd[1]].iocb == mworker_accept_wrapper)
+               return;
+
+       fcntl(proc_self->ipc_fd[1], F_SETFL, O_NONBLOCK);
+       /* In multi-tread, we need only one thread to process
+        * events on the pipe with master
+        */
+       fd_insert(proc_self->ipc_fd[1], fdtab[proc_self->ipc_fd[1]].owner, mworker_accept_wrapper, 1);
+       fd_want_recv(proc_self->ipc_fd[1]);
+}