From: Zorro Lang <zlang@redhat.com>
To: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH] [PATCH-V2]fs/fsstress: prevent orphan and zombie processes to be left
Date: Wed, 20 Aug 2014 10:35:10 +0800 [thread overview]
Message-ID: <53F4095E.2070205@redhat.com> (raw)
parent use signal handler to deal with SIGTERM, make sure children processes
will be over before parent.
command "killall fsstress; wait;" can be used with this patch.
Signed-off-by: Zorro Lang <zlang@redhat.com>
---
Hi,
Ping ...
I have sent my patch for a long time, but no response until now. If
there are any problems you don't want to merge it, please tell me.
(Re-send this patch again now. )
Thank you,
Zorro Lang
testcases/kernel/fs/fsstress/fsstress.c | 40
++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/fs/fsstress/fsstress.c
b/testcases/kernel/fs/fsstress/fsstress.c
index 2243280..4a8a1c2 100644
--- a/testcases/kernel/fs/fsstress/fsstress.c
+++ b/testcases/kernel/fs/fsstress/fsstress.c
@@ -30,7 +30,11 @@
* http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
*/
+#include <config.h>
#include "global.h"
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
#define XFS_ERRTAG_MAX 17
@@ -227,6 +231,7 @@ int no_xfs = 0;
#else
int no_xfs = 1;
#endif
+sig_atomic_t should_stop = 0;
void add_to_flist(int, int, int);
void append_pathname(pathname_t *, char *);
@@ -273,6 +278,11 @@ void usage(void);
void write_freq(void);
void zero_freq(void);
+void sg_handler(int signum)
+{
+ should_stop = 1;
+}
+
int main(int argc, char **argv)
{
char buf[10];
@@ -297,6 +307,7 @@ int main(int argc, char **argv)
#ifndef NO_XFS
xfs_error_injection_t err_inj;
#endif
+ struct sigaction action;
errrange = errtag = 0;
umask(0);
@@ -389,7 +400,7 @@ int main(int argc, char **argv)
make_freq_table();
- while ((loopcntr <= loops) || (loops == 0)) {
+ while ((loopcntr <= loops) || (loops == 0) && !should_stop) {
if (!dirname) {
/* no directory specified */
if (!nousage)
@@ -465,17 +476,44 @@ int main(int argc, char **argv)
#endif
close(fd);
unlink(buf);
+
+
if (nproc == 1) {
procid = 0;
doproc();
} else {
+ setpgid(0, 0);
+ action.sa_handler = sg_handler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ if (sigaction(SIGTERM, &action, 0)) {
+ perror("sigaction failed");
+ exit(1);
+ }
+
for (i = 0; i < nproc; i++) {
if (fork() == 0) {
+
+ action.sa_handler = SIG_DFL;
+ sigemptyset(&action.sa_mask);
+ if (sigaction(SIGTERM, &action, 0))
+ return 1;
+#ifdef HAVE_SYS_PRCTL_H
+ prctl(PR_SET_PDEATHSIG, SIGKILL);
+ if (getppid() == 1) /* parent died already? */
+ return 0;
+#endif
procid = i;
doproc();
return 0;
}
}
+ while (wait(&stat) > 0 && !should_stop) {
+ continue;
+ }
+ action.sa_flags = SA_RESTART;
+ sigaction(SIGTERM, &action, 0);
+ kill(-getpid(), SIGTERM);
while (wait(&stat) > 0)
continue;
}
--
1.9.3
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next reply other threads:[~2014-08-20 2:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-20 2:35 Zorro Lang [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-08-12 9:52 [LTP] [PATCH] [PATCH-V2]fs/fsstress: prevent orphan and zombie processes to be left Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53F4095E.2070205@redhat.com \
--to=zlang@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.