lib/util: Make prctl_set_comment take a printf format string
authorAndrew Bartlett <abartlet@samba.org>
Fri, 21 Feb 2020 20:06:19 +0000 (09:06 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 27 Feb 2020 03:42:35 +0000 (03:42 +0000)
This makes it easier to pass a small amount of variable information
into the buffer, to distinguish processes in the AD DC.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
lib/util/util_process.c
lib/util/util_process.h
source3/lib/util.c

index bde6060597eae5ae96d22414a80b490aa2db962f..bb5dc15fa98718bc272990110b3b2e17cf0041e3 100644 (file)
  */
 
 #include "util_process.h"
-#include "config.h"
+#include "replace.h"
 
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
 
-int prctl_set_comment(const char *comment)
+int prctl_set_comment(const char *comment_format, ...)
 {
 #if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
+       char comment[16];
+       va_list ap;
+       va_start(ap, comment_format);
+       vsnprintf(comment, sizeof(comment), comment_format, ap);
+       va_end(ap);
+
        return prctl(PR_SET_NAME, (unsigned long) comment, 0, 0, 0);
 #endif
        return 0;
index 6e1ef07f1860fe59bf53ee52bb5c6a6b0884a257..5b337d32aec5a876c90f2d40405834d141abe96a 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef _SAMBA_UTIL_PROCESS_H
 #define _SAMBA_UTIL_PROCESS_H
 
+#include "replace.h"
+
 /**
  * @brief Set the process comment name.
  *
@@ -30,6 +32,6 @@
  *
  * @return              -1 on error, 0 on success.
  */
-int prctl_set_comment(const char *comment);
+int prctl_set_comment(const char *comment_format, ...) PRINTF_ATTRIBUTE(1,2);
 
 #endif
index e9a7368b290c4486d021bdcd3e90f341fe94b0b8..4b276415378b619b099962c716c6ed8b9cb52295 100644 (file)
@@ -513,7 +513,7 @@ NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
        }
 
        if (comment) {
-               prctl_set_comment(comment);
+               prctl_set_comment("%s", comment);
        }
 
  done: