Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "Action.h"

#include <assert.h>
#include <errno.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdlib.h>
Expand Down Expand Up @@ -675,9 +676,13 @@ static Htop_Reaction actionStrace(State* st) {

TraceScreen* ts = TraceScreen_new(p);
bool ok = TraceScreen_forkTracer(ts);
if (ok) {
InfoScreen_run((InfoScreen*)ts);
if (!ok) {
char errmsg[256];
int saved_errno = errno;
snprintf(errmsg, sizeof(errmsg), "Failed to start tracer: %s", strerror(saved_errno));
InfoScreen_addLine(&ts->super, errmsg);
}
InfoScreen_run((InfoScreen*)ts);
TraceScreen_delete((Object*)ts);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
clear();
CRT_enableDelay();
Expand Down
18 changes: 12 additions & 6 deletions TraceScreen.c
Comment thread
re2zero marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,27 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
return true;

err:
close(fdpair[1]);
close(fdpair[0]);
{
int saved_errno = errno;
close(fdpair[1]);
close(fdpair[0]);
errno = saved_errno;
}
return false;
}

static void TraceScreen_updateTrace(InfoScreen* super) {
TraceScreen* this = (TraceScreen*) super;

int fd_strace = fileno(this->strace);
int fd_strace = -1;
if (this->strace) {
fd_strace = fileno(this->strace);
}

fd_set fds;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
if (this->strace_alive) {
assert(fd_strace != -1);
if (this->strace_alive && fd_strace >= 0) {
FD_SET(fd_strace, &fds);
}

Expand All @@ -150,7 +156,7 @@ static void TraceScreen_updateTrace(InfoScreen* super) {

char buffer[1025];
size_t nread = 0;
if (ready > 0 && FD_ISSET(fd_strace, &fds))
if (fd_strace >= 0 && ready > 0 && FD_ISSET(fd_strace, &fds))
nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace);

if (nread && this->tracing) {
Expand Down
Loading