1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/process/process_handle.h" 6 7 #include <stdint.h> 8 9 #include <ostream> 10 11 #include "base/check.h" 12 #include "build/build_config.h" 13 14 namespace base { 15 16 namespace { 17 ProcessId g_pid_outside_of_namespace = kNullProcessId; 18 } // namespace 19 operator <<(std::ostream & os,const UniqueProcId & obj)20std::ostream& operator<<(std::ostream& os, const UniqueProcId& obj) { 21 os << obj.GetUnsafeValue(); 22 return os; 23 } 24 GetUniqueIdForProcess()25UniqueProcId 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()); 31 } 32 33 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX) 34 InitUniqueIdForProcessInPidNamespace(ProcessId pid_outside_of_namespace)35void InitUniqueIdForProcessInPidNamespace(ProcessId pid_outside_of_namespace) { 36 DCHECK(pid_outside_of_namespace != kNullProcessId); 37 g_pid_outside_of_namespace = pid_outside_of_namespace; 38 } 39 40 #endif 41 42 } // namespace base 43