process-util: introduce proc_set_comm() helper
This operation is done at a bunch of places, let's add a type-safe helper for it.
This commit is contained in:
@@ -182,6 +182,7 @@ static int update_argv(const char name[], size_t l) {
|
||||
|
||||
int rename_process_full(const char *comm, const char *invocation) {
|
||||
bool truncated = false;
|
||||
int r;
|
||||
|
||||
/* This is a like a poor man's setproctitle(). It changes the comm field by the name specified by
|
||||
* 'comm', and changes argv[0] and the glibc's internally used names of the process
|
||||
@@ -204,8 +205,9 @@ int rename_process_full(const char *comm, const char *invocation) {
|
||||
|
||||
/* First step, change the comm field. The main thread's comm is identical to the process comm. This means we
|
||||
* can use PR_SET_NAME, which sets the thread name for the calling thread. */
|
||||
if (prctl(PR_SET_NAME, comm) < 0)
|
||||
log_debug_errno(errno, "PR_SET_NAME failed: %m");
|
||||
r = proc_set_comm(comm);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "PR_SET_NAME failed: %m");
|
||||
if (l >= TASK_COMM_LEN) /* Linux userspace process names can be 15 chars at max */
|
||||
truncated = true;
|
||||
|
||||
|
||||
@@ -2288,3 +2288,7 @@ int prctl_safe(int op, unsigned long arg2, unsigned long arg3, unsigned long arg
|
||||
|
||||
return RET_NERRNO(prctl(op, arg2, arg3, arg4, arg5));
|
||||
}
|
||||
|
||||
int proc_set_comm(const char *comm) {
|
||||
return prctl_safe(PR_SET_NAME, (unsigned long) comm, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -257,3 +257,5 @@ _noreturn_ void report_errno_and_exit(int errno_fd, int error);
|
||||
int read_errno(int errno_fd);
|
||||
|
||||
int prctl_safe(int op, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
|
||||
|
||||
int proc_set_comm(const char *comm);
|
||||
|
||||
Reference in New Issue
Block a user