summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-04-04 16:47:11 +1000
committerBenBE <BenBE@geshi.org>2023-04-06 00:19:54 +0200
commit14da84f877a0f3627ddaea836c9537b2292fa22d (patch)
treed8eff482c76709187482e41eb36628b5de935078
parente7f447b6a3473a572d3e6c191128f1796477860d (diff)
Refactor to use a program name pointer instead of PACKAGE macro
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.
-rw-r--r--CRT.c20
-rw-r--r--CommandLine.c6
-rw-r--r--CommandLine.h4
-rw-r--r--htop.c4
-rw-r--r--pcp-htop.c7
5 files changed, 25 insertions, 16 deletions
diff --git a/CRT.c b/CRT.c
index 3c062919..50f0c0e8 100644
--- a/CRT.c
+++ b/CRT.c
@@ -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"
@@ -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
@@ -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,
@@ -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) */
diff --git a/CommandLine.c b/CommandLine.c
index 83359206..2b2a68c2 100644
--- a/CommandLine.c
+++ b/CommandLine.c
@@ -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,
@@ -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;
@@ -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)
diff --git a/CommandLine.h b/CommandLine.h
index fbdede84..18395005 100644
--- a/CommandLine.h
+++ b/CommandLine.h
@@ -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
diff --git a/htop.c b/htop.c
index 6b9ea48a..71557938 100644
--- a/htop.c
+++ b/htop.c
@@ -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);
}
diff --git a/pcp-htop.c b/pcp-htop.c
index 2713c896..ed585ecb 100644
--- a/pcp-htop.c
+++ b/pcp-htop.c
@@ -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);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy