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 <pwd.h>
21
#include <stdlib.h>
22
#include <sys/types.h>
23
#include <unistd.h>
24
25
#include <iterator>
26
27
#include <
ers/LocalContext.hpp
>
28
29
#if !defined(__APPLE__) && !defined(__rtems__)
30
#include <execinfo.h>
31
#include <sys/syscall.h>
32
#else
33
int
34
backtrace(
void
**,
int
)
35
{
36
return
0;
37
}
38
#endif
39
40
pid_t
41
gettid
()
42
{
43
#if !defined(__APPLE__) && !defined(__rtems__)
44
return
syscall(SYS_gettid);
45
#else
46
return
0;
47
#endif
48
}
49
50
namespace
{
51
const
char
*
52
get_cwd()
53
{
54
static
std::string buf;
55
if
(buf.empty()) {
56
char
tmp[1024];
57
if
(::getcwd(tmp,
sizeof
(tmp)))
58
buf = tmp;
59
}
60
return
buf.c_str();
61
}
62
63
const
char
*
64
get_user_name()
65
{
66
static
std::string buf;
67
if
(buf.empty()) {
68
struct
passwd* psw = ::getpwuid(geteuid());
69
if
(psw)
70
buf = psw->pw_name;
71
}
72
return
buf.c_str();
73
}
74
75
const
char
*
76
get_host_name()
77
{
78
static
std::string buf;
79
if
(buf.empty()) {
80
char
tmp[1024];
81
if
(!::gethostname(tmp,
sizeof
(tmp)))
82
buf = tmp;
83
}
84
return
buf.c_str();
85
}
86
}
87
88
ers::LocalContext::LocalContext
(
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
}
102
103
const
char
*
104
ers::LocalContext::application_name
()
const
105
{
106
static
int
pid = ::getpid();
107
static
const
char
* env = ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) ? ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) :
"Undefined"
;
108
109
if
(pid != ::getpid()) {
110
pid = ::getpid();
111
env = ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) ? ::getenv(
"DUNEDAQ_APPLICATION_NAME"
) :
"Undefined"
;
112
}
113
return
env;
114
}
115
116
const
ers::LocalProcessContext
ers::LocalContext::c_process
(get_host_name(), get_cwd(), geteuid(), get_user_name());
gettid
pid_t gettid()
Definition
LocalContext.cpp:41
LocalContext.hpp
ers::LocalContext::application_name
const char * application_name() const
Definition
LocalContext.cpp:104
ers::LocalContext::function_name
const char * function_name() const
Definition
LocalContext.hpp:82
ers::LocalContext::line_number
int line_number() const
Definition
LocalContext.hpp:89
ers::LocalContext::m_file_name
const char *const m_file_name
Definition
LocalContext.hpp:113
ers::LocalContext::m_line_number
const int m_line_number
Definition
LocalContext.hpp:115
ers::LocalContext::m_function_name
const char *const m_function_name
Definition
LocalContext.hpp:114
ers::LocalContext::package_name
const char * package_name() const
Definition
LocalContext.hpp:91
ers::LocalContext::m_stack
void * m_stack[64]
Definition
LocalContext.hpp:117
ers::LocalContext::LocalContext
LocalContext(const char *package_name, const char *filename, int line_number, const char *function_name, bool debug=false)
Definition
LocalContext.cpp:88
ers::LocalContext::m_thread_id
const pid_t m_thread_id
Definition
LocalContext.hpp:116
ers::LocalContext::m_stack_size
const int m_stack_size
Definition
LocalContext.hpp:118
ers::LocalContext::c_process
static const LocalProcessContext c_process
Definition
LocalContext.hpp:110
ers::LocalContext::m_package_name
const char *const m_package_name
Definition
LocalContext.hpp:112
ers::debug
void debug(const Issue &issue, int level=debug_level())
Definition
ers.hpp:91
std
Definition
SchemaUtils.hpp:118
ers::LocalProcessContext
Definition
LocalContext.hpp:42
tablepositions::filename
@ filename
Definition
ui_constants.hpp:13
Generated on
for DUNE-DAQ by
1.18.0