All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/4] Update syscalls/bind02 to new API
Date: Fri, 4 Oct 2019 14:36:36 +0200	[thread overview]
Message-ID: <20191004123636.GA5442@rei.lan> (raw)
In-Reply-To: <20190926151331.25070-2-mdoucha@suse.cz>

Hi!
Pushed with minor changes, thanks.

* The new test library runs the test in a forked process, there is no
  need to reset the effective GID and UID in the cleanup anymore, so
  I've removed the cleanup function.

* Changed the test to explicitly test for -1 as a return value. We have
  to be pedantic here. We had bugs where syscalls returned non-zero
  value which was != -1 which broke programs that were explicitly
  testing for -1.

+ Minor things such as:
  - using TTERRNO instead of TERRNO, which means that you print the
    value of TST_ERR instead of errno which could be clobbered because
    you call close() after bind()
  - declared run() and setup() as a static functions
  - make use of SAFE_CLOSE() instead of close()

Full diff:

diff --git a/testcases/kernel/syscalls/bind/bind02.c b/testcases/kernel/syscalls/bind/bind02.c
index 532831265..65944cbe3 100644
--- a/testcases/kernel/syscalls/bind/bind02.c
+++ b/testcases/kernel/syscalls/bind/bind02.c
@@ -26,7 +26,7 @@
 #define TCP_PRIVILEGED_PORT 463
 #define TEST_USERNAME "nobody"
 
-void run(void)
+static void run(void)
 {
 	struct sockaddr_in servaddr;
 	int sockfd;
@@ -37,18 +37,18 @@ void run(void)
 	servaddr.sin_port = htons(TCP_PRIVILEGED_PORT);
 	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
 	TEST(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)));
-	close(sockfd);
+	SAFE_CLOSE(sockfd);
 
-	if (!TST_RET) {
-		tst_res(TFAIL, "bind() succeeded unexpectedly");
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "bind() returned %li, expected -1", TST_RET);
 	} else if (TST_ERR == EACCES) {
-		tst_res(TPASS, "bind() failed as expected");
+		tst_res(TPASS | TTERRNO, "bind() failed as expected");
 	} else {
-		tst_res(TFAIL | TERRNO, "Unexpected error");
+		tst_res(TFAIL | TTERRNO, "Unexpected error");
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
 	struct passwd *pw;
 	struct group *gr;
@@ -62,15 +62,8 @@ void setup(void)
 	SAFE_SETEUID(pw->pw_uid);
 }
 
-void cleanup(void)
-{
-	SAFE_SETEGID(0);
-	SAFE_SETEUID(0);
-}
-
 static struct tst_test test = {
 	.test_all = run,
 	.needs_root = 1,
 	.setup = setup,
-	.cleanup = cleanup
 };

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-10-04 12:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 15:13 [LTP] [PATCH v2 0/4] Increase bind() converage - GH#538 Martin Doucha
2019-09-26 15:13 ` [LTP] [PATCH v2 1/4] Update syscalls/bind02 to new API Martin Doucha
2019-10-04 12:36   ` Cyril Hrubis [this message]
2019-09-26 15:13 ` [LTP] [PATCH v2 2/4] Create separate .c file for include/tst_net.h Martin Doucha
2019-10-04 12:40   ` Cyril Hrubis
2019-09-26 15:13 ` [LTP] [PATCH v2 3/4] Add socket address initialization functions to tst_net library Martin Doucha
2019-10-04 12:42   ` Cyril Hrubis
2019-09-26 15:13 ` [LTP] [PATCH v2 4/4] Add connection tests for bind() Martin Doucha
2019-10-04 13:03   ` Cyril Hrubis

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=20191004123636.GA5442@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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.