DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
src
LocalContext.cpp
Go to the documentation of this file.
1
/*
2
* LocalContext.cxx
3
* ers
4
*
5
* Created by Serguei Kolos on 26.11.05.
6
* Copyright 2004 CERN. All rights reserved.
7
*
8
*/
9
#include <sys/types.h>
10
#include <pwd.h>
11
#include <unistd.h>
12
#include <stdlib.h>
13
14
#include <iterator>
15
16
#include <
ers/LocalContext.hpp
>
17
18
#if !defined(__APPLE__) && !defined(__rtems__)
19
#include <sys/syscall.h>
20
#include <execinfo.h>
21
#else
22
int
backtrace(
void
**,
int
) {
23
return
0;
24
}
25
#endif
26
27
pid_t
gettid
() {
28
#if !defined(__APPLE__) && !defined(__rtems__)
29
return
syscall( SYS_gettid );
30
#else
31
return
0;
32
#endif
33
}
34
35
36
namespace
37
{
38
const
char
* get_cwd( )
39
{
40
static
std::string buf;
41
if
( buf.empty() )
42
{
43
char
tmp[1024];
44
if
( ::getcwd( tmp,
sizeof
( tmp ) ) )
45
buf = tmp;
46
}
47
return
buf.c_str();
48
}
49
50
const
char
* get_user_name()
51
{
52
static
std::string buf;
53
if
( buf.empty() )
54
{
55
struct
passwd * psw = ::getpwuid( geteuid() );
56
if
( psw )
57
buf = psw->pw_name;
58
}
59
return
buf.c_str();
60
}
61
62
const
char
* get_host_name()
63
{
64
static
std::string buf;
65
if
( buf.empty() )
66
{
67
char
tmp[1024];
68
if
( !::gethostname( tmp,
sizeof
( tmp ) ) )
69
buf = tmp;
70
}
71
return
buf.c_str();
72
}
73
}
74
75
76
ers::LocalContext::LocalContext
(
77
const
char
* package_name,
78
const
char
*
filename
,
79
int
line_number,
80
const
char
* function_name,
81
bool
debug)
82
: m_package_name( package_name ),
83
m_file_name(
filename
),
84
m_function_name( function_name ),
85
m_line_number( line_number ),
86
m_thread_id(
gettid
() ),
87
m_stack_size( debug ? backtrace( m_stack,
std
::size(m_stack) ) : 0)
88
{ ; }
89
90
const
char
*
91
ers::LocalContext::application_name
()
const
92
{
93
static
int
pid = ::getpid();
94
static
const
char
* env = ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) ? ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) :
"Undefined"
;
95
96
if
(pid != ::getpid()) {
97
pid = ::getpid();
98
env = ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) ? ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) :
"Undefined"
;
99
}
100
return
env;
101
}
102
103
const
ers::LocalProcessContext
ers::LocalContext::c_process
( get_host_name(),
104
get_cwd(),
105
geteuid(),
106
get_user_name());
gettid
pid_t gettid()
Definition
LocalContext.cpp:27
LocalContext.hpp
ers::LocalContext::application_name
const char * application_name() const
Definition
LocalContext.cpp:91
ers::LocalContext::LocalContext
LocalContext(const char *package_name, const char *filename, int line_number, const char *function_name, bool debug=false)
Definition
LocalContext.cpp:76
ers::LocalContext::c_process
static const LocalProcessContext c_process
Definition
LocalContext.hpp:113
std
Definition
SchemaUtils.hpp:148
ers::LocalProcessContext
Definition
LocalContext.hpp:32
tablepositions::filename
@ filename
Generated on Sat Jun 28 2025 for DUNE-DAQ by
1.12.0