From: Andrew Bartlett Date: Fri, 21 Feb 2020 20:07:19 +0000 (+1300) Subject: s4-smbd: Make use of prctl_set_comment() X-Git-Tag: ldb-2.2.0~1570 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3136d2fd957d7d5c9f2bcfe6c1724c77739d93f6;p=thirdparty%2Fsamba.git s4-smbd: Make use of prctl_set_comment() This makes it possible to tell different child tasks apart on linux systems that have not compiled against libsetproctitle or libbsd-setproctitle. Use "ps -ef -o pid,comm" to see the tree with these titles. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14287 Signed-off-by: Andrew Bartlett Reviewed-by: Gary Lockyer --- diff --git a/source4/smbd/process_prefork.c b/source4/smbd/process_prefork.c index 5667fb5f1ef..3c93fc0ee2a 100644 --- a/source4/smbd/process_prefork.c +++ b/source4/smbd/process_prefork.c @@ -44,6 +44,7 @@ #include "ldb_wrap.h" #include "lib/util/tfork.h" #include "lib/messaging/irpc.h" +#include "lib/util/util_process.h" #define min(a, b) (((a) < (b)) ? (a) : (b)) @@ -290,6 +291,11 @@ static void prefork_fork_master( pid = getpid(); setproctitle("task[%s] pre-fork master", service_name); + /* + * We must fit within 15 chars of text or we will truncate, so + * we put the constant part last + */ + prctl_set_comment("%s[master]", service_name); /* * this will free all the listening sockets and all state that @@ -690,6 +696,13 @@ static void prefork_fork_worker(struct task_server *task, setproctitle("task[%s] pre-forked worker(%d)", service_name, pd->instances); + /* + * We must fit within 15 chars of text or we will truncate, so + * we put child number last + */ + prctl_set_comment("%s(%d)", + service_name, + pd->instances); prefork_reload_after_fork(); if (service_details->post_fork != NULL) { service_details->post_fork(task, pd); diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index 139339c92ec..e0a3536f638 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -31,6 +31,7 @@ #include "lib/messaging/messaging.h" #include "lib/util/debug.h" #include "source3/lib/messages_dgm.h" +#include "lib/util/util_process.h" static unsigned connections_active = 0; static unsigned smbd_max_processes = 0; @@ -342,6 +343,12 @@ static void standard_accept_connection( pid = getpid(); setproctitle("task[%s] standard worker", proc_ctx->name); + /* + * We must fit within 15 chars of text or we will truncate, so + * we put the constant part last + */ + prctl_set_comment("%s[work]", proc_ctx->name); + /* This is now the child code. We need a completely new event_context to work with */ if (tevent_re_initialise(ev) != 0) { @@ -501,6 +508,11 @@ static void standard_new_task(struct tevent_context *ev, } setproctitle("task[%s]", service_name); + /* + * We must fit within 15 chars of text or we will truncate, so + * we put the constant part last + */ + prctl_set_comment("%s[task]", service_name); /* * Set up the process context to be passed through to the terminate