mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-29 05:38:00 +00:00
Add a wrapper function to render open() POSIX-compliant.
POSIX mandates that open(symlink, O_NOFOLLOW) fail with errno == ELOOP. FreeBSD chooses to deviate from this, but Got depends on it. Introducing a wrapper avoids (1) the need to patch every occurrence, (2) having to check each release for new instances, and (3) slipups when modifying complex boolean expressions.
This commit is contained in:
parent
0e5bdc3ed6
commit
18588b77ae
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=550279
@ -2,6 +2,7 @@
|
||||
|
||||
PORTNAME= got
|
||||
PORTVERSION= 0.41
|
||||
PORTREVISION= 1
|
||||
CATEGORIES= devel
|
||||
MASTER_SITES= https://gameoftrees.org/releases/
|
||||
|
||||
|
@ -7,6 +7,7 @@ SRCS= basename.c \
|
||||
getdtablecount.c \
|
||||
imsg.c \
|
||||
imsg-buffer.c \
|
||||
open.c \
|
||||
recallocarray.c
|
||||
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
|
65
devel/got/files/openbsd-compat/open.c
Normal file
65
devel/got/files/openbsd-compat/open.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Christian Weisgerber <naddy@FreeBSD.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*
|
||||
* POSIX mandates that open(symlink, O_NOFOLLOW) fail with errno == ELOOP.
|
||||
* FreeBSD chooses to deviate from this, but Got depends on it.
|
||||
*/
|
||||
int
|
||||
open_posix(const char *path, int flags, ...)
|
||||
{
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
int ret;
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
ret = open(path, flags, mode);
|
||||
} else
|
||||
ret = open(path, flags);
|
||||
|
||||
if (ret == -1 && (flags & O_NOFOLLOW) && errno == EMLINK)
|
||||
errno = ELOOP;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
openat_posix(int fd, const char *path, int flags, ...)
|
||||
{
|
||||
va_list ap;
|
||||
mode_t mode;
|
||||
int ret;
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
va_start(ap, flags);
|
||||
mode = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
ret = openat(fd, path, flags, mode);
|
||||
} else
|
||||
ret = openat(fd, path, flags);
|
||||
|
||||
if (ret == -1 && (flags & O_NOFOLLOW) && errno == EMLINK)
|
||||
errno = ELOOP;
|
||||
|
||||
return (ret);
|
||||
}
|
@ -47,6 +47,15 @@
|
||||
#define SIMPLEQ_CONCAT(head1, head2) \
|
||||
STAILQ_CONCAT(head1, head2)
|
||||
|
||||
/*
|
||||
* <fcntl.h>
|
||||
*/
|
||||
#define open(...) open_posix(__VA_ARGS__)
|
||||
#define openat(...) openat_posix(__VA_ARGS__)
|
||||
|
||||
int open_posix(const char *path, int flags, ...);
|
||||
int openat_posix(int fd, const char *path, int flags, ...);
|
||||
|
||||
/*
|
||||
* <libgen.h>
|
||||
*/
|
||||
|
@ -10,24 +10,6 @@
|
||||
|
||||
if (Vflag) {
|
||||
got_version_print_str();
|
||||
@@ -4022,7 +4023,7 @@ print_diff(void *arg, unsigned char status, unsigned c
|
||||
if (dirfd != -1) {
|
||||
fd = openat(dirfd, de_name, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
- if (errno != ELOOP) {
|
||||
+ if (errno != ELOOP && errno != EMLINK) {
|
||||
err = got_error_from_errno2("openat",
|
||||
abspath);
|
||||
goto done;
|
||||
@@ -4035,7 +4036,7 @@ print_diff(void *arg, unsigned char status, unsigned c
|
||||
} else {
|
||||
fd = open(abspath, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
- if (errno != ELOOP) {
|
||||
+ if (errno != ELOOP && errno != EMLINK) {
|
||||
err = got_error_from_errno2("open",
|
||||
abspath);
|
||||
goto done;
|
||||
@@ -9421,11 +9422,11 @@ cat_commit(struct got_object_id *id, struct got_reposi
|
||||
}
|
||||
fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_AUTHOR,
|
||||
|
@ -1,14 +1,5 @@
|
||||
--- lib/object_create.c.orig 2020-09-25 11:58:47 UTC
|
||||
+++ lib/object_create.c
|
||||
@@ -131,7 +131,7 @@ got_object_blob_file_create(struct got_object_id **id,
|
||||
|
||||
fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
- if (errno != ELOOP)
|
||||
+ if (errno != ELOOP && errno != EMLINK)
|
||||
return got_error_from_errno2("open", ondisk_path);
|
||||
|
||||
if (lstat(ondisk_path, &sb) == -1) {
|
||||
@@ -144,7 +144,7 @@ got_object_blob_file_create(struct got_object_id **id,
|
||||
}
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
--- lib/worktree.c.orig 2020-09-25 11:58:47 UTC
|
||||
+++ lib/worktree.c
|
||||
@@ -1227,7 +1227,7 @@ replace_existing_symlink(const char *ondisk_path, cons
|
||||
*/
|
||||
fd = open(ondisk_path, O_RDWR | O_EXCL | O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
- if (errno != ELOOP)
|
||||
+ if (errno != ELOOP && errno != EMLINK)
|
||||
return got_error_from_errno2("open", ondisk_path);
|
||||
|
||||
/* We are updating an existing on-disk symlink. */
|
||||
@@ -1703,9 +1703,9 @@ get_file_status(unsigned char *status, struct stat *sb
|
||||
}
|
||||
} else {
|
||||
fd = open(abspath, O_RDONLY | O_NOFOLLOW);
|
||||
- if (fd == -1 && errno != ENOENT && errno != ELOOP)
|
||||
+ if (fd == -1 && errno != ENOENT && errno != ELOOP && errno != EMLINK)
|
||||
return got_error_from_errno2("open", abspath);
|
||||
- else if (fd == -1 && errno == ELOOP) {
|
||||
+ else if (fd == -1 && (errno == ELOOP || errno == EMLINK)) {
|
||||
if (lstat(abspath, sb) == -1)
|
||||
return got_error_from_errno2("lstat", abspath);
|
||||
} else if (fd == -1 || fstat(fd, sb) == -1) {
|
||||
@@ -3518,7 +3518,7 @@ worktree_status(struct got_worktree *worktree, const c
|
||||
fd = open(ondisk_path, O_RDONLY | O_NOFOLLOW | O_DIRECTORY);
|
||||
if (fd == -1) {
|
||||
if (errno != ENOTDIR && errno != ENOENT && errno != EACCES &&
|
||||
- errno != ELOOP)
|
||||
+ errno != ELOOP && errno != EMLINK)
|
||||
err = got_error_from_errno2("open", ondisk_path);
|
||||
else
|
||||
err = report_single_file_status(path, ondisk_path,
|
||||
@@ -4190,7 +4190,7 @@ create_patched_content(char **path_outfile, int revers
|
||||
if (dirfd2 != -1) {
|
||||
fd2 = openat(dirfd2, de_name2, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd2 == -1) {
|
||||
- if (errno != ELOOP) {
|
||||
+ if (errno != ELOOP && errno != EMLINK) {
|
||||
err = got_error_from_errno2("openat", path2);
|
||||
goto done;
|
||||
}
|
||||
@@ -4204,7 +4204,7 @@ create_patched_content(char **path_outfile, int revers
|
||||
} else {
|
||||
fd2 = open(path2, O_RDONLY | O_NOFOLLOW);
|
||||
if (fd2 == -1) {
|
||||
- if (errno != ELOOP) {
|
||||
+ if (errno != ELOOP && errno != EMLINK) {
|
||||
err = got_error_from_errno2("open", path2);
|
||||
goto done;
|
||||
}
|
Loading…
Reference in New Issue
Block a user