s3:lib/messages*: s/getpid/tevent_cached_getpid
authorStefan Metzmacher <metze@samba.org>
Mon, 25 Jul 2022 12:29:35 +0000 (14:29 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 25 Jul 2022 17:34:33 +0000 (17:34 +0000)
Our messaging code is very performance critical and
we should note waste time in getpid() syscalls...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages.c
source3/lib/messages_ctdb.c
source3/lib/messages_ctdb_ref.c

index 8641a9dad564a2b14ca9d00164952f7a24509dba..7d3d46960a92805179d20a65948dbe31a87ae9b6 100644 (file)
@@ -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;
        }
index d3e2e3f858937fbf7368a6267acd016ea7f4afc7..3e784bf723733d11d96fe13944a7b0b0661baae3 100644 (file)
@@ -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",
index 3570ed8ae4c8c5e8c1446bfccf7215ebe95192ec..ed6285f2e36a75fdb48f33b104fc6ef0e571a042 100644 (file)
@@ -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);