[LTP] [PATCH] open04: add EMFILE check

Li Wang liwang@redhat.com
Mon Sep 19 14:12:28 CEST 2022


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220919/2307aca6/attachment.htm>


More information about the ltp mailing list