All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: LTP List <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH] open04: add EMFILE check
Date: Mon, 19 Sep 2022 20:12:28 +0800	[thread overview]
Message-ID: <CAEemH2eDc0qfdkaOxrbEPsmOmZp7MA=exHRkjQPgxaJAh7HP2w@mail.gmail.com> (raw)
In-Reply-To: <YyRER2kntqxXG7tl@yuki>


[-- Attachment #1.1: Type: text/plain, Size: 2378 bytes --]

Cyril Hrubis <chrubis@suse.cz> wrote:

Hi!
> > > I faintly remmeber a similar patch where we decided not to work around
> > > for a test harness leaking filedescriptors into testcases.
> > >
> >
> > This also should be a solution, I searched the mailing list and got a
> > patch[1].
> > Do you mean adding that close-on-exec flag when opening fd in harness?
>
> Yes, that way you can be sure that no file descriptors are leaked to the
> tests.
>

Ok, should I send patch v2 like this below?

Note: the automation test open04 got passed but I'm not sure
if this has a side effect on logs. But from my observation, some
tests (with old-API) log can't be collected anymore.

--- a/pan/ltp-pan.c
+++ b/pan/ltp-pan.c
@@ -443,7 +443,7 @@ int main(int argc, char **argv)
        }

        if (outputfilename) {
-               if (!freopen(outputfilename, "a+", stdout)) {
+               if (!freopen(outputfilename, "a+e", stdout)) {
                        fprintf(stderr,
                                "pan(%s): Error %s (%d) opening output file
'%s'\n",
                                panname, strerror(errno), errno,
@@ -565,7 +565,7 @@ int main(int argc, char **argv)
                } else if (starts == -1)        //wjh
                {
                        FILE *f = (FILE *) - 1;
-                       if ((f = fopen(PAN_STOP_FILE, "r")) != 0) {
+                       if ((f = fopen(PAN_STOP_FILE, "r+")) != 0) {
                                printf("Got %s Stopping!\n", PAN_STOP_FILE);
                                fclose(f);
                                unlink(PAN_STOP_FILE);
@@ -1277,7 +1277,7 @@ static char *slurp(char *file)
        int fd;
        struct stat sbuf;

-       if ((fd = open(file, O_RDONLY)) < 0) {
+       if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) {
                fprintf(stderr,
                        "pan(%s): open(%s,O_RDONLY) failed.  errno:%d
 %s\n",
                        panname, file, errno, strerror(errno));
@@ -1372,7 +1372,7 @@ static void write_kmsg(const char *fmt, ...)
        FILE *kmsg;
        va_list ap;

-       if ((kmsg = fopen("/dev/kmsg", "r+")) == NULL) {
+       if ((kmsg = fopen("/dev/kmsg", "r+e")) == NULL) {
                fprintf(stderr, "Error %s: (%d) opening /dev/kmsg\n",
                                strerror(errno), errno);
                exit(1);


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 3939 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


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

  reply	other threads:[~2022-09-19 12:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15  3:10 [LTP] [PATCH] open04: add EMFILE check Li Wang
2022-09-15 12:52 ` Petr Vorel
2022-09-15 14:21   ` Cyril Hrubis
2022-09-16  1:36     ` Li Wang
2022-09-16  9:39       ` Cyril Hrubis
2022-09-19 12:12         ` Li Wang [this message]
2022-09-20  5:53           ` Li Wang
2022-09-20 14:21             ` Cyril Hrubis
2022-09-20 18:29             ` 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='CAEemH2eDc0qfdkaOxrbEPsmOmZp7MA=exHRkjQPgxaJAh7HP2w@mail.gmail.com' \
    --to=liwang@redhat.com \
    --cc=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.