#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;
}
*/
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