ctdb-common: Add client pid to connect callback in sock_daemon
authorAmitay Isaacs <amitay@gmail.com>
Tue, 6 Feb 2018 05:42:39 +0000 (16:42 +1100)
committerMartin Schwenke <martins@samba.org>
Thu, 5 Jul 2018 04:52:43 +0000 (06:52 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/sock_daemon.c
ctdb/common/sock_daemon.h
ctdb/server/ctdb_eventd.c
ctdb/tests/src/sock_daemon_test.c
ctdb/wscript

index a56057b3e0b350d3e2a8ee7f0c95af2f28edadb2..3c17519ff89386c6412bbcfcea1f012ba99728dd 100644 (file)
@@ -36,6 +36,7 @@
 #include "common/reqid.h"
 #include "common/comm.h"
 #include "common/pidfile.h"
+#include "common/system.h"
 #include "common/sock_daemon.h"
 
 struct sock_socket {
@@ -114,9 +115,14 @@ static int sock_client_context_init(TALLOC_CTX *mem_ctx,
        }
 
        if (sock->funcs->connect != NULL) {
+               pid_t pid;
                bool status;
 
-               status = sock->funcs->connect(client_ctx, sock->private_data);
+               (void) ctdb_get_peer_pid(client_fd, &pid);
+
+               status = sock->funcs->connect(client_ctx,
+                                             pid,
+                                             sock->private_data);
                if (! status) {
                        talloc_free(client_ctx);
                        close(client_fd);
index aa40995b3e4380c9bf869b9c2ea4198581f5fbd9..705c4fab359e8cd430f3d12eaa4a9f7b3ba414a9 100644 (file)
@@ -109,6 +109,7 @@ struct sock_daemon_funcs {
  * connect() is called when there is a new connection
  *
  * @param[in] client The new socket client context
+ * @param[in] pid The pid of the new client process, or -1 if unknown
  * @param[in] private_data Private data set with the socket
  * @return true if connection should be accepted, false otherwise
  *
@@ -139,6 +140,7 @@ struct sock_daemon_funcs {
  */
 struct sock_socket_funcs {
        bool (*connect)(struct sock_client_context *client,
+                       pid_t pid,
                        void *private_data);
        void (*disconnect)(struct sock_client_context *client,
                           void *private_data);
index ce7b078cf7ab14cba44822c74fae4ff5cc1d077a..cd0284c16a9476794f07c8ade99d1654312ce9b4 100644 (file)
@@ -625,6 +625,7 @@ static struct eventd_client *client_find(struct eventd_context *ectx,
 }
 
 static bool client_connect(struct sock_client_context *client_ctx,
+                          pid_t pid,
                           void *private_data)
 {
        struct eventd_context *ectx = talloc_get_type_abort(
index ebc0b8594c368ed3bb12d655b0b77db2163384f5..916ba2236f034206253cb42774cdb6d3e34ceb4e 100644 (file)
@@ -788,6 +788,7 @@ struct test5_server_state {
 };
 
 static bool test5_connect(struct sock_client_context *client,
+                         pid_t pid,
                          void *private_data)
 {
        struct test5_server_state *state =
index a2ed80251b6e1e794ed2cd3d52c8ba7668b5f6d0..c762106ccc055a0f3aa94b28dd0f74b84680af02 100644 (file)
@@ -450,7 +450,7 @@ def build(bld):
     bld.SAMBA_SUBSYSTEM('ctdb-server-util',
                         source=bld.SUBDIR('common',
                                           '''sock_daemon.c'''),
-                        deps='''samba-util ctdb-util tevent-util
+                        deps='''samba-util ctdb-util ctdb-system tevent-util
                                 LIBASYNC_REQ replace talloc tevent''')
 
     bld.SAMBA_SUBSYSTEM('ctdb-ipalloc',
@@ -800,7 +800,6 @@ def build(bld):
         'comm_client_test',
         'pidfile_test',
         'run_proc_test',
-        'sock_daemon_test',
         'sock_io_test',
         'hash_count_test',
         'run_event_test',
@@ -837,6 +836,12 @@ def build(bld):
                      deps='samba-util ctdb-system popt',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_BINARY('sock_daemon_test',
+                     source='tests/src/sock_daemon_test.c',
+                     deps='''ctdb-system talloc tevent tevent-util
+                             LIBASYNC_REQ samba-util sys_rw''',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
     bld.SAMBA_SUBSYSTEM('ctdb-protocol-tests-basic',
                         source=bld.SUBDIR('tests/src',
                                           'protocol_common_basic.c'),