Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Sep 2020 14:16:54 +0000 (UTC)
From:      Christian Weisgerber <naddy@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r550279 - in head/devel/got: . files files/openbsd-compat
Message-ID:  <202009271416.08REGsmr042514@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: naddy
Date: Sun Sep 27 14:16:53 2020
New Revision: 550279
URL: https://svnweb.freebsd.org/changeset/ports/550279

Log:
  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.

Added:
  head/devel/got/files/openbsd-compat/open.c   (contents, props changed)
Deleted:
  head/devel/got/files/patch-lib_worktree.c
Modified:
  head/devel/got/Makefile
  head/devel/got/files/openbsd-compat/Makefile
  head/devel/got/files/openbsd-compat/openbsd-compat.h
  head/devel/got/files/patch-got_got.c
  head/devel/got/files/patch-lib_object__create.c

Modified: head/devel/got/Makefile
==============================================================================
--- head/devel/got/Makefile	Sun Sep 27 13:54:24 2020	(r550278)
+++ head/devel/got/Makefile	Sun Sep 27 14:16:53 2020	(r550279)
@@ -2,6 +2,7 @@
 
 PORTNAME=	got
 PORTVERSION=	0.41
+PORTREVISION=	1
 CATEGORIES=	devel
 MASTER_SITES=	https://gameoftrees.org/releases/
 

Modified: head/devel/got/files/openbsd-compat/Makefile
==============================================================================
--- head/devel/got/files/openbsd-compat/Makefile	Sun Sep 27 13:54:24 2020	(r550278)
+++ head/devel/got/files/openbsd-compat/Makefile	Sun Sep 27 14:16:53 2020	(r550279)
@@ -7,6 +7,7 @@ SRCS=	basename.c \
 	getdtablecount.c \
 	imsg.c \
 	imsg-buffer.c \
+	open.c \
 	recallocarray.c
 
 CFLAGS+= -I${.CURDIR}

Added: head/devel/got/files/openbsd-compat/open.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/got/files/openbsd-compat/open.c	Sun Sep 27 14:16:53 2020	(r550279)
@@ -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);
+}

Modified: head/devel/got/files/openbsd-compat/openbsd-compat.h
==============================================================================
--- head/devel/got/files/openbsd-compat/openbsd-compat.h	Sun Sep 27 13:54:24 2020	(r550278)
+++ head/devel/got/files/openbsd-compat/openbsd-compat.h	Sun Sep 27 14:16:53 2020	(r550279)
@@ -48,6 +48,15 @@
 	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>
  */
 #undef basename

Modified: head/devel/got/files/patch-got_got.c
==============================================================================
--- head/devel/got/files/patch-got_got.c	Sun Sep 27 13:54:24 2020	(r550278)
+++ head/devel/got/files/patch-got_got.c	Sun Sep 27 14:16:53 2020	(r550279)
@@ -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,

Modified: head/devel/got/files/patch-lib_object__create.c
==============================================================================
--- head/devel/got/files/patch-lib_object__create.c	Sun Sep 27 13:54:24 2020	(r550278)
+++ head/devel/got/files/patch-lib_object__create.c	Sun Sep 27 14:16:53 2020	(r550279)
@@ -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,
  	}
  



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009271416.08REGsmr042514>