[minicoredumper] Write core dumps even if they have not existed before

Michael michael at mipisi.de
Sat Sep 30 11:49:13 CEST 2017


Hi members of minicoredumper at linutronix.de 
<mailto:minicoredumper at linutronix.de>,

I started using minicoredumper for our projects. Very nice and handy tool!

Just an idea on how it could be made even more handy.

Motivation:
On embedded system an enduser should not see any core dumps on the 
device. So core dumps are something you only need for development.
There is a nice feature of minicoredumper that allows to customize the 
path where core files are stored. My problem here is that this path needs to
exist in filesystem.

What I have done is setting the customized core dump path to 
/home/root/crash and patch the minicoredump to not fail if dir does not 
exist.
Instead now the sub directory "crash" is created when the first crash 
occurs.

For me and my colleagues (especially for fieldtest) this is nice, 
because then you see: If a dir crash exists, something went wrong, else 
all fine.

To achieve this I patched the minicoredumper source:

 From a89bb8711d3521cd11d69ef0531918d0345aa5c9 Mon Sep 17 00:00:00 2001
From: "Bode, Michael (BSH)" <Michael.Bode at bshg.com>
Date: Sat, 30 Sep 2017 11:03:35 +0200
Subject: [PATCH] Modify mkdir function to generate core dump also if dir 
have
  not existed before

---
  src/minicoredumper/corestripper.c | 20 +++++++++++++++++++-
  1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/minicoredumper/corestripper.c 
b/src/minicoredumper/corestripper.c
index f4e7fcd..dce1170 100644
--- a/src/minicoredumper/corestripper.c
+++ b/src/minicoredumper/corestripper.c
@@ -308,6 +308,24 @@ out:
      return err;
  }

+
+static int mkpath(char *dir, mode_t mode)
+{
+    struct stat sb;
+
+    if (!dir) {
+        errno = EINVAL;
+        return 1;
+    }
+
+    if (!stat(dir, &sb))
+        return 0;
+
+    mkpath(dirname(strdupa(dir)), mode);
+
+    return mkdir(dir, mode);
+}
+
  static int init_di(struct dump_info *di, char **argv, int argc)
  {
      const char *recept;
@@ -430,7 +448,7 @@ static int init_di(struct dump_info *di, char 
**argv, int argc)
      }
      di->dst_dir = tmp_path;

-    if (mkdir(di->dst_dir, 0700) == -1) {
+    if (mkpath(di->dst_dir, 0700) == -1) {
          info("unable to create directory \'%s\': %s", di->dst_dir,
               strerror(errno));
          return 1;
-- 
2.7.4

Please don't take my implementation proposal too serious. I just want to 
give you the idea here.
If you agree that this is an improvement maybe it would be even better 
to have an option in JSON file if you want to write non-existing paths.

Br,
Michael



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linutronix.de/pipermail/minicoredumper/attachments/20170930/818e5478/attachment.html>


More information about the minicoredumper mailing list