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 <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
33int
34backtrace(void**, int)
35{
36 return 0;
37}
38#endif
39
40pid_t
42{
43#if !defined(__APPLE__) && !defined(__rtems__)
44 return syscall(SYS_gettid);
45#else
46 return 0;
47#endif
48}
49
50namespace {
51const char*
52get_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
63const char*
64get_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
75const char*
76get_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
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 ;
101}
102
103const char*
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
116const ers::LocalProcessContext ers::LocalContext::c_process(get_host_name(), get_cwd(), geteuid(), 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:91