mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 10:16:41 +00:00
util: Make CRIU run_id machine-level unique.
Instead of relying on chance of CLOCK_MONOTONIC reading being unique, use pid namespace ID that combined with the process ID will make it unique on the machine level. If pidns is not enabled on a kernel we'll get ENOENT, but then CRIU's pid will already be unique. If there is some other error, log it but continue, as the socket clash (if it happens) will result in a failed run anyway. Fixes:45e048d77a(2022-03-31 "criu: generate unique socket names") Fixes:408a7d82d6(2022-02-12 "util: add an unique ID of the current criu run") Change-Id: I111c006e1b5b1db8932232684c976a84f4256e49 Signed-off-by: Michał Mirosław <emmir@google.com>
This commit is contained in:
parent
eecc53d05a
commit
9ad59f58ff
1 changed files with 8 additions and 3 deletions
11
criu/util.c
11
criu/util.c
|
|
@ -1880,11 +1880,16 @@ uint64_t criu_run_id;
|
|||
|
||||
void util_init(void)
|
||||
{
|
||||
struct timespec tp;
|
||||
struct stat statbuf;
|
||||
|
||||
criu_run_id = getpid();
|
||||
if (!stat("/proc/self/ns/pid", &statbuf))
|
||||
criu_run_id |= (uint64_t)statbuf.st_ino << 32;
|
||||
else if (errno != ENOENT)
|
||||
pr_perror("Can't stat /proc/self/ns/pid - CRIU run id might not be unique");
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
criu_run_id = ((uint64_t)getpid() << 32) + tp.tv_sec + tp.tv_nsec;
|
||||
compel_run_id = criu_run_id;
|
||||
pr_info("CRIU run id = %#" PRIx64 "\n", criu_run_id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue