Skip to contentSkip to conversation

lib: add tst_no_corefile to avoid corefile dumping

RFC PATCH New Li Wang 2 participants 5 messages Jul 1, 2019 – Jul 3, 2019

lore
Share & tools
lore

Li Wang

author
#0 lore raw

RFC PATCH 1/1 lib: add tst_no_corefile to avoid corefile dumping

Cc Jan Stancek <[email protected]>
---
 include/tst_safe_macros.h                        | 16 ++++++++++++++++
 testcases/kernel/security/umip/umip_basic_test.c |  2 ++
 testcases/kernel/syscalls/ipc/shmat/shmat01.c    | 16 +++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)
include/tst_safe_macros.h +16 -0
index 53a888c80..110e2984f 100644
@@ -394,6 +394,22 @@ static inline int safe_setrlimit(const char *file, const int lineno,
 #define SAFE_SETRLIMIT(resource, rlim) \
 	safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
 
+/*
+ * Crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+static inline void tst_no_corefile(void)
+{
+       struct rlimit r;
+
+       r.rlim_cur = 1;
+       r.rlim_max = 1;
+       SAFE_SETRLIMIT(RLIMIT_CORE, &r);
+       tst_res(TINFO, "Avoid dumping corefile in following test");
+}
+
 typedef void (*sighandler_t)(int);
 static inline sighandler_t safe_signal(const char *file, const int lineno,
 				       int signum, sighandler_t handler)
testcases/kernel/security/umip/umip_basic_test.c +2 -0
index c34d4a1f6..0a86f0727 100644
@@ -86,6 +86,8 @@ static void verify_umip_instruction(unsigned int n)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
+		tst_no_corefile();
+
 		switch (n) {
 		case 0:
 			asm_sgdt();
testcases/kernel/syscalls/ipc/shmat/shmat01.c +3 -13
index aa9dfd4e5..415af01ec 100644
@@ -59,19 +59,9 @@ static void *expected_addr(void *in_addr, void *out_addr)
 
 static void do_child(int *in_addr, int expect_crash)
 {
-	if (expect_crash) {
-		/*
-		 * Crash is expected, avoid dumping corefile.
-		 * 1 is a special value, that disables core-to-pipe.
-		 * At the same time it is small enough value for
-		 * core-to-file, so it skips creating cores as well.
-		*/
-		struct rlimit r;
-
-		r.rlim_cur = 1;
-		r.rlim_max = 1;
-		SAFE_SETRLIMIT(RLIMIT_CORE, &r);
-	}
+	if (expect_crash)
+		tst_no_corefile();
+
 	*in_addr = 10;
 
 	exit(0);
Signature · 1 line
2.20.1
#1 lore raw

RFC PATCH 1/1 lib: add tst_no_corefile to avoid corefile dumping

----- Original Message -----

Quoted 21 lines
Cc Jan Stancek <[email protected]>
---
 include/tst_safe_macros.h                        | 16 ++++++++++++++++
 testcases/kernel/security/umip/umip_basic_test.c |  2 ++
 testcases/kernel/syscalls/ipc/shmat/shmat01.c    | 16 +++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)
