33 #include "TInterpreter.h"
36 #include "TUnixSystem.h"
38 #include "TVirtualStreamerInfo.h"
41 #include "TClassTable.h"
112 static thread_local
bool s_ignoreWarnings =
false;
114 static bool s_ignoreEverything =
false;
116 void RootErrorHandlerImpl(
int level,
char const* location,
char const*
message) {
124 if (level >= kFatal) {
125 el_severity = SeverityLevel::kFatal;
126 }
else if (level >= kSysError) {
127 el_severity = SeverityLevel::kSysError;
128 }
else if (level >=
kError) {
134 if(s_ignoreEverything) {
145 if (message != 0) el_message =
message;
156 size_t index1 = el_message.find(precursor);
157 if (index1 != std::string::npos) {
158 size_t index2 = index1 + precursor.length();
159 size_t index3 = el_message.find_first_of(
" :", index2);
160 if (index3 != std::string::npos) {
161 size_t substrlen = index3-index2;
162 el_identifier +=
"-";
163 el_identifier += el_message.substr(index2,substrlen);
166 index1 = el_location.find(
"::");
167 if (index1 != std::string::npos) {
168 el_identifier +=
"/";
169 el_identifier += el_location.substr(0, index1);
175 if ((el_location.find(
"TBranchElement::Fill") != std::string::npos)
176 && (el_message.find(
"fill branch") != std::string::npos)
177 && (el_message.find(
"address") != std::string::npos)
178 && (el_message.find(
"not set") != std::string::npos)) {
179 el_severity = SeverityLevel::kFatal;
182 if ((el_message.find(
"Tree branches") != std::string::npos)
183 && (el_message.find(
"different numbers of entries") != std::string::npos)) {
184 el_severity = SeverityLevel::kFatal;
190 if ((el_message.find(
"no dictionary for class") != std::string::npos) ||
191 (el_message.find(
"already in TClassTable") != std::string::npos) ||
192 (el_message.find(
"matrix not positive definite") != std::string::npos) ||
193 (el_message.find(
"not a TStreamerInfo object") != std::string::npos) ||
194 (el_message.find(
"Problems declaring payload") != std::string::npos) ||
195 (el_message.find(
"Announced number of args different from the real number of argument passed") != std::string::npos) ||
196 (el_location.find(
"Fit") != std::string::npos) ||
197 (el_location.find(
"TDecompChol::Solve") != std::string::npos) ||
198 (el_location.find(
"THistPainter::PaintInit") != std::string::npos) ||
199 (el_location.find(
"TUnixSystem::SetDisplay") != std::string::npos) ||
200 (el_location.find(
"TGClient::GetFontByName") != std::string::npos) ||
201 (el_message.find(
"nbins is <=0 - set to nbins = 1") != std::string::npos) ||
202 (el_message.find(
"nbinsy is <=0 - set to nbinsy = 1") != std::string::npos) ||
204 (el_location.find(
"CINTTypedefBuilder::Setup")!= std::string::npos) and
205 (el_message.find(
"possible entries are in use!") != std::string::npos))) {
221 if (die && (el_location !=
std::string(
"@SUB=TUnixSystem::DispatchSignals"))) {
222 std::ostringstream sstr;
223 sstr <<
"Fatal Root Error: " << el_location <<
"\n" << el_message <<
'\n';
226 except.clearMessage();
234 if (el_severity == SeverityLevel::kFatal) {
236 }
else if (el_severity == SeverityLevel::kSysError) {
243 edm::LogInfo(
"Root_Information") << el_location << el_message ;
247 void RootErrorHandler(
int level,
bool,
char const* location,
char const* message) {
248 RootErrorHandlerImpl(level, location, message);
253 static int full_write(
int fd,
const char *
text)
255 const char *buffer =
text;
256 size_t count = strlen(text);
260 written =
write(fd, buffer, count);
263 if (errno == EINTR) {
continue;}
264 else {
return -errno;}
272 static int full_read(
int fd,
char *inbuf,
size_t len,
int timeout_s=-1)
276 ssize_t complete = 0;
283 else if ((-1 == (flags = fcntl(fd, F_GETFL))))
289 if (-1 == fcntl(fd, F_SETFL, flags | O_NONBLOCK))
298 struct pollfd poll_info{
fd, POLLIN, 0};
300 if (ms_remaining > 0)
302 if (poll(&poll_info, 1, ms_remaining) == 0)
304 if ((flags & O_NONBLOCK) != O_NONBLOCK)
306 fcntl(fd, F_SETFL, flags);
311 else if (ms_remaining < 0)
313 if ((flags & O_NONBLOCK) != O_NONBLOCK)
315 fcntl(fd, F_SETFL, flags);
320 complete =
read(fd, buf, count);
323 if (errno == EINTR) {
continue;}
324 else if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
continue;}
327 int orig_errno = errno;
328 if ((flags & O_NONBLOCK) != O_NONBLOCK)
330 fcntl(fd, F_SETFL, flags);
338 if ((flags & O_NONBLOCK) != O_NONBLOCK) {
339 fcntl(fd, F_SETFL, flags);
344 static int full_cerr_write(
const char *text)
346 return full_write(2, text);
349 void sig_dostack_then_abort(
int sig, siginfo_t*,
void*) {
351 const char* signalname =
"unknown";
355 signalname =
"bus error";
360 signalname =
"segmentation violation";
365 signalname =
"illegal instruction";
370 signalname =
"external termination request";
376 full_cerr_write(
"\n\nA fatal system signal has occurred: ");
377 full_cerr_write(signalname);
378 full_cerr_write(
"\nThe following is the call stack containing the origin of the signal.\n\n");
382 full_cerr_write(
"\nA fatal system signal has occurred: ");
383 full_cerr_write(signalname);
384 full_cerr_write(
"\n");
388 if ((sig == SIGILL) || (sig == SIGSEGV) || (sig == SIGBUS) || (sig == SIGTERM))
390 signal(sig, SIG_DFL);
399 void sig_abort(
int sig, siginfo_t*,
void*) {
404 void set_default_signals() {
405 signal(SIGILL, SIG_DFL);
406 signal(SIGSEGV, SIG_DFL);
407 signal(SIGBUS, SIG_DFL);
408 signal(SIGTERM, SIG_DFL);
428 char buf[2]; buf[1] =
'\0';
431 int result = full_read(fromParent, buf, 1);
437 set_default_signals();
439 full_cerr_write(
"\n\nTraceback helper thread failed to read from parent: ");
440 full_cerr_write(strerror(-result));
441 full_cerr_write(
"\n");
446 set_default_signals();
448 full_write(toParent, buf);
450 else if (buf[0] ==
'2')
459 else if (buf[0] ==
'3')
465 set_default_signals();
467 full_cerr_write(
"\n\nTraceback helper thread got unknown command from parent: ");
468 full_cerr_write(buf);
469 full_cerr_write(
"\n");
480 full_cerr_write(
"\n\nAttempt to request stacktrace failed: ");
481 full_cerr_write(strerror(-result));
482 full_cerr_write(
"\n");
485 char buf[2]; buf[1] =
'\0';
488 full_cerr_write(
"\n\nWaiting for stacktrace completion failed: ");
489 if (result == -ETIMEDOUT)
491 full_cerr_write(
"timed out waiting for GDB to complete.");
495 full_cerr_write(strerror(-result));
497 full_cerr_write(
"\n");
504 char child_stack[4*1024];
505 char *child_stack_ptr = child_stack + 4*1024;
515 if (child_stack_ptr) {}
520 full_cerr_write(
"(Attempt to perform stack dump failed.)\n");
525 if (waitpid(pid, &status, 0) == -1)
527 full_cerr_write(
"(Failed to wait on stack dump output.)\n");
531 full_cerr_write(
"(GDB stack trace failed unexpectedly)\n");
543 syscall(SYS_execve,
"/bin/sh", argv, __environ);
545 execv(
"/bin/sh", argv);
561 unloadSigHandler_(pset.getUntrackedParameter<bool> (
"UnloadRootSigHandler")),
562 resetErrHandler_(pset.getUntrackedParameter<bool> (
"ResetRootErrHandler")),
563 loadAllDictionaries_(pset.getUntrackedParameter<bool>(
"LoadAllDictionaries")),
564 autoLibraryLoader_(loadAllDictionaries_
or pset.getUntrackedParameter<bool> (
"AutoLibraryLoader"))
569 gSystem->ResetSignal(kSigChild);
570 gSystem->ResetSignal(kSigBus);
571 gSystem->ResetSignal(kSigSegmentationViolation);
572 gSystem->ResetSignal(kSigIllegalInstruction);
573 gSystem->ResetSignal(kSigSystem);
574 gSystem->ResetSignal(kSigPipe);
575 gSystem->ResetSignal(kSigAlarm);
576 gSystem->ResetSignal(kSigUrgent);
577 gSystem->ResetSignal(kSigFloatingException);
578 gSystem->ResetSignal(kSigWindowChanged);
584 gSystem->ResetSignal(kSigBus);
585 gSystem->ResetSignal(kSigSegmentationViolation);
586 gSystem->ResetSignal(kSigIllegalInstruction);
609 SetErrorHandler(RootErrorHandler);
614 gInterpreter->SetClassAutoloading(1);
618 TTree::SetMaxTreeSize(kMaxLong64);
619 TH1::AddDirectory(kFALSE);
626 if (!
hasDictionary(
typeid(std::vector<std::vector<unsigned int> >))) {
638 TIter iter(gROOT->GetListOfFiles());
639 TObject *
obj =
nullptr;
640 while(
nullptr != (obj = iter.Next())) {
641 TFile*
f =
dynamic_cast<TFile*
>(
obj);
646 iter = TIter(gROOT->GetListOfFiles());
653 TThread::Initialize();
655 TObject::SetObjectStat(
false);
658 TVirtualStreamerInfo::Optimize(
false);
662 static thread_local TThread guard;
667 desc.
setComment(
"Centralized interface to ROOT.");
669 ->setComment(
"If True, signals are handled by this service, rather than by ROOT.");
671 ->setComment(
"If True, ROOT messages (e.g. errors, warnings) are handled by this service, rather than by ROOT.");
673 ->setComment(
"If True, enables automatic loading of data dictionaries.");
675 ->setComment(
"If True, loads all ROOT dictionaries.");
677 ->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.");
679 ->setComment(
"Sets ROOT's gDebug value.");
680 descriptions.
add(
"InitRootHandlers", desc);
690 s_ignoreWarnings =
false;
695 s_ignoreWarnings =
true;
704 "set pagination no\n"
705 "thread apply all bt\n"
707 "/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) >=
pidStringLength_)
709 std::ostringstream sstr;
710 sstr <<
"Unable to pre-allocate stacktrace handler information";
727 std::ostringstream sstr;
728 sstr <<
"Failed to create child-to-parent pipes (errno=" << errno <<
"): " << strerror(errno);
737 std::ostringstream sstr;
738 sstr <<
"Failed to create child-to-parent pipes (errno=" << errno <<
"): " << strerror(errno);
T getUntrackedParameter(std::string const &, T const &) const
bool loadAllDictionaries_
virtual void enableWarnings_() override
static void cmssw_stacktrace_fork()
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
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
bool isProcessWideService(TFileService const *)
void setRefCoreStreamer(bool resetAll=false)
std::vector< Variable::Flags > flags
void installCustomHandler(int signum, CFUNC func)
std::shared_ptr< const void > sigSegvHandler_
friend int cmssw_stacktrace(void *)
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_]
edm::serviceregistry::AllArgsMaker< edm::RootHandlers, InitRootHandlers > RootHandlersMaker
static char *const * getPstackArgv()
std::shared_ptr< const void > sigIllHandler_
virtual void initializeThisThreadForUse() override
virtual void ignoreWarnings_() override
static int childToParent_[2]
std::shared_ptr< const void > sigTermHandler_
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 &)