Skip to content

Commit

Permalink
Refactor to use a program name pointer instead of PACKAGE macro
Browse files Browse the repository at this point in the history
During SEGV handling under pcp-htop several incorrect strings were
observed - in particular reporting htop as the binary name instead
of pcp-htop. This is something we want to be crystal clear on when
we request user stack traces etc, so make sure this cannot be done
incorrectly.
  • Loading branch information
natoscott authored and BenBE committed Apr 5, 2023
1 parent e7f447b commit 14da84f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
20 changes: 12 additions & 8 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ in the source distribution for its full text.
#include <string.h>
#include <unistd.h>

#include "CommandLine.h"
#include "ProvideCurses.h"
#include "XUtils.h"

Expand Down Expand Up @@ -1153,10 +1154,11 @@ void CRT_handleSIGSEGV(int signal) {
"============================\n"
"Please check at https://htop.dev/issues whether this issue has already been reported.\n"
"If no similar issue has been reported before, please create a new issue with the following information:\n"
" - Your "PACKAGE" version: '"VERSION"'\n"
" - Your %s version: '"VERSION"'\n"
" - Your OS and kernel version (uname -a)\n"
" - Your distribution and release (lsb_release -a)\n"
" - Likely steps to reproduce (How did it happen?)\n"
" - Likely steps to reproduce (How did it happen?)\n",
program
);

#ifdef PRINT_BACKTRACE
Expand Down Expand Up @@ -1196,15 +1198,16 @@ void CRT_handleSIGSEGV(int signal) {
fprintf(stderr,
"\n"
"To make the above information more practical to work with, "
"please also provide a disassembly of your "PACKAGE" binary. "
"please also provide a disassembly of your %s binary. "
"This can usually be done by running the following command:\n"
"\n"
"\n",
program
);

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

fprintf(stderr,
Expand All @@ -1216,8 +1219,9 @@ void CRT_handleSIGSEGV(int signal) {
fprintf(stderr,
"Running this program with debug symbols or inside a debugger may provide further insights.\n"
"\n"
"Thank you for helping to improve "PACKAGE"!\n"
"\n"
"Thank you for helping to improve %s!\n"
"\n",
program
);

/* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */
Expand Down
6 changes: 3 additions & 3 deletions CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef struct CommandLineSettings_ {
bool readonly;
} CommandLineSettings;

static CommandLineStatus parseArguments(const char* program, int argc, char** argv, CommandLineSettings* flags) {
static CommandLineStatus parseArguments(int argc, char** argv, CommandLineSettings* flags) {

*flags = (CommandLineSettings) {
.pidMatchList = NULL,
Expand Down Expand Up @@ -298,7 +298,7 @@ static void setCommFilter(State* state, char** commFilter) {
*commFilter = NULL;
}

int CommandLine_run(const char* name, int argc, char** argv) {
int CommandLine_run(int argc, char** argv) {

/* initialize locale */
const char* lc_ctype;
Expand All @@ -310,7 +310,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {
CommandLineStatus status = STATUS_OK;
CommandLineSettings flags = { 0 };

if ((status = parseArguments(name, argc, argv, &flags)) != STATUS_OK)
if ((status = parseArguments(argc, argv, &flags)) != STATUS_OK)
return status != STATUS_OK_EXIT ? 1 : 0;

if (flags.readonly)
Expand Down
4 changes: 3 additions & 1 deletion CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ typedef enum {
STATUS_OK_EXIT
} CommandLineStatus;

int CommandLine_run(const char* name, int argc, char** argv);
extern const char* program;

int CommandLine_run(int argc, char** argv);

#endif
4 changes: 3 additions & 1 deletion htop.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ in the source distribution for its full text.
#include "CommandLine.h"


const char* program = PACKAGE;

int main(int argc, char** argv) {
return CommandLine_run(PACKAGE, argc, argv);
return CommandLine_run(argc, argv);
}
7 changes: 4 additions & 3 deletions pcp-htop.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ in the source distribution for its full text.
#include "Platform.h"


const char* program = "pcp-htop";

int main(int argc, char** argv) {
const char* name = "pcp-htop";
pmSetProgname(name);
pmSetProgname(program);

/* extract environment variables */
opts.flags |= PM_OPTFLAG_ENV_ONLY;
(void)pmGetOptions(argc, argv, &opts);

return CommandLine_run(name, argc, argv);
return CommandLine_run(argc, argv);
}

0 comments on commit 14da84f

Please sign in to comment.