summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2018-02-06 16:42:39 +1100
committerMartin Schwenke <martins@samba.org>2018-07-05 06:52:43 +0200
commitf42106fb49deea9a0b185788b07934aff17ef4fd (patch)
treef0594c182208527e282a82767609b5dc114d1d14 /ctdb
parent5586e035f2793cee80e6fb1abbdff3d16451101c (diff)
downloadsamba-f42106fb49deea9a0b185788b07934aff17ef4fd.tar.gz
ctdb-common: Add client pid to connect callback in sock_daemon
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/common/sock_daemon.c8
-rw-r--r--ctdb/common/sock_daemon.h2
-rw-r--r--ctdb/server/ctdb_eventd.c1
-rw-r--r--ctdb/tests/src/sock_daemon_test.c1
-rw-r--r--ctdb/wscript9
5 files changed, 18 insertions, 3 deletions
diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c
index a56057b3e0b..3c17519ff89 100644
--- a/ctdb/common/sock_daemon.c
+++ b/ctdb/common/sock_daemon.c
@@ -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);
diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h
index aa40995b3e4..705c4fab359 100644
--- a/ctdb/common/sock_daemon.h
+++ b/ctdb/common/sock_daemon.h
@@ -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);
diff --git a/ctdb/server/ctdb_eventd.c b/ctdb/server/ctdb_eventd.c
index ce7b078cf7a..cd0284c16a9 100644
--- a/ctdb/server/ctdb_eventd.c
+++ b/ctdb/server/ctdb_eventd.c
@@ -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(
diff --git a/ctdb/tests/src/sock_daemon_test.c b/ctdb/tests/src/sock_daemon_test.c
index ebc0b8594c3..916ba2236f0 100644
--- a/ctdb/tests/src/sock_daemon_test.c
+++ b/ctdb/tests/src/sock_daemon_test.c
@@ -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 =
diff --git a/ctdb/wscript b/ctdb/wscript
index a2ed80251b6..c762106ccc0 100644
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -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'),