Skip to contentSkip to conversation

library: add tst_system for wrapper system(3) without SIGCHLD

PATCH Superseded [email protected] 3 participants 4 messages Nov 17, 2014 – Dec 16, 2014 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 library: add tst_system for wrapper system(3) without SIGCHLD

From: George Wang <[email protected]>

system(3) will raise SIGCHLD signal to parent process, and most test cases will call tst_sig to poison all signals including the SIGCHLD. So add system(3) wrapper function to temporarily disable the poisoned handler for SIGCHLD, which will make the test cases happy.
Replace directly calling system(3) with tst_systm on behalf of ignorcing SIGCHLG signal posioned handler.

---
 include/test.h    |  5 +++++
 lib/tst_mkfs.c    |  2 +-
 lib/tst_run_cmd.c | 17 +++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
include/test.h +5 -0
index 775ba39..326b686 100644
@@ -300,6 +300,11 @@ void tst_run_cmd(void (cleanup_fn)(void),
 		const char *stdout_path,
 		const char *stderr_path);
 
+/* Wrapper function for system(3), ignorcing SIGCLD signal.
+ * @command: the command to be run.
+ */
+int tst_system(const char *command);
+
 /* lib/tst_mkfs.c
  *
  * @dev: path to a device
lib/tst_mkfs.c +1 -1
index 5eb3392..173347a 100644
@@ -45,7 +45,7 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
 		/*
 		 * The -f option was added to btrfs-progs v3.12
 		 */
-		if (system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
+		if (tst_system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
 			tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
 				fs_type);
 			argv[pos++] = "-f";
lib/tst_run_cmd.c +17 -0
index 4eb32e6..5a02db0 100644
@@ -125,3 +125,20 @@ void tst_run_cmd(void (cleanup_fn)(void),
 			"close() on %s failed at %s:%d",
 			stderr_path, __FILE__, __LINE__);
 }
+
+int tst_system(const char *command)
+{
+	int ret = 0;
+
+	/*
+	 *Temporarily disable SIGCHLD of user defined handler, so the
+	 *system(3) function will not cause unexpected SIGCHLD signal
+	 *callback function for test cases.
+	 */
+	void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+	ret = system(command);
+
+	signal(SIGCHLD, old_handler);
+	return ret;
+}
Signature · 13 lines
1.8.4.2


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

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

Quoted 6 lines

From: [email protected]
To: [email protected]
Sent: Monday, 17 November, 2014 5:04:39 PM
Subject: [LTP] [PATCH V2] library: add tst_system for wrapper system(3) without SIGCHLD

From: George Wang <[email protected]>

Hi,

Looks good to me, I tested only on single testcase, it work as advertised. Couple nits to comments/commit message:

Quoted 7 lines

system(3) will raise SIGCHLD signal to parent process, and most test cases will call tst_sig to poison all signals including the SIGCHLD. So add system(3) wrapper function to temporarily disable the poisoned handler for SIGCHLD, which will make the test cases happy.
Replace directly calling system(3) with tst_systm on behalf of

^^ tst_system

Quoted 1 line

ignorcing SIGCHLG signal posioned handler.

^^ ignoring ^^ poisoned
I don't get the "on behalf of" part of that sentence. Maybe:
"Replace system(3) with tst_system() to ignore SIGCHLG signal handler poisoned earlier."

Quoted 13 lines
---
 include/test.h    |  5 +++++
 lib/tst_mkfs.c    |  2 +-
 lib/tst_run_cmd.c | 17 +++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
include/test.h +0 -0
index 775ba39..326b686 100644

