LCOV - code coverage report
Current view: top level - ers/src - LocalContext.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 82.1 % 39 32
Test Date: 2026-07-12 15:23:06 Functions: 83.3 % 6 5

            Line data    Source code
       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         3376 : pid_t gettid() {
      39              : #if !defined(__APPLE__) && !defined(__rtems__)
      40         3376 :     return syscall( SYS_gettid );
      41              : #else
      42              :     return 0;
      43              : #endif
      44              : }
      45              : 
      46              : 
      47              : namespace
      48              : {
      49           76 :     const char * get_cwd( )
      50              :     {
      51          228 :         static std::string buf;
      52           76 :         if ( buf.empty() )
      53              :         {
      54           76 :             char tmp[1024];
      55           76 :             if ( ::getcwd( tmp, sizeof( tmp ) ) )
      56           76 :                 buf = tmp;
      57              :         }
      58           76 :         return buf.c_str();
      59              :     }
      60              : 
      61           76 :     const char * get_user_name()
      62              :     {
      63          152 :         static std::string buf;
      64           76 :         if ( buf.empty() )
      65              :         {
      66           76 :             struct passwd * psw = ::getpwuid( geteuid() );
      67           76 :             if ( psw )
      68           76 :                 buf = psw->pw_name;
      69              :         }
      70           76 :         return buf.c_str();
      71              :     }
      72              : 
      73           76 :     const char * get_host_name()
      74              :     {
      75          152 :         static std::string buf;
      76           76 :         if ( buf.empty() )
      77              :         {
      78           76 :             char tmp[1024];
      79           76 :             if ( !::gethostname( tmp, sizeof( tmp ) ) )
      80           76 :                 buf = tmp;
      81              :         }
      82           76 :         return buf.c_str();
      83              :     }
      84              : }
      85              : 
      86              : 
      87         3376 : ers::LocalContext::LocalContext(
      88              :     const char * package_name,
      89              :     const char * filename,
      90              :     int line_number,
      91              :     const char * function_name,
      92         3376 :     bool debug)
      93         3376 :   : m_package_name( package_name ),
      94         3376 :     m_file_name( filename ),
      95         3376 :     m_function_name( function_name ),
      96         3376 :     m_line_number( line_number ),
      97         6752 :     m_thread_id( gettid() ),
      98         3376 :     m_stack_size( debug ? backtrace( m_stack, std::size(m_stack) ) : 0)
      99         3376 : { ; }
     100              : 
     101              : const char *
     102            0 : ers::LocalContext::application_name() const
     103              : {
     104            0 :     static int pid = ::getpid();
     105            0 :     static const char * env = ::getenv( "DUNEDAQ_APPLICATION_NAME" ) ? ::getenv( "DUNEDAQ_APPLICATION_NAME" ) : "Undefined";
     106              : 
     107            0 :     if (pid != ::getpid()) {
     108            0 :         pid = ::getpid();
     109            0 :         env = ::getenv( "DUNEDAQ_APPLICATION_NAME" ) ? ::getenv( "DUNEDAQ_APPLICATION_NAME" ) : "Undefined";
     110              :     }
     111            0 :     return env;
     112              : }
     113              : 
     114              : const ers::LocalProcessContext  ers::LocalContext::c_process(   get_host_name(),
     115              :                                                                 get_cwd(), 
     116              :                                                                 geteuid(), 
     117              :                                                                 get_user_name());
        

Generated by: LCOV version 2.0-1