File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ int main(int argc, const char **argv) {
52
52
for (int i = 1 ; i < argc; ++i)
53
53
ss << " " << argv[i];
54
54
std::string cmd = ss.str ();
55
- int result = system (cmd.c_str ());
55
+
56
+ int result = std::system (cmd.c_str ());
56
57
57
58
#ifdef _WIN32
58
59
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
@@ -63,14 +64,23 @@ int main(int argc, const char **argv) {
63
64
result = -3 ;
64
65
#endif
65
66
66
- if (result < 0 ) {
67
+ // On POSIX systems, result is a composite value of the exit status and,
68
+ // potentially, the signal that caused termination of the command.
69
+ int retcode = WEXITSTATUS (result);
70
+ int signal = WTERMSIG (result);
71
+
72
+ // If signal is non-zero, then the command caused a crash, usually SIGABRT.
73
+ if (signal) {
67
74
if (expectCrash)
68
75
return 0 ;
69
76
return 1 ;
70
77
}
71
78
79
+ // The command exited normally, but if we expected a crash, return an error
80
+ // code.
72
81
if (expectCrash)
73
82
return 1 ;
74
83
75
- return result == 0 ;
84
+ // Otherwise, invert the success code.
85
+ return retcode == EXIT_SUCCESS;
76
86
}
You can’t perform that action at this time.
0 commit comments