CRASHREPORT cleanup

make deprecation warning suppression unconditional
formatting/whitespace
This commit is contained in:
nhkeni
2023-09-07 20:55:07 -04:00
parent b75bc87662
commit 33d85bfe08
+100 -103
View File
@@ -224,10 +224,12 @@ NH_abort(char *why)
#ifdef CRASHREPORT #ifdef CRASHREPORT
# include <fcntl.h> # include <fcntl.h>
# define HASH_PRAGMA_START \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
# define HASH_PRAGMA_END _Pragma("GCC diagnostic pop");
# ifdef MACOS # ifdef MACOS
# include <CommonCrypto/CommonDigest.h> # include <CommonCrypto/CommonDigest.h>
# define HASH_PRAGMA_START
# define HASH_PRAGMA_END
# define HASH_CONTEXT CC_MD4_CTX # define HASH_CONTEXT CC_MD4_CTX
# define HASH_INIT(ctx) CC_MD4_Init(ctx) # define HASH_INIT(ctx) CC_MD4_Init(ctx)
# define HASH_UPDATE(ctx, ptr, len) CC_MD4_Update(ctx, ptr, len) # define HASH_UPDATE(ctx, ptr, len) CC_MD4_Update(ctx, ptr, len)
@@ -236,16 +238,11 @@ NH_abort(char *why)
# endif # endif
# ifdef __linux__ # ifdef __linux__
# include <openssl/md4.h> # include <openssl/md4.h>
# define HASH_PRAGMA_START \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
# define HASH_PRAGMA_END _Pragma("GCC diagnostic pop");
# define HASH_CONTEXT MD4_CTX # define HASH_CONTEXT MD4_CTX
# define HASH_INIT(ctx) MD4_Init(ctx) # define HASH_INIT(ctx) MD4_Init(ctx)
# define HASH_UPDATE(ctx, ptr, len) MD4_Update(ctx, ptr, len) # define HASH_UPDATE(ctx, ptr, len) MD4_Update(ctx, ptr, len)
# define HASH_FINISH(ctx, out) MD4_Final(out, ctx) # define HASH_FINISH(ctx, out) MD4_Final(out, ctx)
# define HASH_RESULT_SIZE MD4_DIGEST_LENGTH # define HASH_RESULT_SIZE MD4_DIGEST_LENGTH
# endif # endif
// Binary ID - Use only as a hint to contact.html for recognizing our own // Binary ID - Use only as a hint to contact.html for recognizing our own
// binaries. This is easily spoofed! // binaries. This is easily spoofed!
@@ -260,35 +257,35 @@ crashreport_init(int argc UNUSED, char *argv[] UNUSED){
HASH_INIT(&ctx); HASH_INIT(&ctx);
#ifdef MACOS #ifdef MACOS
char *binfile = argv[0]; char *binfile = argv[0];
if(!binfile || !*binfile){ if (!binfile || !*binfile) {
# ifdef BETA # ifdef BETA
// If this triggers, investigate CFBundleGetMainBundle // If this triggers, investigate CFBundleGetMainBundle
// or CFBundleCopyExecutableURL. // or CFBundleCopyExecutableURL.
raw_print("BETA warning: crashreport_init called without useful info"); raw_print("BETA warning: crashreport_init called without useful info");
# endif # endif
goto skip; goto skip;
} }
#endif #endif
#ifdef __linux__ #ifdef __linux__
char binfile[PATH_MAX+1]; char binfile[PATH_MAX+1];
int len = readlink("/proc/self/exe", binfile, sizeof(binfile)-1); int len = readlink("/proc/self/exe", binfile, sizeof(binfile)-1);
if(len>0) { if (len>0) {
binfile[len] = '\0'; binfile[len] = '\0';
} else { } else {
goto skip; goto skip;
} }
#endif #endif
int fd = open(binfile, O_RDONLY, 0); int fd = open(binfile, O_RDONLY, 0);
if(fd == -1) { if (fd == -1) {
# ifdef BETA # ifdef BETA
raw_printf("open e=%s",strerror(errno)); raw_printf("open e=%s",strerror(errno));
# endif # endif
goto skip; goto skip;
} }
int segsize; int segsize;
char segment[4096]; char segment[4096];
while(0 < (segsize = read(fd, segment,sizeof(segment)))){ while (0 < (segsize = read(fd, segment,sizeof(segment)))) {
HASH_UPDATE(&ctx, segment, segsize); HASH_UPDATE(&ctx, segment, segsize);
} }
HASH_FINISH(&ctx, tmp); HASH_FINISH(&ctx, tmp);
close(fd); close(fd);
@@ -296,8 +293,8 @@ crashreport_init(int argc UNUSED, char *argv[] UNUSED){
char *p = bid; char *p = bid;
unsigned char *in = &tmp[0]; unsigned char *in = &tmp[0];
char cnt=HASH_RESULT_SIZE; char cnt=HASH_RESULT_SIZE;
while(cnt--){ while (cnt--) {
p += snprintf(p, HASH_RESULT_SIZE-(p-bid), "%02x",*(in++)); p += snprintf(p, HASH_RESULT_SIZE-(p-bid), "%02x",*(in++));
} }
*p = '\0'; *p = '\0';
return; return;
@@ -320,108 +317,108 @@ crashreport_bidshow(void){
boolean boolean
submit_web_report(const char *msg, char *why){ submit_web_report(const char *msg, char *why){
if(sysopt.crashreporturl){ if (sysopt.crashreporturl) {
const char *xargv[SWR_LINES]; const char *xargv[SWR_LINES];
char version[100]; char version[100];
char versionstring[200]; // used twice as a temp char versionstring[200]; // used twice as a temp
int xargc = 0; int xargc = 0;
char wholetrace[SWR_LINES*80]; // XXX roughly 71 on MacOS, plus buffer char wholetrace[SWR_LINES*80]; // XXX roughly 71 on MacOS, plus buffer
int prelines = 0; // count of lines in trace header int prelines = 0; // count of lines in trace header
char nbuf[6]; // number buffer char nbuf[6]; // number buffer
extern char **environ; extern char **environ;
pid_t pid; pid_t pid;
SWR_ADD(CRASHREPORT); SWR_ADD(CRASHREPORT);
SWR_ADD(sysopt.crashreporturl); SWR_ADD(sysopt.crashreporturl);
// then pairs of key value // then pairs of key value
// subject, generate something useful // subject, generate something useful
SWR_ADD("subject"); SWR_ADD("subject");
snprintf(version, sizeof(version), "%s report for NetHack %s", snprintf(version, sizeof(version), "%s report for NetHack %s",
msg, version_string(versionstring, sizeof(versionstring))); msg, version_string(versionstring, sizeof(versionstring)));
SWR_ADD(version); SWR_ADD(version);
// name: someday, this might be stored in nethackcnf // name: someday, this might be stored in nethackcnf
// email: someday, this might be stored in nethackcnf // email: someday, this might be stored in nethackcnf
// gitver, pull from version.c // gitver, pull from version.c
SWR_ADD("gitver"); SWR_ADD("gitver");
SWR_ADD(getversionstring(versionstring, sizeof(versionstring))); SWR_ADD(getversionstring(versionstring, sizeof(versionstring)));
// hardware: leave for user // hardware: leave for user
// software: leave for user // software: leave for user
// comments: leave for user // comments: leave for user
// details: stack trace // details: stack trace
SWR_ADD("details"); SWR_ADD("details");
// XXX header for wholetrace - what other info do we want? // XXX header for wholetrace - what other info do we want?
// NB: prelines not tested against size of SWR_FRAMES. // NB: prelines not tested against size of SWR_FRAMES.
#define SWR_HDR(line) \ #define SWR_HDR(line) \
if(endp<&wholetrace[sizeof(wholetrace)]){ \ if (endp<&wholetrace[sizeof(wholetrace)]) { \
endp+=snprintf(endp, sizeof(wholetrace)-(endp-wholetrace), "%s\n",line); \ endp+=snprintf(endp, sizeof(wholetrace)-(endp-wholetrace), "%s\n",line); \
prelines++; \ prelines++; \
} }
#define SWR_HDRnonl(line) \ #define SWR_HDRnonl(line) \
if(endp<&wholetrace[sizeof(wholetrace)]){ \ if (endp<&wholetrace[sizeof(wholetrace)]) { \
endp+=snprintf(endp, sizeof(wholetrace)-(endp-wholetrace), "%s",line); \ endp+=snprintf(endp, sizeof(wholetrace)-(endp-wholetrace), "%s",line); \
} }
char *endp = wholetrace; char *endp = wholetrace;
wholetrace[0] = 0; wholetrace[0] = 0;
if(why){ if (why) {
SWR_HDR(why); SWR_HDR(why);
} }
SWR_HDRnonl("bid: "); SWR_HDRnonl("bid: ");
SWR_HDR(bid); SWR_HDR(bid);
void *bt[SWR_FRAMES]; void *bt[SWR_FRAMES];
int count, x; int count, x;
char **info, buf[BUFSZ]; char **info, buf[BUFSZ];
count = backtrace(bt, SIZE(bt)); count = backtrace(bt, SIZE(bt));
info = backtrace_symbols(bt, count); info = backtrace_symbols(bt, count);
for (x = 0; x < count; x++) { for (x = 0; x < count; x++) {
copynchars(buf, info[x], (int) sizeof buf - 1); copynchars(buf, info[x], (int) sizeof buf - 1);
/* try to remove up to 16 blank spaces by removing 8 twice */ /* try to remove up to 16 blank spaces by removing 8 twice */
(void) strsubst(buf, " ", ""); (void) strsubst(buf, " ", "");
(void) strsubst(buf, " ", ""); (void) strsubst(buf, " ", "");
snprintf(endp, SWR_FRAMES*80-(endp-wholetrace), "[%02lu] %s\n", snprintf(endp, SWR_FRAMES*80-(endp-wholetrace), "[%02lu] %s\n",
(unsigned long) x, buf); (unsigned long) x, buf);
endp = eos(endp); endp = eos(endp);
} }
*(endp-1) = '\0'; // remove last newline *(endp-1) = '\0'; // remove last newline
SWR_ADD(wholetrace); SWR_ADD(wholetrace);
// detailrows min(actual,50) Guess since we can't know the // detailrows min(actual,50) Guess since we can't know the
// width of the window. // width of the window.
SWR_ADD("detailrows"); SWR_ADD("detailrows");
(void)snprintf(nbuf,sizeof(nbuf),"%d",count+prelines); (void)snprintf(nbuf,sizeof(nbuf),"%d",count+prelines);
SWR_ADD(nbuf); SWR_ADD(nbuf);
xargv[xargc++] = 0; // terminate array xargv[xargc++] = 0; // terminate array
pid = fork(); pid = fork();
if( pid == 0 ){ if (pid == 0) {
execve(CRASHREPORT, (char * const *)xargv, environ); execve(CRASHREPORT, (char * const *)xargv, environ);
char err[100]; char err[100];
sprintf(err, "Can't start " CRASHREPORT ": %s", strerror(errno)); sprintf(err, "Can't start " CRASHREPORT ": %s", strerror(errno));
raw_print(err); raw_print(err);
} else { } else {
int status; int status;
errno=0; errno=0;
// XXX do we _really_ know this is the right pid? // XXX do we _really_ know this is the right pid?
(void)waitpid(pid, &status, 0); (void)waitpid(pid, &status, 0);
if(status){ // XXX check could be more precise if (status) { // XXX check could be more precise
#if 0 #if 0
// Not useful at the moment. XXX // Not useful at the moment. XXX
char err[100]; char err[100];
sprintf(err, "pid=%d e=%d status=%0x",wpid,errno,status); sprintf(err, "pid=%d e=%d status=%0x",wpid,errno,status);
raw_print(err); raw_print(err);
#endif #endif
return FALSE; return FALSE;
} }
} }
/* free(info); -- Don't risk it. */ /* free(info); -- Don't risk it. */
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
#endif // CRASHREPORT #endif /* CRASHREPORT */
#undef SWR_ADD #undef SWR_ADD
#undef SWR_FRAMES #undef SWR_FRAMES
#undef SWR_HDR #undef SWR_HDR