Received: by mail.netbsd.org (Postfix, from userid 605) id 7402F84ECA; Tue, 7 Jun 2022 09:52:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id ABA2584E5B for ; Tue, 7 Jun 2022 09:52:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([IPv6:::1]) by localhost (mail.netbsd.org [IPv6:::1]) (amavisd-new, port 10025) with ESMTP id J19UOERN-Xmt for ; Tue, 7 Jun 2022 09:52:13 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.NetBSD.org [IPv6:2001:470:a085:999:28c:faff:fe03:5984]) by mail.netbsd.org (Postfix) with ESMTP id ABA9E84D16 for ; Tue, 7 Jun 2022 09:52:13 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 4FFE6FB19; Tue, 7 Jun 2022 09:53:36 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1654595616237050" MIME-Version: 1.0 Date: Tue, 7 Jun 2022 09:53:36 +0000 From: "Jonathan Perkin" Subject: CVS commit: pkgsrc/pkgtools/mktools To: pkgsrc-changes@NetBSD.org Reply-To: jperkin@netbsd.org X-Mailer: log_accum Message-Id: <20220607095336.4FFE6FB19@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1654595616237050 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: jperkin Date: Tue Jun 7 09:53:36 UTC 2022 Added Files: pkgsrc/pkgtools/mktools: DESCR Makefile PLIST pkgsrc/pkgtools/mktools/files: Makefile mk-buildlink-symlinks.c mkpath.c Log Message: mktools: Import new package, version 20220607. Collection of tools written in C to improve the performance of certain sections of the pkgsrc mk infrastructure where shell is too slow. For now this just includes mk-buildlink-symlinks which is used to generate the buildlink3 symlinks as part of the "wrapper" phase. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/mktools/DESCR \ pkgsrc/pkgtools/mktools/Makefile pkgsrc/pkgtools/mktools/PLIST cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/mktools/files/Makefile \ pkgsrc/pkgtools/mktools/files/mk-buildlink-symlinks.c \ pkgsrc/pkgtools/mktools/files/mkpath.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1654595616237050 Content-Disposition: inline Content-Length: 7916 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Added files: Index: pkgsrc/pkgtools/mktools/DESCR diff -u /dev/null pkgsrc/pkgtools/mktools/DESCR:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/DESCR Tue Jun 7 09:53:36 2022 @@ -0,0 +1,2 @@ +Collection of tools written in C to improve the performance of certain +sections of the pkgsrc mk infrastructure where shell is too slow. Index: pkgsrc/pkgtools/mktools/Makefile diff -u /dev/null pkgsrc/pkgtools/mktools/Makefile:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/Makefile Tue Jun 7 09:53:36 2022 @@ -0,0 +1,23 @@ +# $NetBSD: Makefile,v 1.1 2022/06/07 09:53:36 jperkin Exp $ + +PKGNAME= mktools-20220607 +CATEGORIES= pkgtools sysutils + +MAINTAINER= jperkin@pkgsrc.org +HOMEPAGE= https://www.NetBSD.org/ +COMMENT= Collection of pkgsrc mk infrastructure tools +LICENSE= modified-bsd + +USE_BSD_MAKEFILE= yes + +INSTALLATION_DIRS= libexec/mktools + +# Avoid any dependency cycles +CHECK_PERMS_SKIP= * +CHECK_PORTABILITY_SKIP= * +PKGSRC_LOCKTYPE= none + +do-extract: + ${CP} -R ${FILESDIR}/ ${WRKSRC}/ + +.include "../../mk/bsd.pkg.mk" Index: pkgsrc/pkgtools/mktools/PLIST diff -u /dev/null pkgsrc/pkgtools/mktools/PLIST:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/PLIST Tue Jun 7 09:53:36 2022 @@ -0,0 +1,2 @@ +@comment $NetBSD: PLIST,v 1.1 2022/06/07 09:53:36 jperkin Exp $ +libexec/mktools/mk-buildlink-symlinks Index: pkgsrc/pkgtools/mktools/files/Makefile diff -u /dev/null pkgsrc/pkgtools/mktools/files/Makefile:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/files/Makefile Tue Jun 7 09:53:36 2022 @@ -0,0 +1,12 @@ +# $NetBSD: Makefile,v 1.1 2022/06/07 09:53:36 jperkin Exp $ +# +PROGS= mk-buildlink-symlinks + +BINDIR= ${PREFIX}/libexec/mktools + +SRCS.mk-buildlink-symlinks= mk-buildlink-symlinks.c mkpath.c + +WARNS= 4 +NOMAN= + +.include Index: pkgsrc/pkgtools/mktools/files/mk-buildlink-symlinks.c diff -u /dev/null pkgsrc/pkgtools/mktools/files/mk-buildlink-symlinks.c:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/files/mk-buildlink-symlinks.c Tue Jun 7 09:53:36 2022 @@ -0,0 +1,75 @@ +/* $NetBSD: mk-buildlink-symlinks.c,v 1.1 2022/06/07 09:53:36 jperkin Exp $ */ + +/* + * Copyright (c) 2022 Jonathan Perkin + * + * 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 +#include +#include +#include +#include +#include + +#define LINK_SEP " -> " +#define LINK_SEP_LEN 4 + +extern int mkpath(char *, mode_t, mode_t); + +int +main(int argc, char *argv[]) +{ + char *line, *path1, *path2, *pdir; + size_t len; + ssize_t llen; + + for (len = 0, line = NULL; (llen = getline(&line, &len, stdin)) > 0; + free(line), line = NULL, len = 0) { + if (line[llen - 1] == '\n') + line[llen - 1] = '\0'; + + if ((path1 = strstr(line, LINK_SEP)) == NULL) + errx(1, "Could not find separator"); + + *path1 = '\0'; + path1 += LINK_SEP_LEN; + + if ((path2 = strdup(line)) == NULL) + err(1, "strdup"); + + /* + * The implementation notes for dirname() say that its argument + * may be modified, so ensure this operation comes after any + * other use of "line". + */ + if ((pdir = dirname(line)) == NULL) + err(1, "dirname"); + + if (access(pdir, F_OK) != 0) { + if (mkpath(pdir, 0755, 0755) != 0) + err(1, "mkpath: %s", pdir); + } + + if (unlink(path2) != 0 && errno != ENOENT) + warn("unlink: %s", path2); + + if (symlink(path1, path2) != 0) + err(1, "symlink: %s -> %s", path2, path1); + + free(path2); + } +} Index: pkgsrc/pkgtools/mktools/files/mkpath.c diff -u /dev/null pkgsrc/pkgtools/mktools/files/mkpath.c:1.1 --- /dev/null Tue Jun 7 09:53:36 2022 +++ pkgsrc/pkgtools/mktools/files/mkpath.c Tue Jun 7 09:53:36 2022 @@ -0,0 +1,110 @@ +/* $NetBSD: mkpath.c,v 1.1 2022/06/07 09:53:36 jperkin Exp $ */ + +/* + * Copyright (c) 1983, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copy of mkpath() from NetBSD src/bin/mkdir/mkdir.c + */ +#include +#include +#include +#include + +int mkpath(char *path, mode_t mode, mode_t dir_mode); + +/* + * mkpath -- create directories. + * path - path + * mode - file mode of terminal directory + * dir_mode - file mode of intermediate directories + */ +int +mkpath(char *path, mode_t mode, mode_t dir_mode) +{ + struct stat sb; + char *slash; + int done, rv; + + done = 0; + slash = path; + + for (;;) { + slash += strspn(slash, "/"); + slash += strcspn(slash, "/"); + + done = (*(slash + strspn(slash, "/")) == '\0'); + *slash = '\0'; + + rv = mkdir(path, done ? mode : dir_mode); + if (rv < 0) { + /* + * Can't create; path exists or no perms. + * stat() path to determine what's there now. + */ + int sverrno; + + sverrno = errno; + if (stat(path, &sb) < 0) { + /* Not there; use mkdir()s error */ + errno = sverrno; + warn("%s", path); + return -1; + } + if (!S_ISDIR(sb.st_mode)) { + /* Is there, but isn't a directory */ + errno = ENOTDIR; + warn("%s", path); + return -1; + } + } else if (done) { + /* + * Created ok, and this is the last element + */ + /* + * The mkdir() and umask() calls both honor only the + * file permission bits, so if you try to set a mode + * including the sticky, setuid, setgid bits you lose + * them. So chmod(). + */ + if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) != 0 && + chmod(path, mode) == -1) { + warn("%s", path); + return -1; + } + } + + if (done) { + break; + } + *slash = '/'; + } + + return 0; +} --_----------=_1654595616237050--