diff --git a/criu/cr-dump.c b/criu/cr-dump.c index b6c3883e3..f7d9b2b09 100644 --- a/criu/cr-dump.c +++ b/criu/cr-dump.c @@ -716,6 +716,9 @@ int dump_thread_core(int pid, CoreEntry *core, const struct parasite_dump_thread tc->has_pdeath_sig = true; tc->pdeath_sig = ti->pdeath_sig; } + tc->comm = xstrdup(ti->comm); + if (tc->comm == NULL) + return -1; } if (!ret) ret = seccomp_dump_thread(pid, tc); diff --git a/criu/cr-restore.c b/criu/cr-restore.c index edbce5d1f..60e095695 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -3461,6 +3461,11 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns if (construct_sigframe(sigframe, sigframe, blkset, tcore)) goto err; + if (thread_args[i].comm) + strncpy(thread_args[i].comm, tcore->thread_core->comm, TASK_COMM_LEN); + else + strncpy(thread_args[i].comm, core->tc->comm, TASK_COMM_LEN); + if (thread_args[i].pid != pid) core_entry__free_unpacked(tcore, NULL); diff --git a/criu/include/parasite.h b/criu/include/parasite.h index 9de0d2e9a..9e2e1498e 100644 --- a/criu/include/parasite.h +++ b/criu/include/parasite.h @@ -170,6 +170,7 @@ struct parasite_dump_thread { tls_t tls; stack_t sas; int pdeath_sig; + char comm[TASK_COMM_LEN]; struct parasite_dump_creds creds[0]; }; diff --git a/criu/include/restorer.h b/criu/include/restorer.h index fd94de6ca..de14eff95 100644 --- a/criu/include/restorer.h +++ b/criu/include/restorer.h @@ -110,6 +110,8 @@ struct thread_restore_args { void *seccomp_filters_data; unsigned int seccomp_filters_n; bool seccomp_force_tsync; + + char comm[TASK_COMM_LEN]; } __aligned(64); typedef long (*thread_restore_fcall_t) (struct thread_restore_args *args); diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c index b9dae3f94..1567ed7a5 100644 --- a/criu/pie/parasite.c +++ b/criu/pie/parasite.c @@ -172,16 +172,28 @@ static int dump_thread_common(struct parasite_dump_thread *ti) arch_get_tls(&ti->tls); ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long) &ti->tid_addr, 0, 0, 0); - if (ret) + if (ret) { + pr_err("Unable to get the clear_child_tid address: %d\n", ret); goto out; + } ret = sys_sigaltstack(NULL, &ti->sas); - if (ret) + if (ret) { + pr_err("Unable to get signal stack context: %d\n", ret); goto out; + } ret = sys_prctl(PR_GET_PDEATHSIG, (unsigned long)&ti->pdeath_sig, 0, 0, 0); - if (ret) + if (ret) { + pr_err("Unable to get the parent death signal: %d\n", ret); goto out; + } + + ret = sys_prctl(PR_GET_NAME, (unsigned long) &ti->comm, 0, 0, 0); + if (ret) { + pr_err("Unable to get the thread name: %d\n", ret); + goto out; + } ret = dump_creds(ti->creds); out: diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c index e5a40a977..5f442e4a2 100644 --- a/criu/pie/restorer.c +++ b/criu/pie/restorer.c @@ -554,6 +554,12 @@ long __export_restore_thread(struct thread_restore_args *args) if (restore_thread_common(args)) goto core_restore_end; + ret = sys_prctl(PR_SET_NAME, (unsigned long) &args->comm, 0, 0, 0); + if (ret) { + pr_err("Unable to set a thread name: %d\n", ret); + goto core_restore_end; + } + pr_info("%ld: Restored\n", sys_gettid()); restore_finish_stage(task_entries_local, CR_STATE_RESTORE); diff --git a/images/core.proto b/images/core.proto index f9a66b2ae..ce25b0971 100644 --- a/images/core.proto +++ b/images/core.proto @@ -86,6 +86,8 @@ message thread_core_entry { optional seccomp_mode seccomp_mode = 11; optional uint32 seccomp_filter = 12; + + optional string comm = 13; } message task_rlimits_entry {