mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
criu: Initialize util before service worker starts
When restoring dumps in new mount + pid namespaces where multiple dumps share the same network namespace, CRIU may fail due to conflicting unix socket names. This happens because the service worker creates sockets using a pattern that includes criu_run_id, but util_init() is called after cr_service_work() starts. The socket naming pattern "crtools-fd-%d-%d" uses the restore PID and criu_run_id, however criu_run_id is always 0 when not initialized, leading to conflicts when multiple restores run simultaneously either in the same CRIU process or because of multiple CRIU processes doing the same operation in different PID namespaces. Fix this by: - Moving util_init() before cr_service_work() starts - Adding a second util_init() call in the service worker fork to ensure unique IDs across multiple worker runs - Making sure that dump and restore operations have util_init() called early to generate unique socket names With this fix, socket names always include the namespace ID, preventing conflicts when multiple processes with the same pid share a network namespace. Fixes #2499 [ avagin: minore code changes ] Signed-off-by: Lorenzo Fontana <fontanalorenz@gmail.com> Signed-off-by: Andrei Vagin <avagin@google.com>
This commit is contained in:
committed by
Andrei Vagin
parent
9052ef93c7
commit
622b43392f
@@ -1310,6 +1310,14 @@ int cr_service_work(int sk)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
CriuReq *msg = 0;
|
CriuReq *msg = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* util_init initializes criu_run_id and compel_run_id so that sockets
|
||||||
|
* are generated with an unique name identifying the specific process
|
||||||
|
* even in cases where multiple processes with the same pid in
|
||||||
|
* different pid namespaces are sharing the same network namespace.
|
||||||
|
*/
|
||||||
|
util_init();
|
||||||
|
|
||||||
more:
|
more:
|
||||||
opts.mode = CR_SWRK;
|
opts.mode = CR_SWRK;
|
||||||
|
|
||||||
|
@@ -169,7 +169,13 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
pr_err("unknown command: %s\n", argv[optind]);
|
pr_err("unknown command: %s\n", argv[optind]);
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* util_init initializes criu_run_id and compel_run_id so that sockets
|
||||||
|
* are generated with an unique name identifying the specific process
|
||||||
|
* even in cases where multiple processes with the same pid in
|
||||||
|
* different pid namespaces are sharing the same network namespace.
|
||||||
|
*/
|
||||||
|
util_init();
|
||||||
if (opts.mode == CR_SWRK) {
|
if (opts.mode == CR_SWRK) {
|
||||||
if (argc != optind + 2) {
|
if (argc != optind + 2) {
|
||||||
fprintf(stderr, "Usage: criu swrk <fd>\n");
|
fprintf(stderr, "Usage: criu swrk <fd>\n");
|
||||||
@@ -254,8 +260,6 @@ int main(int argc, char *argv[], char *envp[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
util_init();
|
|
||||||
|
|
||||||
if (log_init(opts.output))
|
if (log_init(opts.output))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user