This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patchv2] Minor O_CLOEXEC optimization, "regression" fix
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Kai Tietz <ktietz at redhat dot com>
- Cc: gdb-patches at sourceware dot org, Tom Tromey <tromey at redhat dot com>
- Date: Wed, 9 Oct 2013 16:41:34 +0200
- Subject: [patchv2] Minor O_CLOEXEC optimization, "regression" fix
- Authentication-results: sourceware.org; auth=none
- References: <20131008183214 dot GB27355 at host2 dot jankratochvil dot net> <87li23fsym dot fsf at fleche dot redhat dot com> <20131009131016 dot GA1603 at host2 dot jankratochvil dot net> <173490856 dot 4156973 dot 1381325657769 dot JavaMail dot root at redhat dot com>
On Wed, 09 Oct 2013 15:34:17 +0200, Kai Tietz wrote:
> So yes, probing for EINVAL seems to me like a valid way to probe for valid
> arguments here.
OK, therefore updated the patch.
No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu.
It still reduces the number of syscalls.
Thanks,
Jan
gdb/
2013-10-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* common/filestuff.c (gdb_fopen_cloexec): Remove initialization of
result variable. Rename variable fopen_e_ever_failed to
fopen_e_ever_failed_einval. Retry fopen only for errno EINVAL.
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index d3b13e8..4032f36 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -310,16 +310,16 @@ gdb_open_cloexec (const char *filename, int flags, unsigned long mode)
FILE *
gdb_fopen_cloexec (const char *filename, const char *opentype)
{
- FILE *result = NULL;
+ FILE *result;
/* Probe for "e" support once. But, if we can tell the operating
system doesn't know about close on exec mode "e" without probing,
skip it. E.g., the Windows runtime issues an "Invalid parameter
passed to C runtime function" OutputDebugString warning for
unknown modes. Assume that if O_CLOEXEC is zero, then "e" isn't
supported. */
- static int fopen_e_ever_failed = O_CLOEXEC == 0;
+ static int fopen_e_ever_failed_einval = O_CLOEXEC == 0;
- if (!fopen_e_ever_failed)
+ if (!fopen_e_ever_failed_einval)
{
char *copy;
@@ -329,15 +329,16 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
this path. */
strcat (copy, "e");
result = fopen (filename, copy);
- }
- if (result == NULL)
- {
- /* Fallback. */
- result = fopen (filename, opentype);
- if (result != NULL)
- fopen_e_ever_failed = 1;
+ if (result == NULL && errno == EINVAL)
+ {
+ result = fopen (filename, opentype);
+ if (result != NULL)
+ fopen_e_ever_failed_einval = 1;
+ }
}
+ else
+ result = fopen (filename, opentype);
if (result != NULL)
maybe_mark_cloexec (fileno (result));