diff options
| author | Paul Eggert | 2022-04-17 10:41:17 -0700 |
|---|---|---|
| committer | Paul Eggert | 2022-04-17 10:43:13 -0700 |
| commit | 3cccf0a9107d585173e527550bbc45253624ca2e (patch) | |
| tree | 84f2ace0970fde0dc3c9863755eba8379574ffcf /src | |
| parent | 4641bc1c550a81c71798c0176a6bfc34c8947c74 (diff) | |
| download | emacs-3cccf0a9107d585173e527550bbc45253624ca2e.tar.gz emacs-3cccf0a9107d585173e527550bbc45253624ca2e.zip | |
Don’t assume openat
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'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 72be25f6610..f6d139421af 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2302,6 +2302,20 @@ emacs_fstatat (int dirfd, char const *filename, void *st, int flags) | |||
| 2302 | return r; | 2302 | return r; |
| 2303 | } | 2303 | } |
| 2304 | 2304 | ||
| 2305 | static int | ||
| 2306 | sys_openat (int dirfd, char const *file, int oflags, int mode) | ||
| 2307 | { | ||
| 2308 | #ifdef O_PATH | ||
| 2309 | return openat (dirfd, file, oflags, mode); | ||
| 2310 | #else | ||
| 2311 | /* On platforms without O_PATH, emacs_openat's callers arrange for | ||
| 2312 | DIRFD to be AT_FDCWD, so it should be safe to just call 'open'. | ||
| 2313 | This ports to old platforms like OS X 10.9 that lack openat. */ | ||
| 2314 | eassert (dirfd == AT_FDCWD); | ||
| 2315 | return open (file, oflags, mode); | ||
| 2316 | #endif | ||
| 2317 | } | ||
| 2318 | |||
| 2305 | /* Assuming the directory DIRFD, open FILE for Emacs use, | 2319 | /* Assuming the directory DIRFD, open FILE for Emacs use, |
| 2306 | using open flags OFLAGS and mode MODE. | 2320 | using open flags OFLAGS and mode MODE. |
| 2307 | Use binary I/O on systems that care about text vs binary I/O. | 2321 | 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) | |||
| 2317 | if (! (oflags & O_TEXT)) | 2331 | if (! (oflags & O_TEXT)) |
| 2318 | oflags |= O_BINARY; | 2332 | oflags |= O_BINARY; |
| 2319 | oflags |= O_CLOEXEC; | 2333 | oflags |= O_CLOEXEC; |
| 2320 | while ((fd = openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR) | 2334 | while ((fd = sys_openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR) |
| 2321 | maybe_quit (); | 2335 | maybe_quit (); |
| 2322 | return fd; | 2336 | return fd; |
| 2323 | } | 2337 | } |
| @@ -2330,26 +2344,19 @@ emacs_open (char const *file, int oflags, int mode) | |||
| 2330 | 2344 | ||
| 2331 | /* Same as above, but doesn't allow the user to quit. */ | 2345 | /* Same as above, but doesn't allow the user to quit. */ |
| 2332 | 2346 | ||
| 2333 | static int | 2347 | int |
| 2334 | emacs_openat_noquit (int dirfd, const char *file, int oflags, | 2348 | emacs_open_noquit (char const *file, int oflags, int mode) |
| 2335 | int mode) | ||
| 2336 | { | 2349 | { |
| 2337 | int fd; | 2350 | int fd; |
| 2338 | if (! (oflags & O_TEXT)) | 2351 | if (! (oflags & O_TEXT)) |
| 2339 | oflags |= O_BINARY; | 2352 | oflags |= O_BINARY; |
| 2340 | oflags |= O_CLOEXEC; | 2353 | oflags |= O_CLOEXEC; |
| 2341 | do | 2354 | do |
| 2342 | fd = openat (dirfd, file, oflags, mode); | 2355 | fd = open (file, oflags, mode); |
| 2343 | while (fd < 0 && errno == EINTR); | 2356 | while (fd < 0 && errno == EINTR); |
| 2344 | return fd; | 2357 | return fd; |
| 2345 | } | 2358 | } |
| 2346 | 2359 | ||
| 2347 | int | ||
| 2348 | emacs_open_noquit (char const *file, int oflags, int mode) | ||
| 2349 | { | ||
| 2350 | return emacs_openat_noquit (AT_FDCWD, file, oflags, mode); | ||
| 2351 | } | ||
| 2352 | |||
| 2353 | /* Open FILE as a stream for Emacs use, with mode MODE. | 2360 | /* Open FILE as a stream for Emacs use, with mode MODE. |
| 2354 | Act like emacs_open with respect to threads, signals, and quits. */ | 2361 | Act like emacs_open with respect to threads, signals, and quits. */ |
| 2355 | 2362 | ||