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 fefad43845f8366294c0b5a9789d9cfedead9193
parent ee5f52fdf0b71a6c52b68e3af6d25e6195f46f76
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu,  9 Dec 2021 17:12:24 +0200

add enableCoreDump function

release/libsheepy.c | 31 +++++++++++++++++++++++++++++++
release/libsheepy.h |  5 ++++-
src/libsheepy.c     | 31 +++++++++++++++++++++++++++++++
src/libsheepy.h     |  5 ++++-
4 files changed, 70 insertions(+), 2 deletions(-)

Diffstat:
Mrelease/libsheepy.c | 31+++++++++++++++++++++++++++++++
Mrelease/libsheepy.h | 5++++-
Msrc/libsheepy.c | 31+++++++++++++++++++++++++++++++
Msrc/libsheepy.h | 5++++-
4 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/release/libsheepy.c b/release/libsheepy.c @@ -111,6 +111,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF); void finalizeLibsheepyCharAtExit(void); int64_t getStackLimit(void); int setStackLimit(int64_t stackSize); +int enableCoreDump(void); const char *getProgName(void); bool setProgName(const char *name); void setDefaultProgName(void); @@ -1653,6 +1654,36 @@ int setStackLimit(int64_t stackSize) { return(1); } +/** + * enable core dump + * + * change core dump size to infinity to enable core dump. + * After the program receives a signal generating core dump, + * a core file is written to disk and can be open with gdb + * + * \return + * !0 when ok + * 0 when it failed + */ +int enableCoreDump(void) { + + // enable core dump + struct rlimit limit; + if (getrlimit(RLIMIT_CORE, &limit) == -1) { + pFuncError + return(0); + } + + // dump the complete process memory + limit.rlim_cur = RLIM_INFINITY; + if (setrlimit(RLIMIT_CORE, &limit) == -1) { + pFuncError + return(0); + } + + return(1); +} + /** * get program name diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.6.4" +#define LIBSHEEPY_VERSION "2.2.7" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME @@ -1563,6 +1563,9 @@ int64_t getStackLimit(void) MUST_CHECK; // set stack limit (-1 for unlimited) - returns 0 when error int setStackLimit(int64_t stackSize) MUST_CHECK; +// enable core dump +int enableCoreDump(void) MUST_CHECK; + // get program name const char *getProgName(void) MUST_CHECK; diff --git a/src/libsheepy.c b/src/libsheepy.c @@ -113,6 +113,7 @@ void initLibsheepyF(const char *progPath, initLibsheepyObjectP initF); void finalizeLibsheepyCharAtExit(void); int64_t getStackLimit(void); int setStackLimit(int64_t stackSize); +int enableCoreDump(void); const char *getProgName(void); bool setProgName(const char *name); void setDefaultProgName(void); @@ -1709,6 +1710,36 @@ int setStackLimit(int64_t stackSize) { return(1); } +/** + * enable core dump + * + * change core dump size to infinity to enable core dump. + * After the program receives a signal generating core dump, + * a core file is written to disk and can be open with gdb + * + * \return + * !0 when ok + * 0 when it failed + */ +int enableCoreDump(void) { + + // enable core dump + struct rlimit limit; + if (getrlimit(RLIMIT_CORE, &limit) == -1) { + pFuncError + return(0); + } + + // dump the complete process memory + limit.rlim_cur = RLIM_INFINITY; + if (setrlimit(RLIMIT_CORE, &limit) == -1) { + pFuncError + return(0); + } + + return(1); +} + /** * get program name diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.6.4" +#define LIBSHEEPY_VERSION "2.2.7" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME @@ -1563,6 +1563,9 @@ int64_t getStackLimit(void) MUST_CHECK; // set stack limit (-1 for unlimited) - returns 0 when error int setStackLimit(int64_t stackSize) MUST_CHECK; +// enable core dump +int enableCoreDump(void) MUST_CHECK; + // get program name const char *getProgName(void) MUST_CHECK;