Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Kai Tietz <ktietz@redhat.com>
Cc: gdb-patches@sourceware.org, Tom Tromey <tromey@redhat.com>
Subject: [patchv2] Minor O_CLOEXEC optimization, "regression" fix
Date: Wed, 09 Oct 2013 14:41:00 -0000	[thread overview]
Message-ID: <20131009144134.GA7506@host2.jankratochvil.net> (raw)
In-Reply-To: <173490856.4156973.1381325657769.JavaMail.root@redhat.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));


  reply	other threads:[~2013-10-09 14:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-08 18:32 [patch] " Jan Kratochvil
2013-10-08 19:44 ` Tom Tromey
2013-10-09 13:10   ` Jan Kratochvil
2013-10-09 13:34     ` Kai Tietz
2013-10-09 14:41       ` Jan Kratochvil [this message]
2013-10-09 15:48         ` [patchv2] " Tom Tromey
2013-10-09 16:01           ` [commit] " Jan Kratochvil
2013-10-09 17:07       ` [patch] " Eli Zaretskii
2013-10-09 17:02     ` Eli Zaretskii
2013-10-09 17:08       ` Tom Tromey
2013-10-09 17:29         ` Eli Zaretskii
2013-10-09 17:41           ` Jan Kratochvil
2013-10-09 17:58             ` Eli Zaretskii
2013-10-09 18:37               ` Jan Kratochvil
2013-10-09 19:08                 ` Eli Zaretskii

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=20131009144134.GA7506@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ktietz@redhat.com \
    --cc=tromey@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox