Skip to content

Commit b69d43d

Browse files
committed
TraceScreen use ProgramLauncher to launch trace program
1 parent 9aa4e70 commit b69d43d

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

TraceScreen.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ in the source distribution for its full text.
2424
#include "CRT.h"
2525
#include "FunctionBar.h"
2626
#include "Panel.h"
27+
#include "ProgramLauncher.h"
2728
#include "ProvideCurses.h"
2829
#include "XUtils.h"
2930

@@ -34,6 +35,8 @@ static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"};
3435

3536
static const int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
3637

38+
static ProgramLauncher TraceScreen_programLauncher;
39+
3740
TraceScreen* TraceScreen_new(const Process* process) {
3841
// This initializes all TraceScreen variables to "false" so only default = true ones need to be set below
3942
TraceScreen* this = xCalloc(1, sizeof(TraceScreen));
@@ -67,6 +70,16 @@ static void TraceScreen_draw(InfoScreen* this) {
6770
}
6871

6972
bool TraceScreen_forkTracer(TraceScreen* this) {
73+
#if defined(HTOP_FREEBSD) || defined(HTOP_OPENBSD) || defined(HTOP_NETBSD) || defined(HTOP_DRAGONFLYBSD) || defined(HTOP_SOLARIS)
74+
ProgramLauncher_setPath(&TraceScreen_programLauncher, "truss");
75+
#elif defined(HTOP_LINUX)
76+
ProgramLauncher_setPath(&TraceScreen_programLauncher, "strace");
77+
#else
78+
TraceScreen_programLauncher.lastErrno = ENOSYS;
79+
#endif
80+
if (TraceScreen_programLauncher.lastErrno != 0)
81+
return false;
82+
7083
int fdpair[2] = {-1, -1};
7184

7285
if (pipe(fdpair) < 0)
@@ -93,15 +106,31 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
93106
xSnprintf(buffer, sizeof(buffer), "%d", Process_getPid(this->super.process));
94107

95108
#if defined(HTOP_FREEBSD) || defined(HTOP_OPENBSD) || defined(HTOP_NETBSD) || defined(HTOP_DRAGONFLYBSD) || defined(HTOP_SOLARIS)
96-
// Use of NULL in variadic functions must have a pointer cast.
97-
// The NULL constant is not required by standard to have a pointer type.
98-
execlp("truss", "truss", "-s", "512", "-p", buffer, (void*)NULL);
109+
const char* argv[] = {
110+
"truss",
111+
"-s",
112+
"512",
113+
"-p",
114+
buffer,
115+
NULL
116+
};
117+
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
99118

100119
// Should never reach here, unless execlp fails ...
101120
const char* message = "Could not execute 'truss'. Please make sure it is available in your $PATH.";
102121
(void)! write(STDERR_FILENO, message, strlen(message));
103122
#elif defined(HTOP_LINUX)
104-
execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, (void*)NULL);
123+
const char* argv[] = {
124+
"strace",
125+
"-T",
126+
"-tt",
127+
"-s",
128+
"512",
129+
"-p",
130+
buffer,
131+
NULL
132+
};
133+
ProgramLauncher_execv_const(&TraceScreen_programLauncher, argv);
105134

106135
// Should never reach here, unless execlp fails ...
107136
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";

0 commit comments

Comments
 (0)