diff options
author | Mike Christie <michael.christie@oracle.com> | 2023-03-11 01:03:23 +0300 |
---|---|---|
committer | Christian Brauner (Microsoft) <brauner@kernel.org> | 2023-03-12 12:52:46 +0300 |
commit | cf587db2ee0261c74d04f61f39783db88a0b65e4 (patch) | |
tree | 5fecb82e0ea27438d473a165f274b9355ce0cd42 /kernel | |
parent | e0a98139c162af9601ffa8d6db88dbe745f64b3c (diff) | |
download | linux-cf587db2ee0261c74d04f61f39783db88a0b65e4.tar.xz |
kernel: Allow a kernel thread's name to be set in copy_process
This patch allows kernel users to pass in the thread name so it can be
set during creation instead of having to use set_task_comm after the
thread is created.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fork.c | 7 | ||||
-rw-r--r-- | kernel/kthread.c | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index f68954d05e89..81dfb2532148 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2112,6 +2112,9 @@ static __latent_entropy struct task_struct *copy_process( siginitsetinv(&p->blocked, sigmask(SIGKILL)|sigmask(SIGSTOP)); } + if (args->name) + strscpy_pad(p->comm, args->name, sizeof(p->comm)); + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL; /* * Clear TID on mm_release()? @@ -2730,7 +2733,8 @@ pid_t kernel_clone(struct kernel_clone_args *args) /* * Create a kernel thread. */ -pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) +pid_t kernel_thread(int (*fn)(void *), void *arg, const char *name, + unsigned long flags) { struct kernel_clone_args args = { .flags = ((lower_32_bits(flags) | CLONE_VM | @@ -2738,6 +2742,7 @@ pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) .exit_signal = (lower_32_bits(flags) & CSIGNAL), .fn = fn, .fn_arg = arg, + .name = name, .kthread = 1, }; diff --git a/kernel/kthread.c b/kernel/kthread.c index 7e6751b29101..fa4a12ddf7fb 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -396,7 +396,8 @@ static void create_kthread(struct kthread_create_info *create) current->pref_node_fork = create->node; #endif /* We want our own signal handler (we take no signals by default). */ - pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); + pid = kernel_thread(kthread, create, NULL, + CLONE_FS | CLONE_FILES | SIGCHLD); if (pid < 0) { /* Release the structure when caller killed by a fatal signal. */ struct completion *done = xchg(&create->done, NULL); |