DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
src
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
33
int
backtrace(
void
**,
int
) {
34
return
0;
35
}
36
#endif
37
38
pid_t
gettid
() {
39
#if !defined(__APPLE__) && !defined(__rtems__)
40
return
syscall( SYS_gettid );
41
#else
42
return
0;
43
#endif
44
}
45
46
47
namespace
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
87
ers::LocalContext::LocalContext
(
88
const
char
*
package_name
,
89
const
char
*
filename
,
90
int
line_number
,
91
const
char
*
function_name
,
92
bool
debug
)
93
:
m_package_name
(
package_name
),
94
m_file_name
(
filename
),
95
m_function_name
(
function_name
),
96
m_line_number
(
line_number
),
97
m_thread_id
(
gettid
() ),
98
m_stack_size
(
debug
? backtrace(
m_stack
,
std
::size(
m_stack
) ) : 0)
99
{ ; }
100
101
const
char
*
102
ers::LocalContext::application_name
()
const
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
114
const
ers::LocalProcessContext
ers::LocalContext::c_process
( get_host_name(),
115
get_cwd(),
116
geteuid(),
117
get_user_name());
gettid
pid_t gettid()
Definition
LocalContext.cpp:38
LocalContext.hpp
ers::LocalContext::application_name
const char * application_name() const
Definition
LocalContext.cpp:102
ers::LocalContext::function_name
const char * function_name() const
Definition
LocalContext.hpp:89
ers::LocalContext::line_number
int line_number() const
Definition
LocalContext.hpp:95
ers::LocalContext::m_file_name
const char *const m_file_name
Definition
LocalContext.hpp:127
ers::LocalContext::m_line_number
const int m_line_number
Definition
LocalContext.hpp:129
ers::LocalContext::m_function_name
const char *const m_function_name
Definition
LocalContext.hpp:128
ers::LocalContext::package_name
const char * package_name() const
Definition
LocalContext.hpp:98
ers::LocalContext::m_stack
void * m_stack[64]
Definition
LocalContext.hpp:131
ers::LocalContext::LocalContext
LocalContext(const char *package_name, const char *filename, int line_number, const char *function_name, bool debug=false)
Definition
LocalContext.cpp:87
ers::LocalContext::m_thread_id
const pid_t m_thread_id
Definition
LocalContext.hpp:130
ers::LocalContext::m_stack_size
const int m_stack_size
Definition
LocalContext.hpp:132
ers::LocalContext::c_process
static const LocalProcessContext c_process
Definition
LocalContext.hpp:124
ers::LocalContext::m_package_name
const char *const m_package_name
Definition
LocalContext.hpp:126
ers::debug
void debug(const Issue &issue, int level=debug_level())
Definition
ers.hpp:85
std
Definition
SchemaUtils.hpp:118
ers::LocalProcessContext
Definition
LocalContext.hpp:43
tablepositions::filename
@ filename
Definition
ui_constants.hpp:11
Generated on
for DUNE-DAQ by
1.17.0