include/tst_safe_macros.h +4 -0
index 53a888c80..110e2984f 100644
@@ -394,6 +394,22 @@ static inline int safe_setrlimit(const char *file, const
 int lineno,
 #define SAFE_SETRLIMIT(resource, rlim) \
 	safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
 
+/*
+ * Crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file, const · line 411

Quoted 10 lines
include/tst_safe_macros.h +10 -0
+ * core-to-file, so it skips creating cores as well.
+ */
+static inline void tst_no_corefile(void)
+{
+       struct rlimit r;
+
+       r.rlim_cur = 1;
+       r.rlim_max = 1;
+       SAFE_SETRLIMIT(RLIMIT_CORE, &r);
+       tst_res(TINFO, "Avoid dumping corefile in following test");

I'm fine with helper func. Maybe I'd print also current pid. It could be little spammy if there are many children, but we could address that later (if needed) with a parameter to control verbosity.

author
#2 lore raw

RFC PATCH 1/1 lib: add tst_no_corefile to avoid corefile dumping

Quoted 31 lines · Jan Stancek

----- Original Message -----

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file,

Quoted 13 lines
Cc Jan Stancek <[email protected]>
---
 include/tst_safe_macros.h                        | 16 ++++++++++++++++
 testcases/kernel/security/umip/umip_basic_test.c |  2 ++
 testcases/kernel/syscalls/ipc/shmat/shmat01.c    | 16 +++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)
include/tst_safe_macros.h +0 -0
index 53a888c80..110e2984f 100644
@@ -394,6 +394,22 @@ static inline int safe_setrlimit(const char *file,

const

Quoted 14 lines
include/tst_safe_macros.h +10 -0
 int lineno,
 #define SAFE_SETRLIMIT(resource, rlim) \
      safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
 
+/*
+ * Crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+static inline void tst_no_corefile(void)
+{
+       struct rlimit r;
+
Quoted 9 lines

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file, const int lineno, · line 410

Quoted 4 lines
include/tst_safe_macros.h +4 -0
+       r.rlim_cur = 1;
+       r.rlim_max = 1;
+       SAFE_SETRLIMIT(RLIMIT_CORE, &r);
+       tst_res(TINFO, "Avoid dumping corefile in following test");

I'm fine with helper func. Maybe I'd print also current pid. It could be little spammy if there are many children, but we could address that later (if needed) with a parameter to control verbosity.

To add a parameter (int verbose) sounds good to me.

Btw, should we add some note/comment in the document(test-writing-guidelines.txt)? I take a rough look but not sure which line is the best position for that.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190702/b9356c20/attachment-0001.htm>
#3 lore raw

RFC PATCH 1/1 lib: add tst_no_corefile to avoid corefile dumping

----- Original Message -----

Quoted 43 lines · Jan Stancek
Quoted 32 lines

----- Original Message -----

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file,

Quoted 13 lines
Cc Jan Stancek <[email protected]>
---
 include/tst_safe_macros.h                        | 16 ++++++++++++++++
 testcases/kernel/security/umip/umip_basic_test.c |  2 ++
 testcases/kernel/syscalls/ipc/shmat/shmat01.c    | 16 +++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)
include/tst_safe_macros.h +0 -0
index 53a888c80..110e2984f 100644
@@ -394,6 +394,22 @@ static inline int safe_setrlimit(const char *file,

const

Quoted 14 lines
include/tst_safe_macros.h +10 -0
 int lineno,
 #define SAFE_SETRLIMIT(resource, rlim) \
      safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
 
+/*
+ * Crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+static inline void tst_no_corefile(void)
+{
+       struct rlimit r;
+
Quoted 9 lines

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file, const int lineno, · line 410

Quoted 4 lines
include/tst_safe_macros.h +4 -0
+       r.rlim_cur = 1;
+       r.rlim_max = 1;
+       SAFE_SETRLIMIT(RLIMIT_CORE, &r);
+       tst_res(TINFO, "Avoid dumping corefile in following test");

I'm fine with helper func. Maybe I'd print also current pid. It could be little spammy if there are many children, but we could address that later (if needed) with a parameter to control verbosity.

Quoted 5 lines

To add a parameter (int verbose) sounds good to me.

Btw, should we add some note/comment in the document(test-writing-guidelines.txt)? I take a rough look but not sure which line is the best position for that.

How about we extend "2.2.10 Signal handlers" to "2.2.10 Signals and signal handlers" and put a note there?

Quoted 5 lines

--
Regards,
Li Wang

author
#4 lore raw

RFC PATCH 1/1 lib: add tst_no_corefile to avoid corefile dumping

Quoted 51 lines · Jan Stancek

----- Original Message -----

Quoted 9 lines · Jan Stancek
Quoted 8 lines

----- Original Message -----

Quoted 4 lines
Cc Jan Stancek <[email protected]>
---
 include/tst_safe_macros.h                        | 16

++++++++++++++++

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
 testcases/kernel/security/umip/umip_basic_test.c |  2 ++
 testcases/kernel/syscalls/ipc/shmat/shmat01.c    | 16

+++-------------

Quoted 7 lines
Quoted 7 lines

include/tst_safe_macros.h static inline int safe_setrlimit(const char

Quoted 7 lines
 3 files changed, 21 insertions(+), 13 deletions(-)
include/tst_safe_macros.h +0 -0
index 53a888c80..110e2984f 100644
@@ -394,6 +394,22 @@ static inline int safe_setrlimit(const char

*file,

Quoted 27 lines
Quoted 15 lines

const

Quoted 14 lines
include/tst_safe_macros.h +10 -0
 int lineno,
 #define SAFE_SETRLIMIT(resource, rlim) \
      safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
 
+/*
+ * Crash is expected, avoid dumping corefile.
+ * 1 is a special value, that disables core-to-pipe.
+ * At the same time it is small enough value for
+ * core-to-file, so it skips creating cores as well.
+ */
+static inline void tst_no_corefile(void)
+{
+       struct rlimit r;
+
Quoted 9 lines

include/tst_safe_macros.h static inline int safe_setrlimit(const char *file, const int lineno, · line 410

Quoted 4 lines
include/tst_safe_macros.h +4 -0
+       r.rlim_cur = 1;
+       r.rlim_max = 1;
+       SAFE_SETRLIMIT(RLIMIT_CORE, &r);
+       tst_res(TINFO, "Avoid dumping corefile in following test");

I'm fine with helper func. Maybe I'd print also current pid. It could be little spammy if there are many children, but we could address that later (if needed) with a parameter to control verbosity.

To add a parameter (int verbose) sounds good to me.

Quoted 7 lines
Quoted 3 lines

Btw, should we add some note/comment in the document(test-writing-guidelines.txt)? I take a rough look but not sure which line is the best position for that.

How about we extend "2.2.10 Signal handlers" to "2.2.10 Signals and signal handlers"
and put a note there?

Good point.

Since that core file dumping is(sometimes) a response for signal SIGSEGV in process, we purpose to change that behavior and avoid to generate a dump that related to this topic.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190703/07ab69ce/attachment.htm>