[minicoredumper] [PATCH 14/14] minicoredumper: Add option to exclude specified files from copying from proc

Mateusz Moscicki m.moscicki2 at partner.samsung.com
Tue May 21 14:52:50 CEST 2019


To exclude some files, add option to recipe file, e.g.:

  "proc_info_exclude": [
    "smaps",
    "maps"
  ]

Possible names for exclusion:
 * cmdline
 * environ
 * io
 * maps
 * smaps
 * stack
 * stat
 * statm
 * cwd
 * fd

Change-Id: I476e3448e1f0f8469b5a39ce5f32917f7126e4ce
---
 etc/minicoredumper/generic.recept.json          |  5 ++-
 src/minicoredumper/corestripper.c               | 12 +++++++
 src/minicoredumper/minicoredumper.recept.json.5 | 13 +++++++
 src/minicoredumper/prog_config.c                | 47 +++++++++++++++++++++++++
 src/minicoredumper/prog_config.h                |  6 ++++
 5 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/etc/minicoredumper/generic.recept.json b/etc/minicoredumper/generic.recept.json
index fe24195..70108be 100644
--- a/etc/minicoredumper/generic.recept.json
+++ b/etc/minicoredumper/generic.recept.json
@@ -20,7 +20,10 @@
     "dump_scope": 1024,
     "dump_build_id": false,
     "live_dumper": true,
-    "write_proc_info": false,
+    "write_proc_info": true,
+    "proc_info_exclude": [
+        "smaps"
+    ],
     "write_debug_log": false,
     "dump_fat_core": false,
     "dump_pointed_by_regs": true
diff --git a/src/minicoredumper/corestripper.c b/src/minicoredumper/corestripper.c
index c0d6514..b877a09 100644
--- a/src/minicoredumper/corestripper.c
+++ b/src/minicoredumper/corestripper.c
@@ -2946,6 +2946,15 @@ static int copy_link(const char *dest, const char *src)
 	return ret;
 }
 
+static bool is_file_name_excluded(const char *name, struct dump_info *di)
+{
+	for (int i = 0; i < di->cfg->prog_config.proc_excludes.count; i++) {
+		if (strncmp(name, di->cfg->prog_config.proc_excludes.filenames[i], strlen(name)) == 0)
+			return true;
+	}
+	return false;
+}
+
 static void copy_proc_files(struct dump_info *di, int tasks, const char *name,
 			    int link)
 {
@@ -2957,6 +2966,9 @@ static void copy_proc_files(struct dump_info *di, int tasks, const char *name,
 	DIR *d;
 	int i;
 
+	if (is_file_name_excluded(name, di))
+		return;
+
 	base_len = strlen(di->dst_dir);
 
 	/* assume maximum length expected */
diff --git a/src/minicoredumper/minicoredumper.recept.json.5 b/src/minicoredumper/minicoredumper.recept.json.5
index 0d66b20..043eea7 100644
--- a/src/minicoredumper/minicoredumper.recept.json.5
+++ b/src/minicoredumper/minicoredumper.recept.json.5
@@ -80,6 +80,19 @@ applications when a dump occurs.
 (boolean) Whether interesting /proc files should be copied to the
 dump directory.
 .TP
+.B proc_info_exclude
+(array of strings) Allows to specify which files shouldn't be copied. Allowed values:
+.I cmdline
+.I environ
+.I io
+.I maps
+.I smaps
+.I stack
+.I stat
+.I statm
+.I cwd
+.I fd
+.TP
 .B write_debug_log
 (boolean) Whether
 .BR minicoredumper (1)
diff --git a/src/minicoredumper/prog_config.c b/src/minicoredumper/prog_config.c
index a58da3e..e225cef 100644
--- a/src/minicoredumper/prog_config.c
+++ b/src/minicoredumper/prog_config.c
@@ -331,6 +331,43 @@ static int read_prog_stack_config(struct json_object *root,
 	return 0;
 }
 
+static int read_proc_info_exclude_config(struct json_object *root,
+				  struct proc_info_exclude_config *cfg)
+{
+	int len;
+	int i;
+	int res = 0;
+	if (!json_object_is_type(root, json_type_array))
+		return -1;
+
+	len = json_object_array_length(root);
+	if (len < 1)
+		return 0;
+
+	cfg->filenames = calloc(len, sizeof(char *));
+	if (!cfg->filenames)
+		return -1;
+
+	for (i = 0; i < len; i++) {
+		struct json_object *v;
+
+		v = json_object_array_get_idx(root, i);
+		if (!v) {
+			res = -1;
+			break;
+		}
+
+		cfg->filenames[i] = alloc_json_string(v);
+		if (!cfg->filenames[i]) {
+			res = -1;
+			break;
+		}
+	}
+	cfg->count = i;
+
+	return res;
+}
+
 static int read_prog_config(struct json_object *root, struct prog_config *cfg)
 {
 	struct json_object_iterator it_end;
@@ -411,6 +448,9 @@ static int read_prog_config(struct json_object *root, struct prog_config *cfg)
 		} else if (strcmp(n, "dump_pointed_by_regs") == 0) {
 			if (get_json_boolean(v, &cfg->dump_pointed_by_regs) != 0)
 				return -1;
+		} else if (strcmp(n, "proc_info_exclude") == 0) {
+			if (read_proc_info_exclude_config(v, &cfg->proc_excludes) != 0)
+				return -1;
 		} else {
 			info("WARNING: ignoring unknown config item: %s", n);
 		}
@@ -708,6 +748,11 @@ static void set_config_defaults(struct prog_config *cfg)
 
 	/* dump NT_GNU_BUILD_ID */
 	cfg->dump_build_id = false;
+
+	/* Array of excluded files */
+	cfg->proc_excludes.count = 0;
+	cfg->proc_excludes.filenames = NULL;
+
 }
 
 int init_prog_config(struct config *cfg, const char *cfg_file)
@@ -756,6 +801,8 @@ void free_config(struct config *cfg)
 
 	for (i = 0; i < cfg->prog_config.maps.nglobs; i++)
 		free(cfg->prog_config.maps.name_globs[i]);
+	for (i = 0; i < cfg->prog_config.proc_excludes.count; i++)
+		free(cfg->prog_config.proc_excludes.filenames[i]);
 	if (cfg->prog_config.maps.name_globs)
 		free(cfg->prog_config.maps.name_globs);
 
diff --git a/src/minicoredumper/prog_config.h b/src/minicoredumper/prog_config.h
index 9d69153..2f57c12 100644
--- a/src/minicoredumper/prog_config.h
+++ b/src/minicoredumper/prog_config.h
@@ -37,10 +37,16 @@ struct maps_config {
 	size_t nglobs;
 };
 
+struct proc_info_exclude_config {
+	char **filenames;
+	size_t count;
+};
+
 struct prog_config {
 	struct stack_config stack;
 	struct maps_config maps;
 	struct interesting_buffer *buffers;
+	struct proc_info_exclude_config proc_excludes;
 	char *core_compressor;
 	char *core_compressor_ext;
 	bool core_in_tar;
-- 
2.7.4




More information about the minicoredumper mailing list