blob: f2702ad1304e5344d687cde99168f0be174547dd [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2015 The Chromium Authors
rickyz5b937a32015-10-21 23:52:202// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Findeisen2a373a2d2019-08-15 19:44:305#include "base/process/process_handle.h"
6
rickyz5b937a32015-10-21 23:52:207#include <stdint.h>
8
Hans Wennborgafeb3902020-06-17 14:42:299#include <ostream>
10
Hans Wennborgc3cffa62020-04-27 10:09:1211#include "base/check.h"
rickyz5b937a32015-10-21 23:52:2012#include "build/build_config.h"
13
14namespace base {
15
16namespace {
Chris Findeisen2a373a2d2019-08-15 19:44:3017ProcessId g_pid_outside_of_namespace = kNullProcessId;
rickyz5b937a32015-10-21 23:52:2018} // namespace
19
Chris Findeisen2a373a2d2019-08-15 19:44:3020std::ostream& operator<<(std::ostream& os, const UniqueProcId& obj) {
21 os << obj.GetUnsafeValue();
22 return os;
23}
rickyz5b937a32015-10-21 23:52:2024
Chris Findeisen2a373a2d2019-08-15 19:44:3025UniqueProcId GetUniqueIdForProcess() {
26 // Used for logging. Must not use LogMessage or any of the macros that call
27 // into it.
28 return (g_pid_outside_of_namespace != kNullProcessId)
29 ? UniqueProcId(g_pid_outside_of_namespace)
30 : UniqueProcId(GetCurrentProcId());
rickyz5b937a32015-10-21 23:52:2031}
32
Xiaohan Wang37e81612022-01-15 18:27:0033#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)
rickyz5b937a32015-10-21 23:52:2034
35void InitUniqueIdForProcessInPidNamespace(ProcessId pid_outside_of_namespace) {
Chris Findeisen2a373a2d2019-08-15 19:44:3036 DCHECK(pid_outside_of_namespace != kNullProcessId);
37 g_pid_outside_of_namespace = pid_outside_of_namespace;
rickyz5b937a32015-10-21 23:52:2038}
39
40#endif
41
42} // namespace base