* [LTP] [PATCH] kill05: fix race condition in do_master_child
@ 2011-04-27 6:31 Jan Stancek
2011-05-04 16:58 ` Garrett Cooper
0 siblings, 1 reply; 2+ messages in thread
From: Jan Stancek @ 2011-04-27 6:31 UTC (permalink / raw)
To: ltp-list
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
There is a race condition when starting child. Master child can go
forward before child changes its reuid.
Fix this by waiting until child is ready.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
testcases/kernel/syscalls/kill/kill05.c | 25 +++++++++++++++++--------
1 files changed, 17 insertions(+), 8 deletions(-)
[-- Attachment #2: 0001-kill05-fix-race-condition-in-do_master_child.patch --]
[-- Type: text/x-patch, Size: 1146 bytes --]
diff --git a/testcases/kernel/syscalls/kill/kill05.c b/testcases/kernel/syscalls/kill/kill05.c
index e44b690..fe34788 100644
--- a/testcases/kernel/syscalls/kill/kill05.c
+++ b/testcases/kernel/syscalls/kill/kill05.c
@@ -130,6 +130,16 @@ int main(int ac, char **av)
tst_exit();
}
+void wait_for_flag(int value)
+{
+ while (1) {
+ if (*flag == value)
+ break;
+ else
+ sleep(1);
+ }
+}
+
/*
* do_master_child()
*/
@@ -160,6 +170,7 @@ void do_master_child(char **av)
perror("setreuid failed (in child)");
exit(1);
}
+ *flag = 1;
#ifdef UCLINUX
if (self_exec(av[0], "") < 0) {
perror("self_exec failed");
@@ -175,10 +186,13 @@ void do_master_child(char **av)
exit(1);
}
+ /* wait until child sets its euid */
+ wait_for_flag(1);
+
TEST(kill(pid1, TEST_SIG));
/* signal the child that we're done */
- *flag = 1;
+ *flag = 2;
if (waitpid(pid1, &status, 0) == -1) {
perror("waitpid failed");
@@ -204,13 +218,8 @@ void do_master_child(char **av)
void do_child()
{
-
- while (1) {
- if (*flag == 1)
- exit(0);
- else
- sleep(1);
- }
+ wait_for_flag(2);
+ exit(0);
}
void setup(void)
[-- Attachment #3: Type: text/plain, Size: 355 bytes --]
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-04 16:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-27 6:31 [LTP] [PATCH] kill05: fix race condition in do_master_child Jan Stancek
2011-05-04 16:58 ` Garrett Cooper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox