Skip to contentSkip to conversation

This fix make sure the function "setpgid" get invoked in the right time in setpgid03 test02.

PATCH In review Jin Li 2 participants 4 messages Dec 26, 2011 – Jan 5, 2012 2 messages not in the archive

lore
Share & tools
lore

Jin Li

author
#0 lore raw

PATCH 1/1 This fix make sure the function "setpgid" get invoked in the right time in setpgid03 test02.

In setpgid03 test02, the function "setpgid" is likely to be invoked

in father process before the function "execlp" get invoked in child

process. Sometimes The performance or NFS file system may cause that

the switch of context could not be done even after the 1 second sleeping

of father process. In this case, the setpgid will get unexpected error

number. Add sync mechanism to insure the 'setpgid' get invoked in the right

order.

---
 testcases/kernel/syscalls/setpgid/setpgid03.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/setpgid/setpgid03.c +12 -3
index a894389..a011419 100644
@@ -46,6 +46,7 @@
 
 char *TCID = "setpgid03";
 int TST_TOTAL = 1;
+char temp_file[64];
 
 void do_child(void);
 void setup(void);
@@ -60,6 +61,7 @@ int main(int ac, char **av)
 
 	int lc;			/* loop counter */
 	char *msg;		/* message returned from parse_opts */
+	char cmd_line[1024];    /* command line for exec */
 
 	/* parse standard options */
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
@@ -74,6 +76,10 @@ int main(int ac, char **av)
 	 */
 	setup();
 
+	sprintf(temp_file,"/tmp/%s_file",TCID);
+
+	sprintf(cmd_line,"touch %s;sleep 5s;rm -f %s", temp_file, temp_file);
+
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
 		/* reset Tst_count in case we are looping */
@@ -132,12 +138,15 @@ int main(int ac, char **av)
 
 		}
 		if (pid == 0) {
-			if (execlp("sleep", "sleep", "3", NULL) < 0) {
+			if (execlp("sh", "sh", "-c", cmd_line, NULL) < 0) {
 				perror("exec failed");
 			}
 			exit(127);
 		} else {
-			sleep(1);
+			while ( access(temp_file, F_OK) != 0 ) {
+                            sleep(1);
+			}
+
 			rval = setpgid(pid, getppid());
 			if (errno == EACCES) {
 				tst_resm(TPASS, "setpgid SUCCEEDED to set "
@@ -203,4 +212,4 @@ void cleanup(void)
 	 */
 	TEST_CLEANUP;
 
-}
\ No newline at end of file
+}
Signature · 13 lines
1.6.3.1


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 13 lines

In setpgid03 test02, the function "setpgid" is likely to be invoked in father process before the function "execlp" get invoked in child process. Sometimes The performance or NFS file system may cause that the switch of context could not be done even after the 1 second sleeping of father process. In this case, the setpgid will get unexpected error number. Add sync mechanism to insure the 'setpgid' get invoked in the right order.

---
void do_child(void);
void setup(void);

testcases/kernel/syscalls/setpgid/setpgid03.c int main(int ac, char **av) · line 64

Quoted 4 lines
testcases/kernel/syscalls/setpgid/setpgid03.c +1 -0
@@ -60,6 +61,7 @@ int main(int ac, char **av)
 
 	int lc;			/* loop counter */
 	char *msg;		/* message returned from parse_opts */
+	char cmd_line[1024];    /* command line for exec */

Please don't add trivial comments (and remove trivial comments that are in the code allready).

testcases/kernel/syscalls/setpgid/setpgid03.c int main(int ac, char **av) · line 79

Quoted 7 lines
testcases/kernel/syscalls/setpgid/setpgid03.c +1 -0
 	/* parse standard options */
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
@@ -74,6 +76,10 @@ int main(int ac, char **av)
 	 */
 	setup();
 
+	sprintf(temp_file,"/tmp/%s_file",TCID);

Maybe it would be better to use tst_tmpdir() so the test has it's own and unique directory to create temp files instead of utlizing /tmp directly. (several instances of the test could then run at once).

testcases/kernel/syscalls/setpgid/setpgid03.c int main(int ac, char **av) · line 81

Quoted 1 line
testcases/kernel/syscalls/setpgid/setpgid03.c +1 -0
+	sprintf(cmd_line,"touch %s;sleep 5s;rm -f %s", temp_file, temp_file);

Hm, I still don't think the race is gone now. As once the shell calls rm, it exits, so most likely when the parent calls setpgid() the process is gone (and from the original source it seems that the process should be running while the parent calls setpgid()). And moreover the file doesn't need to be created when the parent tries access() for the first time.

Quoted 22 lines
testcases/kernel/syscalls/setpgid/setpgid03.c +5 -2
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
 		/* reset Tst_count in case we are looping */
@@ -132,12 +138,15 @@ int main(int ac, char **av)
 
 		}
 		if (pid == 0) {
-			if (execlp("sleep", "sleep", "3", NULL) < 0) {
+			if (execlp("sh", "sh", "-c", cmd_line, NULL) < 0) {
 				perror("exec failed");
 			}
 			exit(127);
 		} else {
-			sleep(1);
+			while ( access(temp_file, F_OK) != 0 ) {
+                            sleep(1);
+			}
+
 			rval = setpgid(pid, getppid());
 			if (errno == EACCES) {
 				tst_resm(TPASS, "setpgid SUCCEEDED to set "

testcases/kernel/syscalls/setpgid/setpgid03.c void cleanup(void) · line 213

Quoted 2 lines
testcases/kernel/syscalls/setpgid/setpgid03.c +0 -0
@@ -203,4 +212,4 @@ void cleanup(void)
 	 */
 	TEST_CLEANUP;

And please use the checkpatch next time.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Hi!
Could you please resend this without the html formatting. (it's commont nettiquete not to send these into mailing lists)

Quoted 129 lines

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">Hi Cyril <br>
<br>
Please see the feed back below.<br>
</font><br>
Cyril Hrubis &#20889;&#36947;:
<blockquote cite="mid:[email protected]"
type="cite">
<pre wrap="">Hi!
</pre>
<blockquote type="cite">
<pre wrap="">In setpgid03 test02, the function "setpgid" is likely to be invoked
in father process before the function "execlp" get invoked in child process. Sometimes The performance or NFS file system may cause that the switch of context could not be done even after the 1 second sleeping of father process. In this case, the setpgid will get unexpected error number. Add sync mechanism to insure the 'setpgid' get invoked in the right order.

Signed-off-by Jin Li <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a>

---
void do_child(void);
void setup(void);

testcases/kernel/syscalls/setpgid/setpgid03.c +1 -0
@@ -60,6 +61,7 @@ int main(int ac, char **av)
 
 	int lc;			/* loop counter */
 	char *msg;		/* message returned from parse_opts */
+	char cmd_line[1024];    /* command line for exec */
    </pre>
  </blockquote>
  <pre wrap=""><!---->

Please don't add trivial comments (and remove trivial comments that are in the code allready).
</pre>
</blockquote>
Accepted <br>
<blockquote cite="mid:[email protected]"
type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap=""> /* parse standard options */

testcases/kernel/syscalls/setpgid/setpgid03.c +1 -0
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
@@ -74,6 +76,10 @@ int main(int ac, char **av)
 	 */
 	setup();
 
+	sprintf(temp_file,"/tmp/%s_file",TCID);
    </pre>
  </blockquote>
  <pre wrap=""><!---->

Maybe it would be better to use tst_tmpdir() so the test has it's own and unique directory to create temp files instead of utlizing /tmp directly. (several instances of the test could then run at once).
</pre>
</blockquote>
Accepted<br>
<blockquote cite="mid:[email protected]"
type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">

    <pre wrap="">+	sprintf(cmd_line,"touch %s;sleep 5s;rm -f %s", temp_file, temp_file);
    </pre>

</blockquote>
<pre wrap=""><!---->
Hm, I still don't think the race is gone now. As once the shell calls rm, it exits, so most likely when the parent calls setpgid() the process is gone (and from the original source it seems that the process should be running while the parent calls setpgid()). And moreover the file doesn't need to be created when the parent tries access() for the first time.
</pre>
</blockquote>
I'm afraid that I don't agree with you. The child and father get the same schedule priority. <br>
So during the 5s sleeping of father, the child have enough time to run "setpgid".<br>
Here is just a execution sync-up that make sure the "execlp" is invoked&nbsp; just&nbsp; before&nbsp; <br>
the "setpgid" get invoked in father<br>
<br>
Thanks,<br>
<br>
Jin<br>
<br>
<blockquote cite="mid:[email protected]"
type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">

    <pre wrap=""> 	for (lc = 0; TEST_LOOPING(lc); lc++) {
testcases/kernel/syscalls/setpgid/setpgid03.c +5 -2
 		/* reset Tst_count in case we are looping */
@@ -132,12 +138,15 @@ int main(int ac, char **av)
 
 		}
 		if (pid == 0) {
-			if (execlp("sleep", "sleep", "3", NULL) &lt; 0) {
+			if (execlp("sh", "sh", "-c", cmd_line, NULL) &lt; 0) {
 				perror("exec failed");
 			}
 			exit(127);
 		} else {
-			sleep(1);
+			while ( access(temp_file, F_OK) != 0 ) {
+                            sleep(1);
+			}
+
 			rval = setpgid(pid, getppid());
 			if (errno == EACCES) {
 				tst_resm(TPASS, "setpgid SUCCEEDED to set "
@@ -203,4 +212,4 @@ void cleanup(void)
 	 */
 	TEST_CLEANUP;
    </pre>
  </blockquote>

<pre wrap=""><!---->
And please use the checkpatch next time.

</pre>
</blockquote>
</body>
</html>

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi!

Quoted 5 lines

I'm afraid that I don't agree with you. The child and father get the same schedule priority. So during the 5s sleeping of father, the child have enough time to run "setpgid". Here is just a execution sync-up that make sure the "execlp" is invoked just before the "setpgid" get invoked in father.

Well yes and no. This is exactly the case where the tests would work fine most of the time, but may generate false regressions from time to time.

You can't really say that some process will be schedulled during some time on multitasking system, you may only say that it's likely.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list