Skip to contentSkip to conversation

syscalls/chown01: Fix test file creation

PATCH Applied Jungsoo Son 3 participants 4 messages Jun 8, 2013 – Jun 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/chown01: Fix test file creation

There is a bug in the code to create the file and the code is very intricate. So replace it with SAFE_FILE_PRINTF().

---
 testcases/kernel/syscalls/chown/chown01.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/testcases/kernel/syscalls/chown/chown01.c
index 50b9ea5..14b699b 100644

testcases/kernel/syscalls/chown/chown01.c +6 -14
@@ -116,9 +116,7 @@
 #include <signal.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "chown01";
 int TST_TOTAL = 1;
@@ -126,8 +124,10 @@ int TST_TOTAL = 1;
 int exp_enos[] = { 0, 0 };
 
 char fname[255];
-int fd, uid, gid;
-char *buf = "davef";
+int uid, gid;
+
+static void setup();
+static void cleanup();
 
 int main(int ac, char **av)
 {
@@ -163,7 +163,7 @@ int main(int ac, char **av)
 
 }
 
-void setup()
+static void setup()
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -176,17 +176,11 @@ void setup()
 	gid = getegid();
 
 	sprintf(fname, "t_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	else if (write(fd, &buf, strlen(buf)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "write(%s, &buf, strlen(buf)) failed", fname);
-	else if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",

fname);
+
+ SAFE_FILE_PRINTF(cleanup, fname, "davef");
}

-void cleanup()
+static void cleanup()
{
TEST_CLEANUP;

Signature · 13 lines
1.7.9.5


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

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

Quoted 9 lines

From: "Jungsoo Son" <[email protected]>
To: [email protected]
Sent: Saturday, 8 June, 2013 4:54:26 AM
Subject: [LTP] [PATCH] syscalls/chown01: Fix test file creation

There is a bug in the code to create the file and the code is very intricate. So replace it with SAFE_FILE_PRINTF().

Please add void to setup()/cleanup(). The rest looks OK.

Regards,
Jan

Quoted 21 lines
---
 testcases/kernel/syscalls/chown/chown01.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/chown/chown01.c +1 -3
index 50b9ea5..14b699b 100644
@@ -116,9 +116,7 @@
 #include <signal.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "chown01";
 int TST_TOTAL = 1;

testcases/kernel/syscalls/chown/chown01.c int TST_TOTAL = 1; · line 130

Quoted 9 lines
testcases/kernel/syscalls/chown/chown01.c +4 -2
@@ -126,8 +124,10 @@ int TST_TOTAL = 1;
 int exp_enos[] = { 0, 0 };
 
 char fname[255];
-int fd, uid, gid;
-char *buf = "davef";
+int uid, gid;
+
+static void setup();
+static void cleanup();

in these two above ^^

testcases/kernel/syscalls/chown/chown01.c int main(int ac, char **av) · line 166

Quoted 9 lines
testcases/kernel/syscalls/chown/chown01.c +1 -1
 int main(int ac, char **av)
 {
@@ -163,7 +163,7 @@ int main(int ac, char **av)
 
 }
 
-void setup()
+static void setup()

here

Quoted 12 lines
testcases/kernel/syscalls/chown/chown01.c +0 -5
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -176,17 +176,11 @@ void setup()
 	gid = getegid();
 
 	sprintf(fname, "t_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	else if (write(fd, &buf, strlen(buf)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,

testcases/kernel/syscalls/chown/chown01.c void setup() · line 184

Quoted 10 lines
testcases/kernel/syscalls/chown/chown01.c +3 -4
-			 "write(%s, &buf, strlen(buf)) failed", fname);
-	else if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",
 fname);
+
+	SAFE_FILE_PRINTF(cleanup, fname, "davef");
 }
 
-void cleanup()
+static void cleanup()

and here.

Quoted 7 lines
testcases/kernel/syscalls/chown/chown01.c +0 -1
 {
 	TEST_CLEANUP;
 
--

1.7.9.5

Quoted 11 lines

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

I added 'void' to setup() and cleanup() as your mention.

There is a bug in the code to create the file and the code is very intricate. So replace it with SAFE_FILE_PRINTF().

---
 testcases/kernel/syscalls/chown/chown01.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/chown/chown01.c +9 -15
index 50b9ea5..d95564e 100644
@@ -116,9 +116,7 @@
 #include <signal.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "chown01";
 int TST_TOTAL = 1;
@@ -126,8 +124,10 @@ int TST_TOTAL = 1;
 int exp_enos[] = { 0, 0 };
 
 char fname[255];
-int fd, uid, gid;
-char *buf = "davef";
+int uid, gid;
+
+static void setup(void);
+static void cleanup(void);
 
 int main(int ac, char **av)
 {
@@ -163,7 +163,7 @@ int main(int ac, char **av)
 
 }
 
-void setup()
+static void setup(void)
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
@@ -176,17 +176,11 @@ void setup()
 	gid = getegid();
 
 	sprintf(fname, "t_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	else if (write(fd, &buf, strlen(buf)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "write(%s, &buf, strlen(buf)) failed", fname);
-	else if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", fname);
+
+	SAFE_FILE_PRINTF(cleanup, fname, "davef");
 }
 
-void cleanup()
+static void cleanup(void)
 {
 	TEST_CLEANUP;
 
Signature · 1 line
1.7.9.5
Quoted 89 lines

-----Original Message-----
From: Jan Stancek [mailto:[email protected]]
Sent: Monday, June 10, 2013 11:08 PM
To: Jungsoo Son
Cc: [email protected]
Subject: Re: [LTP] [PATCH] syscalls/chown01: Fix test file creation

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

Quoted 9 lines

From: "Jungsoo Son" <[email protected]>
To: [email protected]
Sent: Saturday, 8 June, 2013 4:54:26 AM
Subject: [LTP] [PATCH] syscalls/chown01: Fix test file creation

There is a bug in the code to create the file and the code is very intricate. So replace it with SAFE_FILE_PRINTF().

Please add void to setup()/cleanup(). The rest looks OK.

Regards,
Jan

Quoted 2 lines
---
 testcases/kernel/syscalls/chown/chown01.c |   24 +++++++++--------------

-

Quoted 19 lines
 1 file changed, 9 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/chown/chown01.c +1 -3
index 50b9ea5..14b699b 100644
@@ -116,9 +116,7 @@
 #include <signal.h>
 #include "test.h"
 #include "usctest.h"
-
-void setup();
-void cleanup();
+#include "safe_macros.h"
 
 char *TCID = "chown01";
 int TST_TOTAL = 1;

testcases/kernel/syscalls/chown/chown01.c int TST_TOTAL = 1; int exp_enos[] = { 0, 0 }; · line 129

Quoted 8 lines
testcases/kernel/syscalls/chown/chown01.c +4 -2
@@ -126,8 +124,10 @@ int TST_TOTAL = 1;  int exp_enos[] = { 0, 0 };
 
 char fname[255];
-int fd, uid, gid;
-char *buf = "davef";
+int uid, gid;
+
+static void setup();
+static void cleanup();

in these two above ^^

testcases/kernel/syscalls/chown/chown01.c int main(int ac, char **av) · line 166

Quoted 9 lines
testcases/kernel/syscalls/chown/chown01.c +1 -1
 int main(int ac, char **av)
 {
@@ -163,7 +163,7 @@ int main(int ac, char **av)
 
 }
 
-void setup()
+static void setup()

here

Quoted 20 lines
testcases/kernel/syscalls/chown/chown01.c +0 -0
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup); @@ -176,17 +176,11 @@ void

setup()

testcases/kernel/syscalls/chown/chown01.c +0 -8
 	gid = getegid();
 
 	sprintf(fname, "t_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	else if (write(fd, &buf, strlen(buf)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "write(%s, &buf, strlen(buf)) failed", fname);
-	else if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",

fname);

testcases/kernel/syscalls/chown/chown01.c +2 -0
+
+	SAFE_FILE_PRINTF(cleanup, fname, "davef");
 }
Quoted 23 lines

testcases/kernel/syscalls/chown/chown01.c

Quoted 2 lines
testcases/kernel/syscalls/chown/chown01.c +1 -1
-void cleanup()
+static void cleanup()

and here.

Quoted 18 lines

{
TEST_CLEANUP;

--
1.7.9.5

----------------------------------------------------------------------
-------- How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations 2. Dashboards that offer high-level views of enterprise services 3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Applied
#3 lore raw
Quoted 7 lines · Jungsoo Son

I added 'void' to setup() and cleanup() as your mention.

There is a bug in the code to create the file and the code is very intricate. So replace it with SAFE_FILE_PRINTF().

Applied, thank you.

Wanlong Gao

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list