[PATCH] call setproctitle_init in samba daemon

Ralph Böhme slow at samba.org
Sun Sep 17 23:41:30 UTC 2017


On Thu, Sep 14, 2017 at 05:35:06AM +0000, Gary Lockyer via samba-technical wrote:
> Address BUG: https://bugzilla.samba.org/show_bug.cgi?id=9816
> 
> But more importantly displays meaningful output in ps.

generally looks good, two issue:

- spelling mistake, setptoctitle_init instead of setproctitle_init
                        ^

- one hunk only changed the indentation of a function:

  @@ -355,8 +355,8 @@ static void atfork_child(void) {
    main server.
   */
   static int binary_smbd_main(const char *binary_name,
  -                               int argc,
  -                               const char *argv[])
  +                           int argc,
  +                           const char *argv[])
   {
          bool opt_daemon = false;
          bool opt_interactive = false;
  
  I guess this can be removed?

- the three args main() variant is not-portable afaict, we may want to use the
  portable global environ pointer instead, cf the FIXUP commit in the attached
  patchset

- one commit message had a few spelling mistakes also fixed in the attached
  patchset

Cheerio!
-slow
-------------- next part --------------
From 41093b6d476dfaaf9b4c368b8a9208a13d1bf66b Mon Sep 17 00:00:00 2001
From: Gary Lockyer <gary at catalyst.net.nz>
Date: Thu, 14 Sep 2017 09:36:21 +1200
Subject: [PATCH 1/4] s4:smbd: call setproctitle_init

Call setproctitle_init() in main which suppresses the
  "samba: setproctitle not initialized, please either call
   setproctitle_init() or link against libbsd-ctor."
messages, but more importantly it displays meaningful details in ps
output.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=9816

Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
---
 lib/replace/replace.c | 5 +++++
 lib/replace/replace.h | 4 ++++
 lib/replace/wscript   | 2 ++
 source4/smbd/server.c | 3 ++-
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index 9351b6c94e3..dc81e9cd5ab 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -942,3 +942,8 @@ void rep_setproctitle(const char *fmt, ...)
 {
 }
 #endif
+#ifndef HAVE_SETPROCTITLE_INIT
+void rep_setproctitle_init(int argc, char *argv[], char *envp[])
+{
+}
+#endif
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index a41e9f89d20..128978c561e 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -918,6 +918,10 @@ int usleep(useconds_t);
 void rep_setproctitle(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
 #endif
 
+#ifndef HAVE_SETPROCTITLE_INIT
+#define setproctitle_init rep_setproctitle_init
+void rep_setproctitle_init(int argc, char *argv[], char *envp[]);
+#endif
 bool nss_wrapper_enabled(void);
 bool nss_wrapper_hosts_enabled(void);
 bool socket_wrapper_enabled(void);
diff --git a/lib/replace/wscript b/lib/replace/wscript
index 6972f2d6e40..f7dd4d806e4 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -271,6 +271,8 @@ def configure(conf):
         conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
     if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
         conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
+    if not conf.CHECK_FUNCS('setptoctitle_init'):
+        conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
 
     if not conf.CHECK_FUNCS('closefrom'):
         conf.CHECK_FUNCS_IN('closefrom', 'bsd', headers='bsd/unistd.h')
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index ba520e0a8f5..ddcab73a498 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -629,7 +629,8 @@ static int binary_smbd_main(const char *binary_name,
 	return 0;
 }
 
-int main(int argc, const char *argv[])
+int main(int argc, const char *argv[], const char *envp[])
 {
+	setproctitle_init(argc,discard_const(argv), discard_const(envp));
 	return binary_smbd_main("samba", argc, argv);
 }
-- 
2.13.5


From 44c658d280a2015b081937ba495b8685017e5296 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sat, 16 Sep 2017 12:16:20 -0700
Subject: [PATCH 2/4] FIXUP: previous commit

Use environ directly instead of using non-standard three argument
main().
---
 lib/replace/wscript   | 2 +-
 source4/smbd/server.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index f7dd4d806e4..952663257fa 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -271,7 +271,7 @@ def configure(conf):
         conf.CHECK_FUNCS_IN('getpeereid', 'bsd', headers='sys/types.h bsd/unistd.h')
     if not conf.CHECK_FUNCS_IN('setproctitle', 'setproctitle', headers='setproctitle.h'):
         conf.CHECK_FUNCS_IN('setproctitle', 'bsd', headers='sys/types.h bsd/unistd.h')
-    if not conf.CHECK_FUNCS('setptoctitle_init'):
+    if not conf.CHECK_FUNCS('setproctitle_init'):
         conf.CHECK_FUNCS_IN('setproctitle_init', 'bsd', headers='sys/types.h bsd/unistd.h')
 
     if not conf.CHECK_FUNCS('closefrom'):
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index ddcab73a498..dccc826d595 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -629,8 +629,9 @@ static int binary_smbd_main(const char *binary_name,
 	return 0;
 }
 
-int main(int argc, const char *argv[], const char *envp[])
+int main(int argc, const char *argv[])
 {
-	setproctitle_init(argc,discard_const(argv), discard_const(envp));
+	setproctitle_init(argc, discard_const(argv), environ);
+
 	return binary_smbd_main("samba", argc, argv);
 }
-- 
2.13.5


From aba77ba73b1f7f5e351b9d1665a006e04b6aab48 Mon Sep 17 00:00:00 2001
From: Gary Lockyer <gary at catalyst.net.nz>
Date: Wed, 6 Sep 2017 16:04:50 +1200
Subject: [PATCH 3/4] s4:smbd: set samba root process title

Set the process title in the samba root process to clearly identify it
in ps output.

Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 source4/smbd/server.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index dccc826d595..249391c0dff 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -382,6 +382,8 @@ static int binary_smbd_main(const char *binary_name,
 	struct server_state *state = NULL;
 	struct tevent_signal *se = NULL;
 
+	setproctitle("root process");
+
 	pc = poptGetContext(binary_name, argc, argv, long_options, 0);
 	while((opt = poptGetNextOpt(pc)) != -1) {
 		switch(opt) {
-- 
2.13.5


From bdcf916d947943b0edb7f6050808e3e20c047de3 Mon Sep 17 00:00:00 2001
From: Gary Lockyer <gary at catalyst.net.nz>
Date: Wed, 6 Sep 2017 15:59:55 +1200
Subject: [PATCH 4/4] tfork: set waiter process title

Display a meaningful process title for the waiter process, now that smbd is
calling setproctitle_init() and this value will be displayed in ps
output.

Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 lib/util/tfork.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/util/tfork.c b/lib/util/tfork.c
index ca4ab5076ce..8ed5811c536 100644
--- a/lib/util/tfork.c
+++ b/lib/util/tfork.c
@@ -537,6 +537,7 @@ static pid_t tfork_start_waiter_and_worker(struct tfork_state *state,
 	/*
 	 * The "waiter" child.
 	 */
+	setproctitle("tfork waiter process");
 	CatchSignal(SIGCHLD, SIG_DFL);
 
 	close(status_sp_caller_fd);
-- 
2.13.5



More information about the samba-technical mailing list