From 405f8907b9da158b8548a4d9b85871406fcc2801 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 13:56:40 +0100 Subject: process-util: actually move rename_process() over The prototype was moved long ago, actually move the definition over now, too. --- src/basic/process-util.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/basic/process-util.c') diff --git a/src/basic/process-util.c b/src/basic/process-util.c index c534656c97..31951cdd4f 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,37 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return 0; } +void rename_process(const char name[8]) { + assert(name); + + /* This is a like a poor man's setproctitle(). It changes the + * comm field, argv[0], and also the glibc's internally used + * name of the process. For the first one a limit of 16 chars + * applies, to the second one usually one of 10 (i.e. length + * of "/sbin/init"), to the third one one of 7 (i.e. length of + * "systemd"). If you pass a longer string it will be + * truncated */ + + prctl(PR_SET_NAME, name); + + if (program_invocation_name) + strncpy(program_invocation_name, name, strlen(program_invocation_name)); + + if (saved_argc > 0) { + int i; + + if (saved_argv[0]) + strncpy(saved_argv[0], name, strlen(saved_argv[0])); + + for (i = 1; i < saved_argc; i++) { + if (!saved_argv[i]) + break; + + memzero(saved_argv[i], strlen(saved_argv[i])); + } + } +} + int is_kernel_thread(pid_t pid) { const char *p; size_t count; -- cgit v1.2.3-54-g00ecf