DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
LocalContext.cpp
Go to the documentation of this file.
1/*
2 * DUNE DAQ modification notice:
3 * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 * Renamed since fork: yes (from src/LocalContext.cxx to src/LocalContext.cpp).
6 *
7 * Original copyright:
8 * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9 * Licensed under the Apache License, Version 2.0.
10 */
11
12/*
13 * LocalContext.cxx
14 * ers
15 *
16 * Created by Serguei Kolos on 26.11.05.
17 * Copyright 2004 CERN. All rights reserved.
18 *
19 */
20#include <sys/types.h>
21#include <pwd.h>
22#include <unistd.h>
23#include <stdlib.h>
24
25#include <iterator>
26
27#include <ers/LocalContext.hpp>
28
29#if !defined(__APPLE__) && !defined(__rtems__)
30#include <sys/syscall.h>
31#include <execinfo.h>
32#else
33int backtrace(void**, int) {
34 return 0;
35}
36#endif
37
38pid_t gettid() {
39#if !defined(__APPLE__) && !defined(__rtems__)
40 return syscall( SYS_gettid );
41#else
42 return 0;
43#endif
44}
45
46
47namespace
48{
49 const char * get_cwd( )
50 {
51 static std::string buf;
52 if ( buf.empty() )
53 {
54 char tmp[1024];
55 if ( ::getcwd( tmp, sizeof( tmp ) ) )
56 buf = tmp;
57 }
58 return buf.c_str();
59 }
60
61 const char * get_user_name()
62 {
63 static std::string buf;
64 if ( buf.empty() )
65 {
66 struct passwd * psw = ::getpwuid( geteuid() );
67 if ( psw )
68 buf = psw->pw_name;
69 }
70 return buf.c_str();
71 }
72
73 const char * get_host_name()
74 {
75 static std::string buf;
76 if ( buf.empty() )
77 {
78 char tmp[1024];
79 if ( !::gethostname( tmp, sizeof( tmp ) ) )
80 buf = tmp;
81 }
82 return buf.c_str();
83 }
84}
85
86
88 const char * package_name,
89 const char * filename,
90 int line_number,
91 const char * function_name,
92 bool debug)
98 m_stack_size( debug ? backtrace( m_stack, std::size(m_stack) ) : 0)
99{ ; }
100
101const char *
103{
104 static int pid = ::getpid();
105 static const char * env = ::getenv( "DUNEDAQ_APPLICATION_NAME" ) ? ::getenv( "DUNEDAQ_APPLICATION_NAME" ) : "Undefined";
106
107 if (pid != ::getpid()) {
108 pid = ::getpid();
109 env = ::getenv( "DUNEDAQ_APPLICATION_NAME" ) ? ::getenv( "DUNEDAQ_APPLICATION_NAME" ) : "Undefined";
110 }
111 return env;
112}
113
115 get_cwd(),
116 geteuid(),
117 get_user_name());
pid_t gettid()
const char * application_name() const
const char * function_name() const
int line_number() const
const char *const m_file_name
const char *const m_function_name
const char * package_name() const
LocalContext(const char *package_name, const char *filename, int line_number, const char *function_name, bool debug=false)
const pid_t m_thread_id
static const LocalProcessContext c_process
const char *const m_package_name
void debug(const Issue &issue, int level=debug_level())
Definition ers.hpp:85