mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
lib/util: add process_set_title()
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
987cba9057
commit
19c82c19c0
@ -26,16 +26,42 @@
|
|||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#endif
|
#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 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];
|
char comment[16];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, comment_format);
|
va_start(ap, comment_format);
|
||||||
vsnprintf(comment, sizeof(comment), comment_format, ap);
|
vsnprintf(comment, sizeof(comment), comment_format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return prctl(PR_SET_NAME, (unsigned long) comment, 0, 0, 0);
|
process_set_title("%s", "%s", comment);
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,17 @@
|
|||||||
*/
|
*/
|
||||||
int prctl_set_comment(const char *comment_format, ...) PRINTF_ATTRIBUTE(1,2);
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user