Skip to content

Commit

Permalink
Merge branch 'htop-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex313031 authored Apr 17, 2024
2 parents 5bab2d3 + 7017b86 commit 04c2000
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 159 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
release: '6.4.0'
usesh: true
prepare: |
pkg install -y gmake autoconf-2.71 automake ncurses git
pkg install -y gmake autoconf automake ncurses git
git config --global --add safe.directory /home/runner/work/htop/htop
run: |
set -e
Expand All @@ -233,7 +233,7 @@ jobs:
release: '14.0'
usesh: true
prepare: |
pkg install -y gmake autoconf-2.71 automake git
pkg install -y gmake autoconf automake git
git config --global --add safe.directory /home/runner/work/htop/htop
run: |
set -e
Expand Down Expand Up @@ -279,12 +279,24 @@ jobs:
release: '7.4'
usesh: true
prepare: |
pkg_add gmake autoconf-2.71 automake-1.16.5 git
pkg_add gmake git
git config --global --add safe.directory /home/runner/work/htop/htop
run: |
set -e
export AUTOCONF_VERSION=2.71
export AUTOMAKE_VERSION=1.16
autoconf_version_full=$(pkg_info -Q autoconf |
LC_ALL=C sed 's/^autoconf-\([0-9]*\.[0-9]*\)\(p[.0-9]*\)\{0,1\}$/\1\2/p; d' |
LC_ALL=C sort -n -r -t . -k 1,1 -k 2,2 |
sed '1 q')
automake_version_full=$(pkg_info -Q automake |
LC_ALL=C sed 's/^automake-\([0-9]*\.[0-9]*\)\(\.[0-9]*\)\{0,1\}\(p[0-9]*\)\{0,1\}$/\1\2\3/p; d' |
LC_ALL=C sort -n -r -t . -k 1,1 -k 2,2 -k 3,3 |
sed '1 q')
pkg_add -v autoconf-${autoconf_version_full} automake-${automake_version_full}
export AUTOCONF_VERSION=$(echo ${autoconf_version_full} |
LC_ALL=C sed 's/^\([0-9]*\.[0-9]*\).*$/\1/')
# Must not include the third version field in $AUTOMAKE_VERSION
export AUTOMAKE_VERSION=$(echo ${automake_version_full} |
LC_ALL=C sed 's/^\([0-9]*\.[0-9]*\).*$/\1/')
./autogen.sh
./configure --enable-unicode --enable-werror
gmake -k
Expand Down
48 changes: 30 additions & 18 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,11 @@ static void CRT_handleSIGTERM(int sgn) {
if (!signal_str)
signal_str = "unknown reason";

fprintf(stderr,
char err_buf[512];
snprintf(err_buf, sizeof(err_buf),
"A signal %d (%s) was received, exiting without persisting settings to htoprc.\n",
sgn, signal_str);
full_write_str(STDERR_FILENO, err_buf);
_exit(0);
}

Expand Down Expand Up @@ -912,15 +914,15 @@ static void dumpStderr(void) {

if (res > 0) {
if (!header) {
fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n");
full_write_str(STDERR_FILENO, ">>>>>>>>>> stderr output >>>>>>>>>>\n");
header = true;
}
full_write(STDERR_FILENO, buffer, res);
}
}

if (header)
fprintf(stderr, "\n<<<<<<<<<< stderr output <<<<<<<<<<\n");
full_write_str(STDERR_FILENO, "\n<<<<<<<<<< stderr output <<<<<<<<<<\n");

close(stderrRedirectNewFd);
stderrRedirectNewFd = -1;
Expand Down Expand Up @@ -1185,6 +1187,8 @@ static void print_backtrace(void) {

unsigned int item = 0;

char err_buf[1024];

while (unw_step(&cursor) > 0) {
unw_word_t pc;
unw_get_reg(&cursor, UNW_REG_IP, &pc);
Expand Down Expand Up @@ -1213,7 +1217,8 @@ static void print_backtrace(void) {
const bool is_signal_frame = unw_is_signal_frame(&cursor) > 0;
const char* frame = is_signal_frame ? " {signal frame}" : "";

fprintf(stderr, "%2u: %#14lx %s (%s+%#lx) [%p]%s\n", item++, pc, fname, symbolName, offset, ptr, frame);
snprintf(err_buf, sizeof(err_buf), "%2u: %#14lx %s (%s+%#lx) [%p]%s\n", item++, pc, fname, symbolName, offset, ptr, frame);
full_write_str(STDERR_FILENO, err_buf);
}
#elif defined(HAVE_EXECINFO_H)
void* backtraceArray[256];
Expand All @@ -1229,7 +1234,9 @@ static void print_backtrace(void) {
void CRT_handleSIGSEGV(int signal) {
CRT_done();

fprintf(stderr, "\n\n"
char err_buf[512];

snprintf(err_buf, sizeof(err_buf), "\n\n"
"FATAL PROGRAM ERROR DETECTED\n"
"============================\n"
"Please check at https://htop.dev/issues whether this issue has already been reported.\n"
Expand All @@ -1240,74 +1247,79 @@ void CRT_handleSIGSEGV(int signal) {
" - Likely steps to reproduce (How did it happen?)\n",
program
);
full_write_str(STDERR_FILENO, err_buf);

#ifdef PRINT_BACKTRACE
fprintf(stderr, " - Backtrace of the issue (see below)\n");
full_write_str(STDERR_FILENO, " - Backtrace of the issue (see below)\n");
#endif

fprintf(stderr,
full_write_str(STDERR_FILENO,
"\n"
);

const char* signal_str = strsignal(signal);
if (!signal_str) {
signal_str = "unknown reason";
}
fprintf(stderr,
snprintf(err_buf, sizeof(err_buf),
"Error information:\n"
"------------------\n"
"A signal %d (%s) was received.\n"
"\n",
signal, signal_str
);
full_write_str(STDERR_FILENO, err_buf);

fprintf(stderr,
full_write_str(STDERR_FILENO,
"Setting information:\n"
"--------------------\n");
Settings_write(CRT_crashSettings, true);
fprintf(stderr, "\n\n");
full_write_str(STDERR_FILENO, "\n\n");

#ifdef PRINT_BACKTRACE
fprintf(stderr,
full_write_str(STDERR_FILENO,
"Backtrace information:\n"
"----------------------\n"
);

print_backtrace();

fprintf(stderr,
snprintf(err_buf, sizeof(err_buf),
"\n"
"To make the above information more practical to work with, "
"please also provide a disassembly of your %s binary. "
"This can usually be done by running the following command:\n"
"\n",
program
);
full_write_str(STDERR_FILENO, err_buf);

#ifdef HTOP_DARWIN
fprintf(stderr, " otool -tvV `which %s` > ~/%s.otool\n", program, program);
snprintf(err_buf, sizeof(err_buf), " otool -tvV `which %s` > ~/%s.otool\n", program, program);
#else
fprintf(stderr, " objdump -d -S -w `which %s` > ~/%s.objdump\n", program, program);
snprintf(err_buf, sizeof(err_buf), " objdump -d -S -w `which %s` > ~/%s.objdump\n", program, program);
#endif
full_write_str(STDERR_FILENO, err_buf);

fprintf(stderr,
full_write_str(STDERR_FILENO,
"\n"
"Please include the generated file in your report.\n"
);
#endif

fprintf(stderr,
snprintf(err_buf, sizeof(err_buf),
"Running this program with debug symbols or inside a debugger may provide further insights.\n"
"\n"
"Thank you for helping to improve %s!\n"
"\n",
program
);
full_write_str(STDERR_FILENO, err_buf);

/* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */
if (sigaction(signal, &old_sig_handler[signal], NULL) < 0) {
/* This avoids an infinite loop in case the handler could not be reset. */
fprintf(stderr,
full_write_str(STDERR_FILENO,
"!!! Chained handler could not be restored. Forcing exit.\n"
);
_exit(1);
Expand All @@ -1317,7 +1329,7 @@ void CRT_handleSIGSEGV(int signal) {
raise(signal);

// Always terminate, even if installed handler returns
fprintf(stderr,
full_write_str(STDERR_FILENO,
"!!! Chained handler did not exit. Forcing exit.\n"
);
_exit(1);
Expand Down
6 changes: 3 additions & 3 deletions Compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ int Compat_faccessat(int dirfd,
}

// Fallback to stat(2)/lstat(2) depending on flags
struct stat statinfo;
struct stat sb;
if (flags) {
ret = lstat(pathname, &statinfo);
ret = lstat(pathname, &sb);
} else {
ret = stat(pathname, &statinfo);
ret = stat(pathname, &sb);
}

return ret;
Expand Down
2 changes: 2 additions & 0 deletions HeaderLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in the source distribution for its full text.

typedef enum HeaderLayout_ {
HF_INVALID = -1,
HF_ONE_100,
HF_TWO_50_50,
HF_TWO_33_67,
HF_TWO_67_33,
Expand All @@ -38,6 +39,7 @@ static const struct {
const char* name;
const char* description;
} HeaderLayout_layouts[LAST_HEADER_LAYOUT] = {
[HF_ONE_100] = { 1, { 100, 0, 0, 0 }, "one_100", "1 column - full width", },
[HF_TWO_50_50] = { 2, { 50, 50, 0, 0 }, "two_50_50", "2 columns - 50/50 (default)", },
[HF_TWO_33_67] = { 2, { 33, 67, 0, 0 }, "two_33_67", "2 columns - 33/67", },
[HF_TWO_67_33] = { 2, { 67, 33, 0, 0 }, "two_67_33", "2 columns - 67/33", },
Expand Down
8 changes: 7 additions & 1 deletion Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
static const char BarMeterMode_characters[] = "|#*@$%&.";

static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// Draw the caption
const char* caption = Meter_getCaption(this);
attrset(CRT_colors[METER_TEXT]);
int captionLen = 3;
mvaddnstr(y, x, caption, captionLen);
x += captionLen;
w -= captionLen;

// Draw the bar borders
attrset(CRT_colors[BAR_BORDER]);
mvaddch(y, x, '[');
w--;
Expand All @@ -199,14 +202,16 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {

x++;

if (w < 1)
if (w < 1) {
return;
}

// The text in the bar is right aligned;
// Pad with maximal spaces and then calculate needed starting position offset
RichString_begin(bar);
RichString_appendChr(&bar, 0, ' ', w);
RichString_appendWide(&bar, 0, this->txtBuffer);

int startPos = RichString_sizeVal(bar) - w;
if (startPos > w) {
// Text is too large for bar
Expand All @@ -223,6 +228,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// If still too large, print the start not the end
startPos = MINIMUM(startPos, w);
}

assert(startPos >= 0);
assert(startPos <= w);
assert(startPos + w <= RichString_sizeVal(bar));
Expand Down
14 changes: 7 additions & 7 deletions OpenFilesScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
OpenFiles_FileData* fdata = NULL;
bool lsofIncludesFileSize = false;

FILE* fd = fdopen(fdpair[0], "r");
if (!fd) {
FILE* fp = fdopen(fdpair[0], "r");
if (!fp) {
pdata->error = 1;
return pdata;
}
for (;;) {
char* line = String_readLine(fd);
char* line = String_readLine(fp);
if (!line) {
break;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {

free(line);
}
fclose(fd);
fclose(fp);

int wstatus;
while (waitpid(child, &wstatus, 0) == -1)
Expand All @@ -238,10 +238,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
item = &fdata->data;
const char* filename = getDataForType(item, 'n');

struct stat st;
if (stat(filename, &st) == 0) {
struct stat sb;
if (stat(filename, &sb) == 0) {
char fileSizeBuf[21]; /* 20 (long long) + 1 (NULL) */
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, (uint64_t)st.st_size); /* st.st_size is long long on macOS, long on linux */
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, (uint64_t)sb.st_size); /* sb.st_size is long long on macOS, long on linux */
free_and_xStrdup(&item->data[fileSizeIndex], fileSizeBuf);
}
}
Expand Down
Loading

0 comments on commit 04c2000

Please sign in to comment.