libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit 82ed9e083e931af3004c10f24da26a873ed41e33
parent d0cff7fa66da3f1a5ff618e9e5254ad95fa65900
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sun, 23 Aug 2020 12:57:46 +0200

print all error messages with pLog (libsheepy log system)

release/libsheepy.c |  2 +-
release/libsheepy.h | 19 +++++++++++++------
src/libsheepy.c     |  2 +-
src/libsheepy.h     | 19 +++++++++++++------
src/tpool.c         |  3 +--
5 files changed, 29 insertions(+), 16 deletions(-)

Diffstat:
Mrelease/libsheepy.c | 2+-
Mrelease/libsheepy.h | 19+++++++++++++------
Msrc/libsheepy.c | 2+-
Msrc/libsheepy.h | 19+++++++++++++------
Msrc/tpool.c | 3+--
5 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/release/libsheepy.c b/release/libsheepy.c @@ -841,7 +841,7 @@ internal void segfault_sigaction(int signal, siginfo_t *si, void *arg) { /* char *s */ /* char realProgPath[8192] */ ucontext_t *context = (ucontext_t *)arg;; - fprintf(stderr, "Segmentation fault (%d) at address %p RIP: %" PRIx64 " in program %s\n", signal, si->si_addr, (uint64_t)context->uc_mcontext.gregs[REG_RIP], libSheepyArg0); + logE("Segmentation fault (%d) at address %p RIP: %" PRIx64 " in program %s\n", signal, si->si_addr, (uint64_t)context->uc_mcontext.gregs[REG_RIP], libSheepyArg0); logBtrace; diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -51,6 +51,8 @@ #endif #include <inttypes.h> /* for PRIu64 in stopwatchLog */ #include <unistd.h> /* for sleep,... */ +#include <string.h> /* for strerror */ +#include <errno.h> /** \file * This file has basic file, random, string, list functions @@ -96,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "1.2.2" +#define LIBSHEEPY_VERSION "1.2.2.1" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME @@ -266,18 +268,23 @@ extern const bool FALSE; #define disableLibsheepyErrorLogs do{logMask &= (~libsheepyErrorMask);}while(0) +#define shperror(string) procbegin\ + char *errstr = strerror(errno);\ + logE("%s: %s", string, errstr);\ + procend + /** * print function name and system error * * to print error, use either pFuncError and shEPrintfS * or shPrintError and shEPrintfS */ -#define pFuncError do{ if ((libsheepyErrorMask) & logMask) { perror(__func__);logEBtrace;} }while(0); +#define pFuncError do{ if ((libsheepyErrorMask) & logMask) { shperror(__func__);logEBtrace;} }while(0); /** * print string and system error */ -#define pStrError(str) do{ if ((libsheepyErrorMask) & logMask) { perror(str);logEBtrace;} }while(0); +#define pStrError(str) do{ if ((libsheepyErrorMask) & logMask) { shperror(str);logEBtrace;} }while(0); /** * print error with line number, function name and file name to stderr @@ -285,7 +292,7 @@ extern const bool FALSE; * to print error, use either pFuncError and shEPrintfS * or shPrintError and shEPrintfS */ -#define shPrintError do{ if ((libsheepyErrorMask) & logMask) { fprintf(stderr, "Error line "stringifyExpr(__LINE__)", function %s, file "__FILE__"\n", __func__); logEBtrace;} }while(0); +#define shPrintError do{ if ((libsheepyErrorMask) & logMask) { logE("Error line "stringifyExpr(__LINE__)", function %s, file "__FILE__"\n", __func__); logEBtrace;} }while(0); /** * print error when function failed. The error code must be -1 @@ -3010,13 +3017,13 @@ char **btrace(void); // TODO readelf missing in macOS #define logBtrace #else -#define logBtrace char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){puts("\n"BLD WHT"Backtrace:"RST);listPrintS(UNIQVAR(r));listFreeS(UNIQVAR(r));puts("---");} +#define logBtrace char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logN("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logN(element);}listFreeS(UNIQVAR(r));logN("---");} #endif extern bool btraceCfg; /** print backtrace in error messages, default is on, use btraceEnable and btraceDisable to configure */ -#define logEBtrace if (btraceCfg) { logBtrace; } +#define logEBtrace if (btraceCfg) { char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logE("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logE(element);}listFreeS(UNIQVAR(r));logE("---");} } // ************************** diff --git a/src/libsheepy.c b/src/libsheepy.c @@ -897,7 +897,7 @@ internal void segfault_sigaction(int signal, siginfo_t *si, void *arg) { /* char *s */ /* char realProgPath[8192] */ ucontext_t *context = (ucontext_t *)arg;; - fprintf(stderr, "Segmentation fault (%d) at address %p RIP: %" PRIx64 " in program %s\n", signal, si->si_addr, (uint64_t)context->uc_mcontext.gregs[REG_RIP], libSheepyArg0); + logE("Segmentation fault (%d) at address %p RIP: %" PRIx64 " in program %s\n", signal, si->si_addr, (uint64_t)context->uc_mcontext.gregs[REG_RIP], libSheepyArg0); logBtrace; diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -51,6 +51,8 @@ #endif #include <inttypes.h> /* for PRIu64 in stopwatchLog */ #include <unistd.h> /* for sleep,... */ +#include <string.h> /* for strerror */ +#include <errno.h> /** \file * This file has basic file, random, string, list functions @@ -96,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "1.2.2" +#define LIBSHEEPY_VERSION "1.2.2.1" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME @@ -266,18 +268,23 @@ extern const bool FALSE; #define disableLibsheepyErrorLogs do{logMask &= (~libsheepyErrorMask);}while(0) +#define shperror(string) procbegin\ + char *errstr = strerror(errno);\ + logE("%s: %s", string, errstr);\ + procend + /** * print function name and system error * * to print error, use either pFuncError and shEPrintfS * or shPrintError and shEPrintfS */ -#define pFuncError do{ if ((libsheepyErrorMask) & logMask) { perror(__func__);logEBtrace;} }while(0); +#define pFuncError do{ if ((libsheepyErrorMask) & logMask) { shperror(__func__);logEBtrace;} }while(0); /** * print string and system error */ -#define pStrError(str) do{ if ((libsheepyErrorMask) & logMask) { perror(str);logEBtrace;} }while(0); +#define pStrError(str) do{ if ((libsheepyErrorMask) & logMask) { shperror(str);logEBtrace;} }while(0); /** * print error with line number, function name and file name to stderr @@ -285,7 +292,7 @@ extern const bool FALSE; * to print error, use either pFuncError and shEPrintfS * or shPrintError and shEPrintfS */ -#define shPrintError do{ if ((libsheepyErrorMask) & logMask) { fprintf(stderr, "Error line "stringifyExpr(__LINE__)", function %s, file "__FILE__"\n", __func__); logEBtrace;} }while(0); +#define shPrintError do{ if ((libsheepyErrorMask) & logMask) { logE("Error line "stringifyExpr(__LINE__)", function %s, file "__FILE__"\n", __func__); logEBtrace;} }while(0); /** * print error when function failed. The error code must be -1 @@ -3010,13 +3017,13 @@ char **btrace(void); // TODO readelf missing in macOS #define logBtrace #else -#define logBtrace char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){puts("\n"BLD WHT"Backtrace:"RST);listPrintS(UNIQVAR(r));listFreeS(UNIQVAR(r));puts("---");} +#define logBtrace char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logN("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logN(element);}listFreeS(UNIQVAR(r));logN("---");} #endif extern bool btraceCfg; /** print backtrace in error messages, default is on, use btraceEnable and btraceDisable to configure */ -#define logEBtrace if (btraceCfg) { logBtrace; } +#define logEBtrace if (btraceCfg) { char **UNIQVAR(r)=btrace();if(UNIQVAR(r)){logE("\n"BLD WHT"Backtrace:"RST);forEachS(UNIQVAR(r), element){logE(element);}listFreeS(UNIQVAR(r));logE("---");} } // ************************** diff --git a/src/tpool.c b/src/tpool.c @@ -17,7 +17,6 @@ #define _DARWIN_C_SOURCE 1 #endif #include <pthread.h> -#include <errno.h> #include <time.h> #if defined(__linux__) #include <sys/prctl.h> @@ -33,7 +32,7 @@ #endif #if !defined(DISABLE_PRINT) || defined(tpool_DEBUG) -#define err(str) fprintf(stderr, str) +#define err(str) logE(str) #else #define err(str) #endif