From owner-svn-ports-all@freebsd.org Sun Sep 27 14:16:55 2020 Return-Path: Delivered-To: svn-ports-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B23D13FCC36; Sun, 27 Sep 2020 14:16:55 +0000 (UTC) (envelope-from naddy@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BznlW4FdQz3Yrl; Sun, 27 Sep 2020 14:16:55 +0000 (UTC) (envelope-from naddy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 763B5DE5A; Sun, 27 Sep 2020 14:16:55 +0000 (UTC) (envelope-from naddy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 08REGtf6042522; Sun, 27 Sep 2020 14:16:55 GMT (envelope-from naddy@FreeBSD.org) Received: (from naddy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 08REGsmr042514; Sun, 27 Sep 2020 14:16:54 GMT (envelope-from naddy@FreeBSD.org) Message-Id: <202009271416.08REGsmr042514@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: naddy set sender to naddy@FreeBSD.org using -f From: Christian Weisgerber Date: Sun, 27 Sep 2020 14:16:54 +0000 (UTC) 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 X-SVN-Group: ports-head X-SVN-Commit-Author: naddy X-SVN-Commit-Paths: in head/devel/got: . files files/openbsd-compat X-SVN-Commit-Revision: 550279 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Sep 2020 14:16:55 -0000 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 + * + * 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 +#include +#include + +/* + * 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) /* + * + */ +#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, ...); + +/* * */ #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, }