]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/sdk/test/common/random_fork_test.cc
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 // Verifies that IDs don't clash after forking the process.
7 // See https://github.com/opentracing-contrib/nginx-opentracing/issues/52
8 # include "src/common/random.h"
10 # include <sys/mman.h>
11 # include <sys/types.h>
12 # include <sys/wait.h>
17 using opentelemetry::sdk::common::Random
;
19 static uint64_t *child_id
;
23 // Set up shared memory to communicate between parent and child processes.
25 // See https://stackoverflow.com/a/13274800/4447365
26 child_id
= static_cast<uint64_t *>(
27 mmap(nullptr, sizeof(*child_id
), PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_ANONYMOUS
, -1, 0));
31 *child_id
= Random::GenerateRandom64();
37 auto parent_id
= Random::GenerateRandom64();
38 auto child_id_copy
= *child_id
;
39 munmap(static_cast<void *>(child_id
), sizeof(*child_id
));
40 if (parent_id
== child_id_copy
)
42 std::cerr
<< "Child and parent ids are the same value " << parent_id
<< "\n";