public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list <ltp-list@lists.sf.net>
Subject: Re: [LTP] [PATCH] Fix FILECAPS test hanging for more than 12 hours
Date: Tue, 4 May 2010 17:33:16 -0500	[thread overview]
Message-ID: <20100504223315.GA16615@us.ibm.com> (raw)
In-Reply-To: <y2l364299f41005041402uce37fd2axc6f1fc7f7df70497@mail.gmail.com>

Quoting Garrett Cooper (yanegomi@gmail.com):
> On Tue, May 4, 2010 at 12:22 PM, Serge E. Hallyn <serue@us.ibm.com> wrote:
> > Quoting Subrata Modak (subrata@linux.vnet.ibm.com):
> >> Serge, please add a Sign-off.
> >
> > It's there in the patch in your attachment...
> 
> Serge,
>     Please address the items in the previous review and we'll get it committed.
> Thanks,
> -Garrett

Ah, I see.  You only broke the testcase to get my attention so you
could get me to use more appropriate ltp helpers.  Sneaky!  And since
I learned some things in the process, great.  Hopefully I'll get them
right when I submit the next set.

From 2077a47e9cd2f85a8e54695c71396a1a8397d3d6 Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue@us.ibm.com>
Date: Wed, 28 Apr 2010 11:26:58 -0500
Subject: [PATCH 1/1] make filecaps tests succeed

Most of these are belated cleanup after the move to using /opt/ltp.
But come on, replacing 'return' with tst_exit(), are you just trying
to mess with my head?

Changelog: may 4: address Garrett's feedback
  1. single return 0 in print_caps.c
  2. use $TMP if defined for location of caps_fifo
  3. use tst_brkm in place of tst_resm.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
 testcases/kernel/security/filecaps/filecapstest.sh |   10 +++-
 testcases/kernel/security/filecaps/print_caps.c    |    5 +-
 .../kernel/security/filecaps/verify_caps_exec.c    |   48 ++++++++------------
 3 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/testcases/kernel/security/filecaps/filecapstest.sh b/testcases/kernel/security/filecaps/filecapstest.sh
index 43582dc..8e2ba11 100755
--- a/testcases/kernel/security/filecaps/filecapstest.sh
+++ b/testcases/kernel/security/filecaps/filecapstest.sh
@@ -22,8 +22,12 @@
 echo "Running in:"
 #rm -f print_caps
 #cp $LTPROOT/testcases/bin/print_caps .
-mkfifo caps_fifo
-chmod 777 caps_fifo
+#FIFOFILE="$LTPROOT/testcases/bin/caps_fifo"
+TMP=${TMP:=/tmp}
+FIFOFILE="$TMP/caps_fifo"
+rm -f $FIFOFILE
+mkfifo $FIFOFILE
+chmod 777 $FIFOFILE
 exit_code=0
 echo "cap_sys_admin tests"
 verify_caps_exec 0
@@ -46,5 +50,5 @@ if [ $tmp -ne 0 ]; then
 	exit_code=$tmp
 fi
 
-unlink caps_fifo
+unlink $FIFOFILE
 exit $exit_code
diff --git a/testcases/kernel/security/filecaps/print_caps.c b/testcases/kernel/security/filecaps/print_caps.c
index f0e9bce..1c3fc1b 100644
--- a/testcases/kernel/security/filecaps/print_caps.c
+++ b/testcases/kernel/security/filecaps/print_caps.c
@@ -36,7 +36,7 @@
 #include <sys/capability.h>
 #endif
 
-#define FIFOFILE "caps_fifo"
+#define FIFOFILE "/tmp/caps_fifo"
 
 int main(int argc, char *argv[])
 {
@@ -65,7 +65,6 @@ int main(int argc, char *argv[])
 	close(fd);
 
 	cap_free(cap);
-#else
-	return 0;
 #endif
+	return 0;
 }
diff --git a/testcases/kernel/security/filecaps/verify_caps_exec.c b/testcases/kernel/security/filecaps/verify_caps_exec.c
index 5250007..c3f65a9 100644
--- a/testcases/kernel/security/filecaps/verify_caps_exec.c
+++ b/testcases/kernel/security/filecaps/verify_caps_exec.c
@@ -43,7 +43,7 @@
 #include <sys/prctl.h>
 #include <test.h>
 
-#define TSTPATH "./print_caps"
+#define TSTPATH "print_caps"
 char *TCID = "filecaps";
 int TST_TOTAL=1;
 
@@ -70,7 +70,7 @@ void print_my_caps()
 	cap_free(txt);
 }
 
