The Gaudi Framework  master (69a68366)
Loading...
Searching...
No Matches
System::Linux Namespace Reference

Namespace holding Linux specific functions. More...

Functions

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

Detailed Description

Namespace holding Linux specific functions.

Function Documentation

◆ accountName()

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

Get the account name of the current user.

Definition at line 90 of file SystemLinux.cpp.

90 {
91
92 const char* acct = ::getlogin();
93 if ( !acct ) acct = ::getenv( "LOGNAME" );
94 if ( !acct ) acct = ::getenv( "USER" );
95
96 return ( acct ? acct : "UNKNOWN" );
97 }

◆ cmdLineArgs()

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

Get the command line arguments of the process.

Definition at line 24 of file SystemLinux.cpp.

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

◆ hostName()

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

Get the system's host name.

Definition at line 50 of file SystemLinux.cpp.

50 {
51
52 static const size_t STRING_SIZE = 512;
53 std::array<char, STRING_SIZE> hname;
54 if ( ::gethostname( hname.data(), STRING_SIZE ) ) { return ""; }
55
56 // According to the gethostname documentation, if a host name is too long
57 // to fit into the array provided by the user, the call will truncate the
58 // name to fit into the array, without adding a terminating null
59 // character at the end, and will not signal an error to the caller.
60 // While SUSv2 guarantees that "Host names are limited to 255 bytes", and
61 // the limit to host names is in practice 64 characters on Linux, just to
62 // be safe, the last character of the returned array is set to null
63 // forecfully.
64 hname.back() = '\0';
65
66 return std::string( hname.data() );
67 }

◆ machineType()

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

Get the runner machine's type.

Definition at line 83 of file SystemLinux.cpp.

83 {
84
85 struct utsname ut;
86 if ( ::uname( &ut ) ) { return "UNKNOWN"; }
87 return std::string( ut.machine );
88 }

◆ osName()

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

Get the operating system's name.

Definition at line 69 of file SystemLinux.cpp.

69 {
70
71 struct utsname ut;
72 if ( ::uname( &ut ) ) { return "UNKNOWN Linux"; }
73 return std::string( ut.sysname );
74 }

◆ osVersion()

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

Get the operating system's version.

Definition at line 76 of file SystemLinux.cpp.

76 {
77
78 struct utsname ut;
79 if ( ::uname( &ut ) ) { return "UNKNOWN version"; }
80 return std::string( ut.release );
81 }

◆ typeinfoName()

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

Get the human readable type name from a typeinfo name.

Definition at line 48 of file SystemLinux.cpp.

48{ return Detail::normalizeTypeName( class_name, true ); }
std::string normalizeTypeName(const char *mangled_name, bool normalize_commas=false)
Normalize a demangled C++ type name for cross-platform consistency.