Skip to content

Commit 027d0c7

Browse files
committed
TraceScreen print errno when exec fails
1 parent 2a31455 commit 027d0c7

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

TraceScreen.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
7777
#else
7878
TraceScreen_programLauncher.lastErrno = ENOSYS;
7979
#endif
80-
if (TraceScreen_programLauncher.lastErrno != 0)
81-
return false;
8280

8381
int fdpair[2] = {-1, -1};
8482

@@ -114,9 +112,14 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
114112
buffer,
115113
NULL
116114
};
117-
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
115+
if (TraceScreen_programLauncher.lastErrno == 0) {
116+
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
117+
} else {
118+
errno = TraceScreen_programLauncher.lastErrno;
119+
}
118120

119121
// Should never reach here, unless execlp fails ...
122+
fprintf(stderr, "Could not execute 'truss': %s\n", strerror(errno));
120123
const char* message = "Could not execute 'truss'. Please make sure it is available in your $PATH.";
121124
(void)! write(STDERR_FILENO, message, strlen(message));
122125
#elif defined(HTOP_LINUX)
@@ -130,9 +133,14 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
130133
buffer,
131134
NULL
132135
};
133-
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
136+
if (TraceScreen_programLauncher.lastErrno == 0) {
137+
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
138+
} else {
139+
errno = TraceScreen_programLauncher.lastErrno;
140+
}
134141

135142
// Should never reach here, unless execlp fails ...
143+
fprintf(stderr, "Could not execute 'strace': %s\n", strerror(errno));
136144
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
137145
(void)! write(STDERR_FILENO, message, strlen(message));
138146
#else // HTOP_DARWIN, HTOP_PCP == HTOP_UNSUPPORTED

0 commit comments

Comments
 (0)