| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

Functions
System::Linux Namespace Reference

Namespace holding Linux specific functions. More...

## Functions
std::vector< std::string > | cmdLineArgs ()
| Get the command line arguments of the process. More...
std::string | typeinfoName (const char *name)
| Get the human readable type name from a typeinfo name. More...
std::string | hostName ()
| Get the system's host name. More...
std::string | osName ()
| Get the operating system's name. More...
std::string | osVersion ()
| Get the operating system's version. More...
std::string | machineType ()
| Get the runner machine's type. More...
std::string | accountName ()
| Get the account name of the current user. More...

## Detailed Description

Namespace holding Linux specific functions.

## Function Documentation

std::string System::Linux::accountName | ( |  | ) |

Get the account name of the current user.

User login name.

Definition at line 122 of file SystemLinux.cpp.

123 {
124
125 const char* acct = ::getlogin();
126 if ( !acct ) acct = ::getenv( "LOGNAME" );
127 if ( !acct ) acct = ::getenv( "USER" );
128
129 return ( acct ? acct : "UNKNOWN" );
130 }

std::vector< std::string > System::Linux::cmdLineArgs | ( |  | ) |

Get the command line arguments of the process.

Command line arguments including executable name as arg[0] as vector of strings.

Definition at line 22 of file SystemLinux.cpp.

23 {
24
25 // Open the file that we can get this information from:
26 char fname[1024];
27 ::sprintf( fname, "/proc/%d/cmdline", ::getpid() );
28 FILE* cmdLine = ::fopen( fname, "r" );
29
30 // The result object:
31 std::vector<std::string> result;
32
33 // Read the command line arguments from there:
34 char cmd[1024];
35 if ( cmdLine ) {
36 long len = ::fread( cmd, sizeof( char ), sizeof( cmd ), cmdLine );
37 if ( len > 0 ) {
38 cmd[len] = 0;
39 for ( char* token = cmd; token - cmd < len; token += ::strlen( token ) + 1 ) {
40 result.push_back( token );
41 }
42 }
43 ::fclose( cmdLine );
44 }
45
46 return result;
47 }
std::vector::push_back
T push_back(T...args)
std::vector< std::string >

std::string System::Linux::hostName | ( |  | ) |

Get the system's host name.

Host name.

Definition at line 70 of file SystemLinux.cpp.

71 {
72
73 static const size_t STRING_SIZE = 512;
74 std::array<char, STRING_SIZE> hname;
75 if (::gethostname( hname.data(), STRING_SIZE ) ) {
76 return "";
77 }
78
79 // According to the gethostname documentation, if a host name is too long
80 // to fit into the array provided by the user, the call will truncate the
81 // name to fit into the array, without adding a terminating null
82 // character at the end, and will not signal an error to the caller.
83 // While SUSv2 guarantees that "Host names are limited to 255 bytes", and
84 // the limit to host names is in practice 64 characters on Linux, just to
85 // be safe, the last character of the returned array is set to null
86 // forecfully.
87 hname.back() = '\0';
88
89 return std::string( hname.data() );
90 }
std::string
STL class.
std::array::data
T data(T...args)
std::array::back
T back(T...args)
std::array
STL class.

std::string System::Linux::machineType | ( |  | ) |

Get the runner machine's type.

Machine type.

Definition at line 112 of file SystemLinux.cpp.

113 {
114
115 struct utsname ut;
116 if (::uname( &ut ) ) {
117 return "UNKNOWN";
118 }
119 return std::string( ut.machine );
120 }
std::string
STL class.

std::string System::Linux::osName | ( |  | ) |

Get the operating system's name.

OS name.

Definition at line 92 of file SystemLinux.cpp.

93 {
94
95 struct utsname ut;
96 if (::uname( &ut ) ) {
97 return "UNKNOWN Linux";
98 }
99 return std::string( ut.sysname );
100 }
std::string
STL class.

std::string System::Linux::osVersion | ( |  | ) |

Get the operating system's version.

OS version.

Definition at line 102 of file SystemLinux.cpp.

103 {
104
105 struct utsname ut;
106 if (::uname( &ut ) ) {
107 return "UNKNOWN version";
108 }
109 return std::string( ut.release );
110 }
std::string
STL class.

std::string System::Linux::typeinfoName | ( | const char * | class_name | ) |

Get the human readable type name from a typeinfo name.

Definition at line 49 of file SystemLinux.cpp.

50 {
51
52 // Demangle the name:
53 int status;
54 auto realname = std::unique_ptr<char, decltype( free )*>(
55 abi::__cxa_demangle( class_name, nullptr, nullptr, &status ), std::free );
56 if ( !realname ) return class_name;
57
58 // Substitute the full type of std::string with "std::string"
59 static const std::regex cxx11_string{
60 "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >( (?=>))?"};
61 std::string result = std::regex_replace( realname.get(), cxx11_string, "std::string" );
62
63 // Substitute ', ' with ','
64 static const std::regex comma_space{", "};
65 result = std::regex_replace( result, comma_space, "," );
66
67 return result;
68 }
std::free
T free(T...args)
std::string
STL class.
std::regex_replace
T regex_replace(T...args)
std::unique_ptr
STL class.
std::regex