aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2013-10-09 16:00:54 +0000
committerJan Kratochvil <jan.kratochvil@redhat.com>2013-10-09 16:00:54 +0000
commitc74e1ccf71458d5e1ab1c5a877a6c27d62597250 (patch)
tree40ded5c89cddad2a408e2f5af7cc32616efed0e1
parent915215be09d492d167fa2a0d0c4d3f75cfb40157 (diff)
downloadgdb-c74e1ccf71458d5e1ab1c5a877a6c27d62597250.zip
gdb-c74e1ccf71458d5e1ab1c5a877a6c27d62597250.tar.gz
gdb-c74e1ccf71458d5e1ab1c5a877a6c27d62597250.tar.bz2
Minor O_CLOEXEC optimization, "regression" fix
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.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/common/filestuff.c21
2 files changed, 17 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d2fb999..3dd66c8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2013-10-09 Pedro Alves <palves@redhat.com>
* monitor.c (monitor_write_memory, monitor_write_memory_bytes)
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));