31 #include "TInterpreter.h"
34 #include "TUnixSystem.h"
36 #include "TVirtualStreamerInfo.h"
39 #include "TClassTable.h"
56 static thread_local
bool s_ignoreWarnings =
false;
58 static bool s_ignoreEverything =
false;
60 void RootErrorHandlerImpl(
int level,
char const* location,
char const*
message) {
68 if (level >= kFatal) {
69 el_severity = SeverityLevel::kFatal;
70 }
else if (level >= kSysError) {
71 el_severity = SeverityLevel::kSysError;
72 }
else if (level >=
kError) {
78 if(s_ignoreEverything) {
89 if (message != 0) el_message =
message;
100 size_t index1 = el_message.find(precursor);
101 if (index1 != std::string::npos) {
102 size_t index2 = index1 + precursor.length();
103 size_t index3 = el_message.find_first_of(
" :", index2);
104 if (index3 != std::string::npos) {
105 size_t substrlen = index3-index2;
106 el_identifier +=
"-";
107 el_identifier += el_message.substr(index2,substrlen);
110 index1 = el_location.find(
"::");
111 if (index1 != std::string::npos) {
112 el_identifier +=
"/";
113 el_identifier += el_location.substr(0, index1);
119 if ((el_location.find(
"TBranchElement::Fill") != std::string::npos)
120 && (el_message.find(
"fill branch") != std::string::npos)
121 && (el_message.find(
"address") != std::string::npos)
122 && (el_message.find(
"not set") != std::string::npos)) {
123 el_severity = SeverityLevel::kFatal;
126 if ((el_message.find(
"Tree branches") != std::string::npos)
127 && (el_message.find(
"different numbers of entries") != std::string::npos)) {
128 el_severity = SeverityLevel::kFatal;
134 if ((el_message.find(
"no dictionary for class") != std::string::npos) ||
135 (el_message.find(
"already in TClassTable") != std::string::npos) ||
136 (el_message.find(
"matrix not positive definite") != std::string::npos) ||
137 (el_message.find(
"not a TStreamerInfo object") != std::string::npos) ||
138 (el_message.find(
"Problems declaring payload") != std::string::npos) ||
139 (el_message.find(
"Announced number of args different from the real number of argument passed") != std::string::npos) ||
140 (el_location.find(
"Fit") != std::string::npos) ||
141 (el_location.find(
"TDecompChol::Solve") != std::string::npos) ||
142 (el_location.find(
"THistPainter::PaintInit") != std::string::npos) ||
143 (el_location.find(
"TUnixSystem::SetDisplay") != std::string::npos) ||
144 (el_location.find(
"TGClient::GetFontByName") != std::string::npos) ||
145 (el_message.find(
"nbins is <=0 - set to nbins = 1") != std::string::npos) ||
146 (el_message.find(
"nbinsy is <=0 - set to nbinsy = 1") != std::string::npos) ||
148 (el_location.find(
"CINTTypedefBuilder::Setup")!= std::string::npos) and
149 (el_message.find(
"possible entries are in use!") != std::string::npos))) {
165 if (die && (el_location !=
std::string(
"@SUB=TUnixSystem::DispatchSignals"))) {
166 std::ostringstream sstr;
167 sstr <<
"Fatal Root Error: " << el_location <<
"\n" << el_message <<
'\n';
170 except.clearMessage();
178 if (el_severity == SeverityLevel::kFatal) {
180 }
else if (el_severity == SeverityLevel::kSysError) {
187 edm::LogInfo(
"Root_Information") << el_location << el_message ;
191 void RootErrorHandler(
int level,
bool,
char const* location,
char const* message) {
192 RootErrorHandlerImpl(level, location, message);
197 static int full_write(
int fd,
const char *
text)
199 const char *buffer =
text;
200 size_t count = strlen(text);
204 written =
write(fd, buffer, count);
207 if (errno == EINTR) {
continue;}
208 else {
return -errno;}
216 static int full_read(
int fd,
char *inbuf,
size_t len,
int timeout_s=-1)
220 ssize_t complete = 0;
227 else if ((-1 == (flags = fcntl(fd, F_GETFL))))
233 if (-1 == fcntl(fd, F_SETFL, flags | O_NONBLOCK))
242 struct pollfd poll_info{
fd, POLLIN, 0};
244 if (ms_remaining > 0)
246 if (poll(&poll_info, 1, ms_remaining) == 0)
248 if ((flags & O_NONBLOCK) != O_NONBLOCK)
250 fcntl(fd, F_SETFL, flags);
255 else if (ms_remaining < 0)
257 if ((flags & O_NONBLOCK) != O_NONBLOCK)
259 fcntl(fd, F_SETFL, flags);
264 complete =
read(fd, buf, count);
267 if (errno == EINTR) {
continue;}
268 else if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
continue;}
271 int orig_errno = errno;
272 if ((flags & O_NONBLOCK) != O_NONBLOCK)
274 fcntl(fd, F_SETFL, flags);
282 if ((flags & O_NONBLOCK) != O_NONBLOCK) {
283 fcntl(fd, F_SETFL, flags);
288 static int full_cerr_write(
const char *text)
290 return full_write(2, text);
293 void sig_dostack_then_abort(
int sig, siginfo_t*,
void*) {
295 const char* signalname =
"unknown";
298 signalname =
"bus error";
301 signalname =
"segmentation violation";
304 signalname =
"illegal instruction";
308 full_cerr_write(
"\n\nA fatal system signal has occurred: ");
309 full_cerr_write(signalname);
310 full_cerr_write(
"\nThe following is the call stack containing the origin of the signal.\n"
311 "NOTE:The first few functions on the stack are artifacts of processing the signal and can be ignored\n\n");
315 full_cerr_write(
"\nA fatal system signal has occurred: ");
316 full_cerr_write(signalname);
317 full_cerr_write(
"\n");
321 if ((sig == SIGILL) || (sig == SIGSEGV) || (sig == SIGBUS))
323 signal(sig, SIG_DFL);
332 void sig_abort(
int sig, siginfo_t*,
void*) {
337 void set_default_signals() {
338 signal(SIGILL, SIG_DFL);
339 signal(SIGSEGV, SIG_DFL);
340 signal(SIGBUS, SIG_DFL);
360 char buf[2]; buf[1] =
'\0';
363 int result = full_read(fromParent, buf, 1);
369 set_default_signals();
371 full_cerr_write(
"\n\nTraceback helper thread failed to read from parent: ");
372 full_cerr_write(strerror(-result));
373 full_cerr_write(
"\n");
378 set_default_signals();
380 full_write(toParent, buf);
382 else if (buf[0] ==
'2')
391 else if (buf[0] ==
'3')
397 set_default_signals();
399 full_cerr_write(
"\n\nTraceback helper thread got unknown command from parent: ");
400 full_cerr_write(buf);
401 full_cerr_write(
"\n");
412 full_cerr_write(
"\n\nAttempt to request stacktrace failed: ");
413 full_cerr_write(strerror(-result));
414 full_cerr_write(
"\n");
417 char buf[2]; buf[1] =
'\0';
420 full_cerr_write(
"\n\nWaiting for stacktrace completion failed: ");
421 if (result == -ETIMEDOUT)
423 full_cerr_write(
"timed out waiting for GDB to complete.");
427 full_cerr_write(strerror(-result));
429 full_cerr_write(
"\n");
436 char child_stack[4*1024];
437 char *child_stack_ptr = child_stack + 4*1024;
447 if (child_stack_ptr) {}
452 full_cerr_write(
"(Attempt to perform stack dump failed.)\n");
457 if (waitpid(pid, &status, 0) == -1)
459 full_cerr_write(
"(Failed to wait on stack dump output.)\n");
463 full_cerr_write(
"(GDB stack trace failed unexpectedly)\n");
475 syscall(SYS_execve,
"/bin/sh", argv, __environ);
477 execv(
"/bin/sh", argv);
493 unloadSigHandler_(pset.getUntrackedParameter<bool> (
"UnloadRootSigHandler")),
494 resetErrHandler_(pset.getUntrackedParameter<bool> (
"ResetRootErrHandler")),
495 loadAllDictionaries_(pset.getUntrackedParameter<bool>(
"LoadAllDictionaries")),
496 autoLibraryLoader_(loadAllDictionaries_
or pset.getUntrackedParameter<bool> (
"AutoLibraryLoader"))
501 gSystem->ResetSignal(kSigChild);
502 gSystem->ResetSignal(kSigBus);
503 gSystem->ResetSignal(kSigSegmentationViolation);
504 gSystem->ResetSignal(kSigIllegalInstruction);
505 gSystem->ResetSignal(kSigSystem);
506 gSystem->ResetSignal(kSigPipe);
507 gSystem->ResetSignal(kSigAlarm);
508 gSystem->ResetSignal(kSigUrgent);
509 gSystem->ResetSignal(kSigFloatingException);
510 gSystem->ResetSignal(kSigWindowChanged);
516 gSystem->ResetSignal(kSigBus);
517 gSystem->ResetSignal(kSigSegmentationViolation);
518 gSystem->ResetSignal(kSigIllegalInstruction);
537 SetErrorHandler(RootErrorHandler);
542 gInterpreter->SetClassAutoloading(1);
546 TTree::SetMaxTreeSize(kMaxLong64);
547 TH1::AddDirectory(kFALSE);
554 if (!
hasDictionary(
typeid(std::vector<std::vector<unsigned int> >))) {
566 TIter iter(gROOT->GetListOfFiles());
567 TObject *
obj =
nullptr;
568 while(
nullptr != (obj = iter.Next())) {
569 TFile*
f =
dynamic_cast<TFile*
>(
obj);
574 iter = TIter(gROOT->GetListOfFiles());
581 TThread::Initialize();
583 TObject::SetObjectStat(
false);
586 TVirtualStreamerInfo::Optimize(
false);
590 static thread_local TThread guard;
595 desc.
setComment(
"Centralized interface to ROOT.");
597 ->setComment(
"If True, signals are handled by this service, rather than by ROOT.");
599 ->setComment(
"If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
601 ->setComment(
"If True, enables automatic loading of data dictionaries.");
603 ->setComment(
"If True, loads all ROOT dictionaries.");
605 ->setComment(
"If True, do an abort when a signal occurs that causes a crash. If False, ROOT will do an exit which attempts to do a clean shutdown.");
607 ->setComment(
"Sets ROOT's gDebug value.");
608 descriptions.
add(
"InitRootHandlers", desc);
618 s_ignoreWarnings =
false;
623 s_ignoreWarnings =
true;
632 "set pagination no\n"
633 "thread apply all bt\n"
635 "/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) >=
pidStringLength_)
637 std::ostringstream sstr;
638 sstr <<
"Unable to pre-allocate stacktrace handler information";
655 std::ostringstream sstr;
656 sstr <<
"Failed to create child-to-parent pipes (errno=" << errno <<
"): " << strerror(errno);
665 std::ostringstream sstr;
666 sstr <<
"Failed to create child-to-parent pipes (errno=" << errno <<
"): " << strerror(errno);
T getUntrackedParameter(std::string const &, T const &) const
virtual void enableWarnings_() override
static void cmssw_stacktrace_fork()
static void stacktraceFromThread()
static char *const pstackArgv_[]
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void setRefCoreStreamer(bool resetAll=false)
std::vector< Variable::Flags > flags
void installCustomHandler(int signum, CFUNC func)
std::shared_ptr< const void > sigSegvHandler_
std::shared_ptr< const void > sigBusHandler_
static TypeWithDict byName(std::string const &name)
void cachePidInfoHandler(unsigned int, unsigned int)
void setComment(std::string const &value)
static char pidString_[pidStringLength_]
static char *const * getPstackArgv()
std::shared_ptr< const void > sigIllHandler_
virtual void initializeThisThreadForUse() override
virtual void ignoreWarnings_() override
static int childToParent_[2]
void addAdditionalInfo(std::string const &info)
int cmssw_stacktrace(void *)
static std::unique_ptr< std::thread > helperThread_
virtual ~InitRootHandlers()
InitRootHandlers(ParameterSet const &pset, ActivityRegistry &iReg)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
static int parentToChild_[2]
void watchPostForkReacquireResources(PostForkReacquireResources::slot_type const &iSlot)
virtual void willBeUsingThreads() override
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static const int pidStringLength_
static void stacktraceHelperThread()
bool hasDictionary(std::type_info const &)