-int drop_root(int keep_perms)
+void drop_root(int keep_perms)
 {
 	int ret;
 
@@ -78,16 +78,19 @@ int drop_root(int keep_perms)
 		prctl(PR_SET_KEEPCAPS, 1);
 	ret = setresuid(1000, 1000, 1000);
 	if (ret) {
-		perror("setresuid");
-		tst_resm(TFAIL, "Error dropping root privs\n");
+		tst_brkm(TFAIL | TERRNO, tst_exit, "Error dropping root privs\n");
 		tst_exit();
 	}
 	if (keep_perms) {
 		cap_t cap = cap_from_text("=eip");
-		cap_set_proc(cap);
+		int ret;
+		if (!cap)
+			tst_brkm(TBROK | TERRNO, tst_exit, "cap_from_text failed\n");
+		ret = cap_set_proc(cap);
+		if (ret < 0)
+			tst_brkm(TBROK | TERRNO, tst_exit, "cap_set_proc failed\n");
 		cap_free(cap);
 	}
-	tst_exit();
 }
 
 int perms_test(void)
@@ -114,17 +117,14 @@ int perms_test(void)
 	return ret;
 }
 
-#define FIFOFILE "caps_fifo"
+#define FIFOFILE "/tmp/caps_fifo"
 void create_fifo(void)
 {
 	int ret;
 
 	ret = mkfifo(FIFOFILE, S_IRWXU | S_IRWXG | S_IRWXO);
-	if (ret == -1 && errno != EEXIST) {
-		perror("mkfifo");
-		tst_resm(TFAIL, "failed creating %s\n", FIFOFILE);
-		tst_exit();
-	}
+	if (ret == -1 && errno != EEXIST)
+		tst_brkm(TFAIL | TERRNO, tst_exit, "failed creating %s\n", FIFOFILE);
 }
 
 void write_to_fifo(char *buf)
@@ -142,11 +142,8 @@ void read_from_fifo(char *buf)
 
 	memset(buf, 0, 200);
 	fd = open(FIFOFILE, O_RDONLY);
-	if (fd < 0) {
-		perror("open");
-		tst_resm(TFAIL, "Failed opening fifo\n");
-		tst_exit();
-	}
+	if (fd < 0)
+		tst_brkm(TFAIL | TERRNO, tst_exit, "Failed opening fifo\n");
 	read(fd, buf, 199);
 	close(fd);
 }
@@ -162,23 +159,18 @@ int fork_drop_and_exec(int keepperms, cap_t expected_caps)
 	static int seqno = 0;
 
 	pid = fork();
-	if (pid < 0) {
-		perror("fork");
-		tst_resm(TFAIL, "%s: failed fork\n", __FUNCTION__);
-		tst_exit();
-	}
+	if (pid < 0)
+		tst_brkm(TFAIL | TERRNO, tst_exit, "%s: failed fork\n", __FUNCTION__);
 	if (pid == 0) {
 		drop_root(keepperms);
 		print_my_caps();
 		sprintf(buf, "%d", seqno);
 		ret = execlp(TSTPATH, TSTPATH, buf, NULL);
-		perror("execl");
-		tst_resm(TFAIL, "%s: exec failed\n", __FUNCTION__);
 		capstxt = cap_to_text(expected_caps, NULL);
 		snprintf(buf, 200, "failed to run as %s\n", capstxt);
 		cap_free(capstxt);
 		write_to_fifo(buf);
-		tst_exit();
+		tst_brkm(TFAIL, tst_exit, "%s: exec failed\n", __FUNCTION__);
 	} else {
 		p = buf;
 		while (1) {
@@ -191,10 +183,8 @@ int fork_drop_and_exec(int keepperms, cap_t expected_caps)
 				c, s, seqno);
 		}
 		p = index(buf, '.')+1;
-		if (p==(char *)1) {
-			tst_resm(TFAIL, "got a bad message from print_caps\n");
-			tst_exit();
-		}
+		if (p==(char *)1)
+			tst_brkm(TFAIL, tst_exit, "got a bad message from print_caps\n");
 		actual_caps = cap_from_text(p);
 		if (cap_compare(actual_caps, expected_caps) != 0) {
 			capstxt = cap_to_text(expected_caps, NULL);
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2010-05-04 22:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 18:20 [LTP] [PATCH] Fix FILECAPS test hanging for more than 12 hours Subrata Modak
2010-05-04 19:22 ` Serge E. Hallyn
2010-05-04 21:02   ` Garrett Cooper
2010-05-04 22:33     ` Serge E. Hallyn [this message]
2010-05-05  5:19       ` Garrett Cooper
2010-05-05 14:18         ` Serge E. Hallyn
2010-05-06  7:50           ` Garrett Cooper
2010-05-06 13:55             ` Serge E. Hallyn
2010-05-06 14:28               ` Subrata Modak

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=20100504223315.GA16615@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=ltp-list@lists.sf.net \
    --cc=yanegomi@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox