library: add tst_system for wrapper system(3) without SIGCHLD
PATCH v3 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 system(3) with tst_system() to ignore SIGCHLG signal handler poisoned earlier.
--- include/test.h | 5 +++++ lib/tst_mkfs.c | 4 +++- lib/tst_run_cmd.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-)
include/test.h +5 -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. +* @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 +3 -1
@@ -45,7 +45,9 @@ 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 (0 ==tst_system ( +"mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null" ) + ) {tst_resm (TINFO ,"Appending '-f' flag to mkfs.%s" , fs_type); argv[pos++] ="-f" ;
lib/tst_run_cmd.c +17 -0
@@ -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=164703151&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
lib/tst_mkfs.c void tst_mkfs(void (cleanup_fn)(void), const char *dev, · line 50
Quoted 4 lines
lib/tst_mkfs.c +3
-1-if (system ("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null" ) ==0 ) { +if (0 ==tst_system ( +"mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null" ) + ) {
This is way too ugly. What about:
if (!tst_system("mkfs.btrfs 2>&1 | grep '\\-f '>/dev/null")) {Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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
Hi!
Quoted 7 lines
- if (
system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null")== 0) {
here is the original author's check, use "== 0", so I'am not sure the "!tst_system" will be good for ltp's coding style.and if I make codes like this, the next line's style will not be consistent to it:
+ if (!tst_system("mkfs.btrfs 2>&1 | grep '\\-f ' >/dev/null")) {
tst_resm(TINFO, "Appending '-f' flag to mkfs.%s",
fs_type);
I do not get what is inconsistent here. The line for the if condition is 79 chars long that way, the next line with tst_resm would be more than 80 therefore it should continue on the next line. It's that simple.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ 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