Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Avinesh Kumar <akumar@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] open04.c: convert to new LTP API
Date: Thu, 1 Sep 2022 08:32:55 +0200	[thread overview]
Message-ID: <YxBSF1ZgU5wSlpi+@pevik> (raw)
In-Reply-To: <20220714060722.18894-1-akumar@suse.de>

Hi Avinesh,

I suggest to merge with these fixes:

* added free (if needed - that was in the original source)
* fixed cleanup (don't run SAFE_CLOSE() if previous SAFE_OPEN() or SAFE_MALLOC()
  failed)
* use TST_EXP_FAIL() - the same result as TST_EXP_FAIL2() with shorter code
* allocate memory needed (it's actually -2)
* #define FNAME "open04"

If it's ok, I'll merge it.

Kind regards,
Petr

diff --git testcases/kernel/syscalls/open/open04.c testcases/kernel/syscalls/open/open04.c
index e7cb533fe..16477e459 100644
--- testcases/kernel/syscalls/open/open04.c
+++ testcases/kernel/syscalls/open/open04.c
@@ -1,19 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) International Business Machines  Corp., 2001
- *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
 /*\
  * [Description]
  *
- * Verify that open(2) fails with EMFILE when
- * per-process limit on the number of open file descriptors has been reached.
+ * Verify that open(2) fails with EMFILE when per-process limit on the number
+ * of open file descriptors has been reached.
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include "tst_test.h"
 
+#define FNAME "open04"
+
 static int fds_limit, first, i;
 static int *fds;
 static char fname[20];
@@ -23,13 +26,13 @@ static void setup(void)
 	int fd;
 
 	fds_limit = getdtablesize();
-	first = SAFE_OPEN("open04", O_RDWR | O_CREAT, 0777);
+	first = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0777);
 
-	fds = SAFE_MALLOC(sizeof(int) * (fds_limit - first));
+	fds = SAFE_MALLOC(sizeof(int) * (fds_limit - first - 2));
 	fds[0] = first;
 
 	for (i = first + 1; i < fds_limit; i++) {
-		sprintf(fname, "open04.%d", i);
+		sprintf(fname, FNAME ".%d", i);
 		fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0777);
 		fds[i - first] = fd;
 	}
@@ -37,16 +40,20 @@ static void setup(void)
 
 static void run(void)
 {
-	sprintf(fname, "open04.%d", fds_limit);
-	TST_EXP_FAIL2(open(fname, O_RDWR | O_CREAT, 0777),
-				EMFILE,
-				"open(%s, O_RDWR | O_CREAT, 0777)", fname);
+	sprintf(fname, FNAME ".%d", fds_limit);
+	TST_EXP_FAIL(open(fname, O_RDWR | O_CREAT, 0777), EMFILE);
 }
 
 static void cleanup(void)
 {
+	if (!first || !fds)
+		return;
+
 	for (i = first; i < fds_limit; i++)
 		SAFE_CLOSE(fds[i - first]);
+
+	if (fds)
+		free(fds);
 }
 
 static struct tst_test test = {

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-09-01  6:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  6:07 [LTP] [PATCH] open04.c: convert to new LTP API Avinesh Kumar
2022-09-01  6:32 ` Petr Vorel [this message]
2022-09-01 11:39   ` Petr Vorel
2022-09-01 16:07   ` Avinesh Kumar
2022-09-01 20:49     ` Petr Vorel

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=YxBSF1ZgU5wSlpi+@pevik \
    --to=pvorel@suse.cz \
    --cc=akumar@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox