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
+17 -20
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,7 +257,7 @@ 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.
@@ -272,14 +269,14 @@ crashreport_init(int argc UNUSED, char *argv[] UNUSED){
#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
@@ -287,7 +284,7 @@ crashreport_init(int argc UNUSED, char *argv[] UNUSED){
} }
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);
@@ -296,7 +293,7 @@ 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';
@@ -320,7 +317,7 @@ 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
@@ -353,17 +350,17 @@ submit_web_report(const char *msg, char *why){
// 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);
} }
@@ -396,7 +393,7 @@ submit_web_report(const char *msg, char *why){
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));
@@ -406,9 +403,9 @@ submit_web_report(const char *msg, char *why){
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);
@@ -421,7 +418,7 @@ submit_web_report(const char *msg, char *why){
} }
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