]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: add process_set_title()
authorRalph Boehme <slow@samba.org>
Fri, 2 Dec 2022 14:17:20 +0000 (15:17 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 14 Dec 2022 01:38:29 +0000 (01:38 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/util_process.c
lib/util/util_process.h

index bb5dc15fa98718bc272990110b3b2e17cf0041e3..4b13c591309a8ab0bcf98f1a516b3eab988e3979 100644 (file)
 #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;
 }
index 5b337d32aec5a876c90f2d40405834d141abe96a..ccb2a7522326b67e1b8be3b47ef228ff4db6b306 100644 (file)
  */
 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