From: Stefan Metzmacher Date: Mon, 25 Jul 2022 12:29:35 +0000 (+0200) Subject: s3:lib/messages*: s/getpid/tevent_cached_getpid X-Git-Tag: ldb-2.6.1~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94e130fb866d4b7bdbeacb4152093d827d5eb2bb;p=thirdparty%2Fsamba.git s3:lib/messages*: s/getpid/tevent_cached_getpid Our messaging code is very performance critical and we should note waste time in getpid() syscalls... Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 8641a9dad56..7d3d46960a9 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -525,7 +525,7 @@ static NTSTATUS messaging_init_internal(TALLOC_CTX *mem_ctx, } ctx->id = (struct server_id) { - .pid = getpid(), .vnn = NONCLUSTER_VNN + .pid = tevent_cached_getpid(), .vnn = NONCLUSTER_VNN }; ctx->event_ctx = ev; @@ -651,7 +651,7 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx) } msg_ctx->id = (struct server_id) { - .pid = getpid(), .vnn = msg_ctx->id.vnn + .pid = tevent_cached_getpid(), .vnn = msg_ctx->id.vnn }; lck_path = lock_path(talloc_tos(), "msg.lock"); @@ -907,7 +907,7 @@ static int send_all_fn(pid_t pid, void *private_data) struct send_all_state *state = private_data; NTSTATUS status; - if (pid == getpid()) { + if (pid == tevent_cached_getpid()) { DBG_DEBUG("Skip ourselves in messaging_send_all\n"); return 0; } diff --git a/source3/lib/messages_ctdb.c b/source3/lib/messages_ctdb.c index d3e2e3f8589..3e784bf7237 100644 --- a/source3/lib/messages_ctdb.c +++ b/source3/lib/messages_ctdb.c @@ -104,7 +104,7 @@ int messaging_ctdb_init(const char *sockname, int timeout, uint64_t unique_id, goto fail; } - ret = register_with_ctdbd(ctx->conn, getpid(), messaging_ctdb_recv, + ret = register_with_ctdbd(ctx->conn, tevent_cached_getpid(), messaging_ctdb_recv, ctx); if (ret != 0) { DBG_DEBUG("register_with_ctdbd returned %s (%d)\n", diff --git a/source3/lib/messages_ctdb_ref.c b/source3/lib/messages_ctdb_ref.c index 3570ed8ae4c..ed6285f2e36 100644 --- a/source3/lib/messages_ctdb_ref.c +++ b/source3/lib/messages_ctdb_ref.c @@ -61,7 +61,7 @@ void *messaging_ctdb_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev, tmp_refs = refs; - if ((refs != NULL) && (ctdb_pid != getpid())) { + if ((refs != NULL) && (ctdb_pid != tevent_cached_getpid())) { /* * Have to reinit after fork */ @@ -82,7 +82,7 @@ void *messaging_ctdb_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev, *err = ret; return NULL; } - ctdb_pid = getpid(); + ctdb_pid = tevent_cached_getpid(); } result->fde = messaging_ctdb_register_tevent_context(result, ev);