include/test.h void tst_run_cmd(void (cleanup_fn)(void), · line 303

Quoted 4 lines
include/test.h +1 -0
@@ -300,6 +300,11 @@ void tst_run_cmd(void (cleanup_fn)(void),
 		const char *stdout_path,
 		const char *stderr_path);
 
+/* Wrapper function for system(3), ignorcing SIGCLD signal.

^^ ignoring

Quoted 12 lines
include/test.h +4 -0
+ * @command: the command to be run.
+ */
+int tst_system(const char *command);
+
 /* lib/tst_mkfs.c
  *
  * @dev: path to a device
lib/tst_mkfs.c +0 -0
index 5eb3392..173347a 100644

lib/tst_mkfs.c void tst_mkfs(void (cleanup_fn)(void), const char *dev, · line 48

Quoted 5 lines
lib/tst_mkfs.c +1 -1
@@ -45,7 +45,7 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
 		/*
 		 * The -f option was added to btrfs-progs v3.12
 		 */
-		if (system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
+		if (tst_system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {

This line is now too long.

Regards,
Jan

Quoted 32 lines
lib/tst_mkfs.c +0 -0
 			tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
 				fs_type);
 			argv[pos++] = "-f";
lib/tst_run_cmd.c +17 -1
index 4eb32e6..5a02db0 100644
@@ -125,3 +125,20 @@ void tst_run_cmd(void (cleanup_fn)(void),
 			"close() on %s failed at %s:%d",
 			stderr_path, __FILE__, __LINE__);
 }
+
+int tst_system(const char *command)
+{
+	int ret = 0;
+
+	/*
+	 *Temporarily disable SIGCHLD of user defined handler, so the
+	 *system(3) function will not cause unexpected SIGCHLD signal
+	 *callback function for test cases.
+	 */
+	void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+	ret = system(command);
+
+	signal(SIGCHLD, old_handler);
+	return ret;
+}
--

1.8.4.2

Quoted 11 lines

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

Hi, George.

I've just found that I'm also motivated to have this bug fixed :)

Are you planning to send an updated version including Jan's comments?

Thanks.

PS: I also tested it with access06 test case:

without the patch:

[root@kholmanskikh access]# LTP_DEV_FS_TYPE=btrfs ./access06

access06    0  TINFO  :  Found free device '/dev/loop0'
access06    1  TBROK  :  tst_sig.c:233: unexpected signal 

SIGCHLD/SIGCLD(17) received (pid = 10671).
access06 2 TBROK : tst_sig.c:233: Remaining cases broken

with:
[root@kholmanskikh access]# LTP_DEV_FS_TYPE=btrfs ./access06

access06    0  TINFO  :  Found free device '/dev/loop0'
access06    0  TINFO  :  Appending '-f' flag to mkfs.btrfs
access06    0  TINFO  :  Formatting /dev/loop0 with btrfs extra opts=''
access06    1  TPASS  :  access failed as expected: 
TEST_ERRNO=EROFS(30): Read-only file system
Quoted 117 lines · Jan Stancek

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

Quoted 6 lines

From: [email protected]
To: [email protected]
Sent: Monday, 17 November, 2014 5:04:39 PM
Subject: [LTP] [PATCH V2] library: add tst_system for wrapper system(3) without SIGCHLD

From: George Wang <[email protected]>

Hi,

Looks good to me, I tested only on single testcase, it work as advertised. Couple nits to comments/commit message:

Quoted 7 lines

system(3) will raise SIGCHLD signal to parent process, and most test cases will call tst_sig to poison all signals including the SIGCHLD. So add system(3) wrapper function to temporarily disable the poisoned handler for SIGCHLD, which will make the test cases happy.
Replace directly calling system(3) with tst_systm on behalf of

^^ tst_system

Quoted 1 line

ignorcing SIGCHLG signal posioned handler.

^^ ignoring ^^ poisoned
I don't get the "on behalf of" part of that sentence. Maybe:
"Replace system(3) with tst_system() to ignore SIGCHLG signal handler poisoned earlier."

Quoted 13 lines
---
  include/test.h    |  5 +++++
  lib/tst_mkfs.c    |  2 +-
  lib/tst_run_cmd.c | 17 +++++++++++++++++
  3 files changed, 23 insertions(+), 1 deletion(-)
include/test.h +0 -0
index 775ba39..326b686 100644

include/test.h void tst_run_cmd(void (cleanup_fn)(void), · line 303

Quoted 4 lines
include/test.h +1 -0
@@ -300,6 +300,11 @@ void tst_run_cmd(void (cleanup_fn)(void),
  		const char *stdout_path,
  		const char *stderr_path);
 
+/* Wrapper function for system(3), ignorcing SIGCLD signal.

^^ ignoring

Quoted 12 lines
include/test.h +4 -0
+ * @command: the command to be run.
+ */
+int tst_system(const char *command);
+
  /* lib/tst_mkfs.c
   *
   * @dev: path to a device
lib/tst_mkfs.c +0 -0
index 5eb3392..173347a 100644

lib/tst_mkfs.c void tst_mkfs(void (cleanup_fn)(void), const char *dev, · line 48

Quoted 5 lines
lib/tst_mkfs.c +1 -1
@@ -45,7 +45,7 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
  		/*
  		 * The -f option was added to btrfs-progs v3.12
  		 */
-		if (system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
+		if (tst_system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {

This line is now too long.

Regards,
Jan

Quoted 32 lines
lib/tst_mkfs.c +0 -0
  			tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
  				fs_type);
  			argv[pos++] = "-f";
lib/tst_run_cmd.c +17 -1
index 4eb32e6..5a02db0 100644
@@ -125,3 +125,20 @@ void tst_run_cmd(void (cleanup_fn)(void),
  			"close() on %s failed at %s:%d",
  			stderr_path, __FILE__, __LINE__);
  }
+
+int tst_system(const char *command)
+{
+	int ret = 0;
+
+	/*
+	 *Temporarily disable SIGCHLD of user defined handler, so the
+	 *system(3) function will not cause unexpected SIGCHLD signal
+	 *callback function for test cases.
+	 */
+	void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+	ret = system(command);
+
+	signal(SIGCHLD, old_handler);
+	return ret;
+}
--

1.8.4.2

Quoted 11 lines

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

Quoted 9 lines

from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

author
#3 lore raw

Sorry for missing to read the review email from Jan. I've already post PATCHv3 about this issue to ltp-list.

Thanks for Jan's review, and I appreciate it very much.

Best regards,

Signature · 41 lines
George Wang 王旭

Kernel Quantity Engineer
Red Hat Software (Beijing) Co.,Ltd
IRC:xuw
Tel:+86-010-62608041
Phone:15901231579
9/F, Tower C, Raycom

----- Original Message -----
From: "Stanislav Kholmanskikh" <[email protected]>
To: [email protected]
Cc: "Jan Stancek" <[email protected]>, [email protected]
Sent: Tuesday, December 16, 2014 6:57:43 PM
Subject: Re: [LTP] [PATCH V2] library: add tst_system for wrapper system(3) without SIGCHLD

Hi, George.

I've just found that I'm also motivated to have this bug fixed :)

Are you planning to send an updated version including Jan's comments?

Thanks.

PS: I also tested it with access06 test case:

without the patch:

[root@kholmanskikh access]# LTP_DEV_FS_TYPE=btrfs ./access06
access06    0  TINFO  :  Found free device '/dev/loop0'
access06    1  TBROK  :  tst_sig.c:233: unexpected signal 
SIGCHLD/SIGCLD(17) received (pid = 10671).
access06    2  TBROK  :  tst_sig.c:233: Remaining cases broken

with:
[root@kholmanskikh access]# LTP_DEV_FS_TYPE=btrfs ./access06
access06    0  TINFO  :  Found free device '/dev/loop0'
access06    0  TINFO  :  Appending '-f' flag to mkfs.btrfs
access06    0  TINFO  :  Formatting /dev/loop0 with btrfs extra opts=''
access06    1  TPASS  :  access failed as expected: 
TEST_ERRNO=EROFS(30): Read-only file system
Quoted 117 lines · Jan Stancek

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

Quoted 6 lines

From: [email protected]
To: [email protected]
Sent: Monday, 17 November, 2014 5:04:39 PM
Subject: [LTP] [PATCH V2] library: add tst_system for wrapper system(3) without SIGCHLD

From: George Wang <[email protected]>

Hi,

Looks good to me, I tested only on single testcase, it work as advertised. Couple nits to comments/commit message:

Quoted 7 lines

system(3) will raise SIGCHLD signal to parent process, and most test cases will call tst_sig to poison all signals including the SIGCHLD. So add system(3) wrapper function to temporarily disable the poisoned handler for SIGCHLD, which will make the test cases happy.
Replace directly calling system(3) with tst_systm on behalf of

^^ tst_system

Quoted 1 line

ignorcing SIGCHLG signal posioned handler.

^^ ignoring ^^ poisoned
I don't get the "on behalf of" part of that sentence. Maybe:
"Replace system(3) with tst_system() to ignore SIGCHLG signal handler poisoned earlier."

Quoted 13 lines
---
  include/test.h    |  5 +++++
  lib/tst_mkfs.c    |  2 +-
  lib/tst_run_cmd.c | 17 +++++++++++++++++
  3 files changed, 23 insertions(+), 1 deletion(-)
include/test.h +0 -0
index 775ba39..326b686 100644

include/test.h void tst_run_cmd(void (cleanup_fn)(void), · line 303

Quoted 4 lines
include/test.h +1 -0
@@ -300,6 +300,11 @@ void tst_run_cmd(void (cleanup_fn)(void),
  		const char *stdout_path,
  		const char *stderr_path);
 
+/* Wrapper function for system(3), ignorcing SIGCLD signal.

^^ ignoring

Quoted 12 lines
include/test.h +4 -0
+ * @command: the command to be run.
+ */
+int tst_system(const char *command);
+
  /* lib/tst_mkfs.c
   *
   * @dev: path to a device
lib/tst_mkfs.c +0 -0
index 5eb3392..173347a 100644

lib/tst_mkfs.c void tst_mkfs(void (cleanup_fn)(void), const char *dev, · line 48

Quoted 5 lines
lib/tst_mkfs.c +1 -1
@@ -45,7 +45,7 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
  		/*
  		 * The -f option was added to btrfs-progs v3.12
  		 */
-		if (system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {
+		if (tst_system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null") == 0) {

This line is now too long.

Regards,
Jan

Quoted 32 lines
lib/tst_mkfs.c +0 -0
  			tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
  				fs_type);
  			argv[pos++] = "-f";
lib/tst_run_cmd.c +17 -1
index 4eb32e6..5a02db0 100644
@@ -125,3 +125,20 @@ void tst_run_cmd(void (cleanup_fn)(void),
  			"close() on %s failed at %s:%d",
  			stderr_path, __FILE__, __LINE__);
  }
+
+int tst_system(const char *command)
+{
+	int ret = 0;
+
+	/*
+	 *Temporarily disable SIGCHLD of user defined handler, so the
+	 *system(3) function will not cause unexpected SIGCHLD signal
+	 *callback function for test cases.
+	 */
+	void *old_handler = signal(SIGCHLD, SIG_DFL);
+
+	ret = system(command);
+
+	signal(SIGCHLD, old_handler);
+	return ret;
+}
--

1.8.4.2

Quoted 11 lines

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

Quoted 9 lines

from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list