Skip to contentSkip to conversation

pan/ltp-pan.c: fix file descriptors leaks

PATCH New Feiyu Zhu 4 participants 9 messages Nov 9, 2020 – Nov 19, 2020

lore
Share & tools
lore

Feiyu Zhu

author
#0 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

ltp-pan will leak file descriptors of fopen() into the child process of the test case, fix this problem by using mode "e" for fopen().

---
 pan/ltp-pan.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
pan/ltp-pan.c +3 -3
index 8b9fbe5..25e554f 100644
@@ -336,7 +336,7 @@ int main(int argc, char **argv)
 		if (!strcmp(logfilename, "-")) {
 			logfile = stdout;
 		} else {
-			if ((logfile = fopen(logfilename, "a+")) == NULL) {
+			if ((logfile = fopen(logfilename, "a+e")) == NULL) {
 				fprintf(stderr,
 					"pan(%s): Error %s (%d) opening log file '%s'\n",
 					panname, strerror(errno), errno,
@@ -453,7 +453,7 @@ int main(int argc, char **argv)
 	}
 
 	if (failcmdfilename) {
-		if (!(failcmdfile = fopen(failcmdfilename, "a+"))) {
+		if (!(failcmdfile = fopen(failcmdfilename, "a+e"))) {
 			fprintf(stderr,
 				"pan(%s): Error %s (%d) opening fail cmd file '%s'\n",
 				panname, strerror(errno), errno,
@@ -463,7 +463,7 @@ int main(int argc, char **argv)
 	}
 
 	if (tconfcmdfilename) {
-		tconfcmdfile = fopen(tconfcmdfilename, "a+");
+		tconfcmdfile = fopen(tconfcmdfilename, "a+e");
 		if (!tconfcmdfile) {
 			fprintf(stderr, "pan(%s): Error %s (%d) opening "
 				"tconf cmd file '%s'\n", panname,
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi!

Quoted 2 lines

ltp-pan will leak file descriptors of fopen() into the child process of the test case, fix this problem by using mode "e" for fopen().

Looks good, however this is supported since glibc 2.7 and it does not seem to be supported on musl libc either.

I guess that it would be better just to close these files after a fork in the runchild() function, but that would mean that we would have to pass all these files as paramters to the function as well.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Cyril, Feiyu

Quoted 7 lines

Hi!

Quoted 2 lines

ltp-pan will leak file descriptors of fopen() into the child process of the test case, fix this problem by using mode "e" for fopen().

Looks good, however this is supported since glibc 2.7 and it does not seem to be supported on musl libc either.

Yes, musl-libc doesn't support "e" mode for fopen[1].

[1]https://git.musl-libc.org/cgit/musl/tree/src/stdio/fopen.c

Quoted 3 lines

I guess that it would be better just to close these files after a fork in the runchild() function, but that would mean that we would have to pass all these files as paramters to the function as well.

+1

Quoted 1 line
#3 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Cyril

Quoted 9 lines

Hi Cyril, Feiyu

Quoted 7 lines

Hi!

Quoted 2 lines

ltp-pan will leak file descriptors of fopen() into the child process of the test case, fix this problem by using mode "e" for fopen().

Looks good, however this is supported since glibc 2.7 and it does not seem to be supported on musl libc either.

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

Quoted 11 lines

[1]https://git.musl-libc.org/cgit/musl/tree/src/stdio/fopen.c

Quoted 3 lines

I guess that it would be better just to close these files after a fork in the runchild() function, but that would mean that we would have to pass all these files as paramters to the function as well.

+1

Quoted 1 line
#4 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi!

Quoted 9 lines
Quoted 1 line

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

To be honest I haven't had used ltp-pan for last two years, so if that change works for everyone still using it, then we can go ahead with it.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Cyril

Quoted 6 lines

Hi!

Quoted 5 lines
Quoted 1 line

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

Quoted 7 lines
Quoted 4 lines

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

To be honest I haven't had used ltp-pan for last two years, so if that change works for everyone still using it, then we can go ahead with it.

OK. I will wait a week. If nobody has objection, I will merge it.

Best Regards
Yang Xu

Quoted 1 line
#6 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Petr

Quoted 10 lines

Hi Cyril

Quoted 9 lines

Hi!

Quoted 8 lines
Quoted 1 line

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

To be honest I haven't had used ltp-pan for last two years, so if that change works for everyone still using it, then we can go ahead with it.

OK. I will wait a week. If nobody has objection, I will merge it.

I plan to merge this patch today. Before it, I want to listen some advise from you( IMO, you know musl-libc a lot and other libc on embedded system).

Quoted 5 lines

Best Regards
Yang Xu

Quoted 1 line
#7 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Xu,

Quoted 11 lines

Hi Petr

Quoted 8 lines

Hi Cyril

Quoted 7 lines

Hi!

Quoted 6 lines
Quoted 1 line

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

To be honest I haven't had used ltp-pan for last two years, so if that change works for everyone still using it, then we can go ahead with it.

OK. I will wait a week. If nobody has objection, I will merge it.

I plan to merge this patch today. Before it, I want to listen some advise from you( IMO, you know musl-libc a lot and other libc on embedded system).

Should be safe.

Kind regards,
Petr

Quoted 2 lines
Quoted 2 lines

Best Regards
Yang Xu

#8 lore raw

PATCH 1/1 pan/ltp-pan.c: fix file descriptors leaks

Hi Feiyu

Pushed, thanks!

Best Regards
Yang Xu

Quoted 35 lines

Hi Xu,

Quoted 11 lines

Hi Petr

Quoted 8 lines

Hi Cyril

Quoted 7 lines

Hi!

Quoted 6 lines
Quoted 1 line

Yes, musl-libc doesn't support "e" mode for fopen[1].

Sorry, I ignore __fmodeflags function, musl libc supports "e" mode since 0.9.7 after this commit 8582a6e9f ("add 'e' modifier (close-on-exec) to fopen and fdopen").

https://git.musl-libc.org/cgit/musl/commit/src?id=8582a6e9f25dd7b87d72961f58008052a4cac473

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

It is about 8 years since musl libc fopen() supports "e". glibc2.7 fopen() supports "e" is about 13 years. Maybe we can use "e" mode now?

To be honest I haven't had used ltp-pan for last two years, so if that change works for everyone still using it, then we can go ahead with it.

OK. I will wait a week. If nobody has objection, I will merge it.

I plan to merge this patch today. Before it, I want to listen some advise from you( IMO, you know musl-libc a lot and other libc on embedded system).

Should be safe.

Kind regards,
Petr

Quoted 2 lines
Quoted 2 lines

Best Regards
Yang Xu

.