all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 12881@debbugs.gnu.org
Subject: bug#12881: Assume at least POSIX.1-1988 for fcntl.h
Date: Wed, 14 Nov 2012 19:33:45 +0200	[thread overview]
Message-ID: <83y5i4t7gm.fsf@gnu.org> (raw)
In-Reply-To: <50A34A56.9080007@cs.ucla.edu>

> Date: Tue, 13 Nov 2012 23:37:58 -0800
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: Eli Zaretskii <eliz@gnu.org>
> 
> On POSIXish hosts it's long been safe to assume at least
> POSIX.1-1988, as the pre-POSIX platforms died out long ago.
> Attached is a patch to simplify Emacs to assume this
> for <fcntl.h>.  I haven't tested this on Windows but have
> tried to make the Windows port work by renaming its O_NDELAY
> flag to O_NONBLOCK, as POSIX standardized the spelling of this
> flag to be O_NONBLOCK.  I'll CC: this patch to Eli to give
> him a heads-up.  This patch is relative to trunk bzr 110892.

Renaming O_NDELAY is a no-brainer, but the patch does much more than
just that.  In several places, it actually changes the code involved
in dealing with the related issues.  Here's one example:

> @@ -4847,23 +4795,8 @@
>  	      else if (nread == -1 && errno == EWOULDBLOCK)
>  		;
>  #endif
> -	      /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
> -		 and Emacs uses O_NONBLOCK, so what we get is EAGAIN.  */
> -#if O_NONBLOCK
> -	      else if (nread == -1 && errno == EAGAIN)
> -		;
> -#else
> -#if O_NDELAY
> -	      else if (nread == -1 && errno == EAGAIN)
> -		;
> -	      /* Note that we cannot distinguish between no input
> -		 available now and a closed pipe.
> -		 With luck, a closed pipe will be accompanied by
> -		 subprocess termination and SIGCHLD.  */
> -	      else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
> -		;
> -#endif /* O_NDELAY */
> -#endif /* O_NONBLOCK */
> +	      else if (nread == -1 && errno == EAGAIN)
> +		;

Here, the code that was left is identical to the one used by platforms
with O_NONBLOCK, but the code used by platforms with O_NDELAY was
different in non-trivial ways.

Another potential problem is that the Windows emulation of fcntl only
works for sockets, whereas O_NONBLOCK is now used in other system
calls, like in emacs_open etc.

This patch also modifies code unrelated to O_NONBLOCK, like this one:

> --- src/callproc.c	2012-11-14 04:55:41 +0000
> +++ src/callproc.c	2012-11-14 07:26:25 +0000
> @@ -1317,16 +1317,7 @@
>      return fd;
>    else
>      {
> -      int new;
> -#ifdef F_DUPFD
> -      new = fcntl (fd, F_DUPFD, minfd);
> -#else
> -      new = dup (fd);
> -      if (new != -1)
> -	/* Note that we hold the original FD open while we recurse,
> -	   to guarantee we'll get a new FD if we need it.  */
> -	new = relocate_fd (new, minfd);
> -#endif
> +      int new = fcntl (fd, F_DUPFD, minfd);
>        if (new == -1)
>  	{
>  	  const char *message_1 = "Error while setting up child: ";

Likewise with O_NOCTTY.

It's possible that you've already analyzed all these places, and they
either aren't getting compiled on Windows or are no-ops.  If so,
please tell the details.  Failing that, Someone(TM) will have to do
the footwork of making sure these changes don't break non-Posix
platforms.





  reply	other threads:[~2012-11-14 17:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-14  7:37 bug#12881: Assume at least POSIX.1-1988 for fcntl.h Paul Eggert
2012-11-14 17:33 ` Eli Zaretskii [this message]
2012-11-15  6:32   ` Paul Eggert
2012-11-15 17:42     ` Eli Zaretskii
2012-11-15 20:07       ` Paul Eggert
2012-11-16  9:49         ` Eli Zaretskii
2012-11-16 14:37           ` Stefan Monnier
2012-11-16 14:55             ` Juanma Barranquero
2012-11-16 15:26               ` Stefan Monnier
2012-11-16 16:00                 ` Eli Zaretskii
2012-11-16 16:29                   ` Juanma Barranquero
2012-11-16 17:41                     ` Eli Zaretskii
2012-11-16 17:10                   ` Stefan Monnier
2012-11-16 17:14                     ` Juanma Barranquero
2012-11-16 17:20                       ` Juanma Barranquero
2012-11-16 17:44                     ` Eli Zaretskii
2012-11-16 17:52                       ` Drew Adams
2012-11-17 22:17           ` Paul Eggert
2012-11-18  3:46             ` Eli Zaretskii
2012-11-18  4:41               ` Paul Eggert
2012-11-18 16:58                 ` Eli Zaretskii
2012-11-16  4:38 ` Paul Eggert

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=83y5i4t7gm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=12881@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.