Macro exit code

I noticed that, when I run a macro like this:

root -b -l -q macro.C+

if the macro has a segmentation violation, ROOT still quits normally and then the exit code is 0.

Is there some way to get the non-zero exit code from the macro crashing to pass through to the shell so it can be checked by a script later?

Hi,

Can’t reproduce.

macro.C:

void macro() {
   TObject* o = (TObject*) 0x123;
   o->GetName();
}

Running it:

$ root.exe -l -b -q macro.C+; echo $?
root [0] 
Processing macro.C+...
Info in <TUnixSystem::ACLiC>: creating shared library /home/axel/build/root/github/obj/./macro_C.so

 *** Break *** segmentation violation



===========================================================
There was a crash (kSigSegmentationViolation).
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f6b3bf23b4c in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f6b3bea92e2 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007f6b3cf7f1b9 in TUnixSystem::Exec (this=0x1ff3aa0, shellcmd=0x33095d0 "/home/axel/build/root/github/obj/etc/gdb-backtrace.sh 4032 1>&2") at /home/axel/build/root/github/src/core/unix/src/TUnixSystem.cxx:2073
#3  0x00007f6b3cf7fd7b in TUnixSystem::StackTrace (this=0x1ff3aa0) at /home/axel/build/root/github/src/core/unix/src/TUnixSystem.cxx:2301
#4  0x00007f6b3cf8588a in TUnixSystem::DispatchSignals (this=0x1ff3aa0, sig=kSigSegmentationViolation) at /home/axel/build/root/github/src/core/unix/src/TUnixSystem.cxx:3539
#5  0x00007f6b3cf7a2f1 in SigHandler (sig=kSigSegmentationViolation) at /home/axel/build/root/github/src/core/unix/src/TUnixSystem.cxx:395
#6  0x00007f6b3cf85a14 in sighandler (sig=11) at /home/axel/build/root/github/src/core/unix/src/TUnixSystem.cxx:3516
#7  0x00007f6b3cfca150 in textinput::TerminalConfigUnix::HandleSignal (this=0x7f6b3d324aa0 <textinput::TerminalConfigUnix::Get()::s>, signum=11) at /home/axel/build/root/github/src/core/textinput/src/textinput/TerminalConfigUnix.cpp:96
#8  0x00007f6b3cfc9f5b in (anonymous namespace)::TerminalConfigUnix__handleSignal (signum=11) at /home/axel/build/root/github/src/core/textinput/src/textinput/TerminalConfigUnix.cpp:36
#9  <signal handler called>
#10 0x00007f6b2ce585f7 in macro () at /home/axel/build/root/github/obj/./macro.C:3
#11 0x00007f6b3d3f5042 in ?? ()
#12 0x0000000000000015 in ?? ()
#13 0x00007fffe404d730 in ?? ()
#14 0x00007fffe404ce70 in ?? ()
#15 0x00007f6b36f49ae2 in cling::IncrementalExecutor::executeWrapper (this=0x7fffe404cdc0, function=..., returnValue=0x123) at /home/axel/build/root/github/src/interpreter/cling/lib/Interpreter/IncrementalExecutor.h:186
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#10 0x00007f6b2ce585f7 in macro () at /home/axel/build/root/github/obj/./macro.C:3
#11 0x00007f6b3d3f5042 in ?? ()
#12 0x0000000000000015 in ?? ()
#13 0x00007fffe404d730 in ?? ()
#14 0x00007fffe404ce70 in ?? ()
#15 0x00007f6b36f49ae2 in cling::IncrementalExecutor::executeWrapper (this=0x7fffe404cdc0, function=..., returnValue=0x123) at /home/axel/build/root/github/src/interpreter/cling/lib/Interpreter/IncrementalExecutor.h:186
===========================================================


Root > 1

So the exit code is 1.

That’s with the current master.

Cheers, Axel.

I was trying this in version 5.34.18. I also tried in 6.02.00 and 6.02.12. In all versions, it gives exit code 0.

Maybe this was fixed fairly recently?

Actually, the returned value 1 seems wrong to me -> for a “segmentation violation” (“SIGSEGV”) I would expect to get 139 (= 128 + 11).
In general, I would expect that if the command is terminated by signal “n” (e.g. “SIGSEGV” is 11 according to “man 7 signal”) then the exit status should be “128 + n”,

Hi,

Good point - I think we are simply registering that we have caught a signal… It’s now sft.its.cern.ch/jira/browse/ROOT-7660

Axel.

Do you know which is the first version of ROOT where it catches the signal at all? As I reported, I tested it up to 6.02.12 and still got exit code 0.

Hi,

And indeed - this is not part of 6.02:

$ git tag --contains 9f243121
v6-03-01-GEANT
v6-03-02
v6-03-04
v6-04-00
v6-04-02
v6-05-01

Cheers, Axel.

Note also that ROOT 5 seems to return 0 in all cases, too.

Hi,

Yes, long overdue, I agree… But we fixed it at last!

Cheers, Axel.

…and the exit code for signals is finally fixed.

Axel.