unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Keith David Bershatsky <esq@lawlist.com>,
	Emacs Devel <emacs-devel@gnu.org>
Subject: Re: Emacs 28 on OSX: emacsclient.c:1415: warning: implicit declaration of function 'openat'
Date: Sun, 17 Apr 2022 10:49:31 -0700	[thread overview]
Message-ID: <a778114b-0fc2-3330-5e24-a7c2f5ab046e@cs.ucla.edu> (raw)
In-Reply-To: <7C193269-26F7-4E85-A1E6-7A3C0C1DECC6@acm.org>

[-- Attachment #1: Type: text/plain, Size: 869 bytes --]

On 4/17/22 02:01, Mattias Engdegård wrote:
> `openat` was introduced in OS X 10.10, but shouldn't gnulib have a substitute? Paul?

Gnulib's openat substitute is so heavyweight that Emacs doesn't use it. 
(The substitute implements openat via fchdir-and-fchdir-back which is 
dubious for Emacs.)

Instead of using Gnulib openat, I installed the attached patch into the 
emacs-28 branch so that Emacs uses openat only on platforms like GNU 
that define O_PATH (as these are the only platforms where Emacs passes a 
value other than AT_FDCWD to openat's first argument). I tested this in 
an artificial Fedora environment where I removed O_PATH, and it passed 
'make check', so this should port to OS X 10.9 as well. Please give it a 
try.

PS. Could we somehow arrange for port-to-old-macOS testing to be done 
before an Emacs release, rather than after?

[-- Attachment #2: 0001-Don-t-assume-openat.patch --]
[-- Type: text/x-patch, Size: 3551 bytes --]

From 3cccf0a9107d585173e527550bbc45253624ca2e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 17 Apr 2022 10:41:17 -0700
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20assume=20openat?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use openat only on platforms with O_PATH.
This ports to OS X 10.9 and earlier.
Problem reported by Keith David Bershatsky in:
https://lists.gnu.org/r/emacs-devel/2022-04/msg00805.html
* lib-src/emacsclient.c (local_sockname): Use open, not openat.
* src/sysdep.c (sys_openat): New static function,
which uses openat only if O_PATH is defined.
(emacs_openat): Use it instead of openat.
(emacs_openat_noquit): Remove.
(emacs_open_noquit): Reimplement as per the old emacs_openat_noquit,
but use plain 'open'.
---
 lib-src/emacsclient.c |  3 +--
 src/sysdep.c          | 29 ++++++++++++++++++-----------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 57a5eff3bf..217a38bc07 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1412,8 +1412,7 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
   char *emacsdirend = sockname + tmpdirlen + suffixlen -
     strlen(server_name) - 1;
   *emacsdirend = '\0';
-  int dir = openat (AT_FDCWD, sockname,
-		    O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
+  int dir = open (sockname, O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
   *emacsdirend = '/';
   if (dir < 0)
     return errno;
diff --git a/src/sysdep.c b/src/sysdep.c
index 72be25f661..f6d139421a 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2302,6 +2302,20 @@ emacs_fstatat (int dirfd, char const *filename, void *st, int flags)
   return r;
 }
 
+static int
+sys_openat (int dirfd, char const *file, int oflags, int mode)
+{
+#ifdef O_PATH
+  return openat (dirfd, file, oflags, mode);
+#else
+  /* On platforms without O_PATH, emacs_openat's callers arrange for
+     DIRFD to be AT_FDCWD, so it should be safe to just call 'open'.
+     This ports to old platforms like OS X 10.9 that lack openat.  */
+  eassert (dirfd == AT_FDCWD);
+  return open (file, oflags, mode);
+#endif
+}
+
 /* Assuming the directory DIRFD, open FILE for Emacs use,
    using open flags OFLAGS and mode MODE.
    Use binary I/O on systems that care about text vs binary I/O.
@@ -2317,7 +2331,7 @@ emacs_openat (int dirfd, char const *file, int oflags, int mode)
   if (! (oflags & O_TEXT))
     oflags |= O_BINARY;
   oflags |= O_CLOEXEC;
-  while ((fd = openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR)
+  while ((fd = sys_openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR)
     maybe_quit ();
   return fd;
 }
@@ -2330,26 +2344,19 @@ emacs_open (char const *file, int oflags, int mode)
 
 /* Same as above, but doesn't allow the user to quit.  */
 
-static int
-emacs_openat_noquit (int dirfd, const char *file, int oflags,
-                     int mode)
+int
+emacs_open_noquit (char const *file, int oflags, int mode)
 {
   int fd;
   if (! (oflags & O_TEXT))
     oflags |= O_BINARY;
   oflags |= O_CLOEXEC;
   do
-    fd = openat (dirfd, file, oflags, mode);
+    fd = open (file, oflags, mode);
   while (fd < 0 && errno == EINTR);
   return fd;
 }
 
-int
-emacs_open_noquit (char const *file, int oflags, int mode)
-{
-  return emacs_openat_noquit (AT_FDCWD, file, oflags, mode);
-}
-
 /* Open FILE as a stream for Emacs use, with mode MODE.
    Act like emacs_open with respect to threads, signals, and quits.  */
 
-- 
2.32.0


  reply	other threads:[~2022-04-17 17:49 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 19:11 Emacs 28 on OSX: emacsclient.c:1415: warning: implicit declaration of function 'openat' Keith David Bershatsky
2022-04-17  9:01 ` Mattias Engdegård
2022-04-17 17:49   ` Paul Eggert [this message]
2022-04-17 19:12     ` Eli Zaretskii
2022-04-17 20:36       ` Paul Eggert
2022-04-18  4:49         ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2022-04-17 18:45 Keith David Bershatsky
2022-04-17 20:37 ` Alan Third
2022-04-17 20:37 ` Paul Eggert
2022-04-17 21:57 Keith David Bershatsky
2022-04-17 23:21 ` Paul Eggert
2022-04-18  0:38 Keith David Bershatsky
2022-04-18  0:58 ` Paul Eggert
2022-04-18  1:39 ` Po Lu
2022-04-18  2:24 Keith David Bershatsky
2022-04-18  2:53 ` Po Lu
2022-04-18 19:51 Keith David Bershatsky
2022-04-18 19:54 ` Paul Eggert
2022-04-19  1:00 ` Po Lu
2022-04-18 20:43 Keith David Bershatsky
2022-04-19  1:24 Keith David Bershatsky
2022-04-19  2:35 ` Po Lu
2022-04-19  4:19   ` Alan Third
2022-04-19  4:24     ` Po Lu
2022-04-19  6:04     ` Eli Zaretskii
2022-04-20  1:23     ` Po Lu
2022-04-20  8:07       ` Alan Third
2022-04-19  2:56 ` Paul Eggert
2022-04-19  4:36 Keith David Bershatsky
2022-04-19  4:38 ` Po Lu
2022-04-20 13:55 Keith David Bershatsky
2022-04-20 16:48 ` Alan Third
2022-04-21  0:51 Keith David Bershatsky
2022-04-21  2:05 ` Po Lu
2022-04-21  5:09 ` Alan Third
2022-04-21  2:22 Keith David Bershatsky
2022-04-21 17:52 Keith David Bershatsky
2022-04-21 19:21 ` Alan Third
2022-04-21 20:51 Keith David Bershatsky
2022-04-21 22:22 ` Alan Third
2022-04-21 22:40 Keith David Bershatsky
2022-04-21 22:44 ` Alan Third
2022-04-22 21:23 Keith David Bershatsky
2022-04-22 21:29 Keith David Bershatsky
2022-04-23 22:13 ` Alan Third
2022-04-23  4:33 Keith David Bershatsky
2022-04-23 22:04 ` Alan Third
2022-04-24  0:08 Keith David Bershatsky
2022-04-24  9:03 ` Alan Third
2022-04-24 17:02 Keith David Bershatsky
2022-04-24 19:22 ` Alan Third
2022-04-25  1:35 Keith David Bershatsky
2022-04-25 18:08 ` Alan Third
2022-04-25  1:49 Keith David Bershatsky
2022-04-25  3:09 ` Po Lu
2022-04-25  3:46 Keith David Bershatsky
2022-04-25  4:13 ` Po Lu
2022-04-25  5:17 Keith David Bershatsky
2022-04-25  5:43 ` Po Lu
2022-04-25  9:56   ` Alan Third
2022-04-25 10:30     ` Po Lu
2022-04-25 18:07       ` Alan Third
2022-04-26  0:10         ` Po Lu
2022-04-26  2:56 Keith David Bershatsky
2022-04-26  3:14 ` Po Lu

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a778114b-0fc2-3330-5e24-a7c2f5ab046e@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=esq@lawlist.com \
    --cc=mattiase@acm.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).