From: Andrew Bartlett Date: Fri, 21 Feb 2020 20:06:19 +0000 (+1300) Subject: lib/util: Make prctl_set_comment take a printf format string X-Git-Tag: ldb-2.2.0~1571 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efb3aa95c5f16caea0835b117b8fb524ff2040a6;p=thirdparty%2Fsamba.git lib/util: Make prctl_set_comment take a printf format string 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 Reviewed-by: Gary Lockyer --- diff --git a/lib/util/util_process.c b/lib/util/util_process.c index bde6060597e..bb5dc15fa98 100644 --- a/lib/util/util_process.c +++ b/lib/util/util_process.c @@ -20,15 +20,21 @@ */ #include "util_process.h" -#include "config.h" +#include "replace.h" #ifdef HAVE_SYS_PRCTL_H #include #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; diff --git a/lib/util/util_process.h b/lib/util/util_process.h index 6e1ef07f186..5b337d32aec 100644 --- a/lib/util/util_process.h +++ b/lib/util/util_process.h @@ -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 diff --git a/source3/lib/util.c b/source3/lib/util.c index e9a7368b290..4b276415378 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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: