9#include "TPluginManager.h"
20#define ut_user ut_name
23#define UTMP_FILE "/etc/utmp"
29#define STRUCT_UTMP struct utmpx
31#if defined(__linux) && defined(__powerpc) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 90)
35#define STRUCT_UTMP struct utmp
52 int hour =
static_cast<int>(realTime / 3600);
53 realTime -= hour * 3600;
54 int min =
static_cast<int>(realTime / 60);
57 <<
"bye,bye\t" <<
DCYAN << getpwuid(getuid())->pw_name <<
RESET_COLOR <<
" after " << hour <<
":"
58 << std::setfill(
'0') << std::setw(2) << min <<
":" << std::setprecision(3) << std::fixed << realTime
59 <<
" h:m:s" << std::endl;
62int main(
int argc,
char** argv)
68 TThread::Initialize();
69 TObject::SetObjectStat(
false);
78 input->SetReturnFromRun(
true);
82 std::cerr << e.
message << std::endl;
84 }
catch(std::runtime_error& e) {
85 std::cerr << e.what() << std::endl;
86 std::cout <<
"Don't know how to handle this error, exiting " << argv[0] <<
"!" << std::endl;
95 gPluginMgr->AddHandler(
"TGuiFactory",
"root",
"GROOTGuiFactory",
"Gui",
"GROOTGuiFactory()");
96 gPluginMgr->AddHandler(
"TBrowserImp",
"GRootBrowser",
"GRootBrowser",
"Gui",
97 "NewBrowser(TBrowser *,const char *,Int_t,Int_t,UInt_t,UInt_t");
98 gPluginMgr->AddHandler(
"TBrowserImp",
"GRootBrowser",
"GRootBrowser",
"Gui",
99 "NewBrowser(TBrowser *,const char *,Int_t,Int_t");
104 FILE* utmp =
nullptr;
105 struct stat file_stats{};
111 utmp = fopen(UTMP_FILE,
"r");
112 if(utmp ==
nullptr) {
116 fstat(fileno(utmp), &file_stats);
117 size = file_stats.st_size;
130 if(ferror(utmp) == 0) {
131 if(fclose(utmp) != EOF && n_read == size) {
132 return static_cast<int>(size /
sizeof(
STRUCT_UTMP));
147 if((ue->ut_name[0] != 0) && (strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)) == 0)) {
159 if(getenv(
"DISPLAY") ==
nullptr) {
160 char* tty = ttyname(0);
164 if(utmp_entry !=
nullptr) {
165 size_t length =
sizeof(utmp_entry->ut_host);
167 auto* host =
new char[length + 1];
169 strncpy(host, utmp_entry->ut_host, length);
170 host[
sizeof(utmp_entry->ut_host)] = 0;
173 if(strchr(host,
':') !=
nullptr) {
174 fprintf(stderr,
"*** DISPLAY not set, setting it to %s\n", host);
176 fprintf(stderr,
"*** DISPLAY not set, setting it to %s:0.0\n", host);
179 setenv(
"DISPLAY", display.c_str(), 0);
181 }
else if(utmp_entry->ut_addr != 0) {
182 struct hostent* he = gethostbyaddr(
reinterpret_cast<const char*
>(&utmp_entry->ut_addr),
sizeof(utmp_entry->ut_addr), AF_INET);
184 fprintf(stderr,
"*** DISPLAY not set, setting it to %s:0.0\n", he->h_name);
185 display = he->h_name;
187 setenv(
"DISPLAY", display.c_str(), 0);
static TGRSIint * instance(int argc=0, char **argv=nullptr, void *options=nullptr, int numOptions=-1, bool noLogo=false, const char *appClassName="grsisort")
static STRUCT_UTMP * SearchEntry(int, const char *)
int main(int argc, char **argv)
static STRUCT_UTMP * gUtmpContents
void SetGRSIPluginHandlers()