diff options
author | Ralph Boehme <slow@samba.org> | 2022-12-02 15:17:20 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-12-14 01:38:29 +0000 |
commit | 19c82c19c009eefe975ae95c8b709fc93f5f4c39 (patch) | |
tree | fe1c43e27c50d6762afafd39d39b1a689f0d2bcd /lib | |
parent | 987cba90573f955fe9c781830daec85ad4d5bf92 (diff) | |
download | samba-19c82c19c009eefe975ae95c8b709fc93f5f4c39.tar.gz |
lib/util: add process_set_title()
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/util_process.c | 32 | ||||
-rw-r--r-- | lib/util/util_process.h | 13 |
2 files changed, 42 insertions, 3 deletions
diff --git a/lib/util/util_process.c b/lib/util/util_process.c index bb5dc15fa98..4b13c591309 100644 --- a/lib/util/util_process.c +++ b/lib/util/util_process.c @@ -26,16 +26,42 @@ #include <sys/prctl.h> #endif -int prctl_set_comment(const char *comment_format, ...) +void process_set_title(const char *short_format, const char *long_format, ...) { #if defined(HAVE_PRCTL) && defined(PR_SET_NAME) + if (short_format != NULL) { + char short_comment[16] = {0,}; + va_list ap; + + va_start(ap, long_format); + vsnprintf(short_comment, sizeof(short_comment), short_format, ap); + va_end(ap); + + prctl(PR_SET_NAME, (unsigned long) short_comment, 0, 0, 0); + } +#endif + + if (long_format != NULL) { + char long_comment[256] = {0,}; + va_list ap; + + va_start(ap, long_format); + vsnprintf(long_comment, sizeof(long_comment), long_format, ap); + va_end(ap); + + setproctitle("%s", long_comment); + } +} + +int prctl_set_comment(const char *comment_format, ...) +{ 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 + process_set_title("%s", "%s", comment); return 0; } diff --git a/lib/util/util_process.h b/lib/util/util_process.h index 5b337d32aec..ccb2a752232 100644 --- a/lib/util/util_process.h +++ b/lib/util/util_process.h @@ -34,4 +34,17 @@ */ int prctl_set_comment(const char *comment_format, ...) PRINTF_ATTRIBUTE(1,2); +/** + * @brief Set the process comment name and longname + * + * @param[in] short_format The comment to set which shouldn't be longer than 16 + * 16 characters (including \0). + * @param[in] long_format The format string and arguments to produce the long + * form of the process name. + * + * @return -1 on error, 0 on success. + */ +void process_set_title(const char *short_format, const char *long_format, ...) + PRINTF_ATTRIBUTE(1,3) PRINTF_ATTRIBUTE(2,3); + #endif |