On Sun, Aug 20, 2023 at 09:05:36PM +0100, Stuart Henderson wrote: > i'm ok with adding pledge (and the homepage update). > > generally when we've added pledge patches to ports before, we used > the 'native' means of error reporting rather than pulling in err.h; > I would slightly prefer to do that here too - for this port it looks > like the native is probably XSUM_log + exit (though one of the cases in > xsum_os_specific.c just uses fprintf(stderr) + abort).
That would be XSUM_log() with strerror(3), which amounts to "xsum_output.h" with <errno.h> and <string.h>, which looks more native, but does not seem as straight forward as a single err(3). Both hunks are at the top of main(), so direct return is both sufficient and consistent with existing returns -- compared to abort(3). This could look like this, I'm fine with both. I can take it upstream (afterwards) and see if/how they want it. Index: Makefile =================================================================== RCS file: /cvs/ports/sysutils/xxhash/Makefile,v retrieving revision 1.15 diff -u -p -r1.15 Makefile --- Makefile 17 Aug 2023 06:44:12 -0000 1.15 +++ Makefile 17 Aug 2023 16:23:55 -0000 @@ -4,20 +4,21 @@ COMMENT = extremely fast non-cryptograph GH_ACCOUNT = Cyan4973 GH_PROJECT = xxHash GH_TAGNAME = v0.8.2 -REVISION = 0 +REVISION = 1 PKGNAME = ${DISTNAME:L} SHARED_LIBS = xxhash 0.3 # 0.8.1 CATEGORIES = sysutils -HOMEPAGE = https://cyan4973.github.io/xxHash/ +HOMEPAGE = https://xxhash.com MAINTAINER = Bjorn Ketelaars <b...@openbsd.org> # BSD 2-Clause PERMIT_PACKAGE = Yes +# uses pledge() WANTLIB = c MAKE_FLAGS = CC="${CC}" \ Index: patches/patch-cli_xsum_os_specific_c =================================================================== RCS file: patches/patch-cli_xsum_os_specific_c diff -N patches/patch-cli_xsum_os_specific_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-cli_xsum_os_specific_c 20 Aug 2023 21:18:41 -0000 @@ -0,0 +1,31 @@ +Use pledge(2), xxhsum(1) only ever reads files or stdin. + +Index: cli/xsum_os_specific.c +--- cli/xsum_os_specific.c.orig ++++ cli/xsum_os_specific.c +@@ -69,6 +69,11 @@ static int XSUM_IS_CONSOLE(FILE* stdStream) + || defined(__DJGPP__) \ + || defined(__MSYS__) \ + || defined(__HAIKU__) ++# ifdef __OpenBSD__ ++# include <errno.h> /* errno */ ++# include <string.h> /* strerror */ ++# include "xsum_output.h" /* XSUM_log */ ++# endif + # include <unistd.h> /* isatty */ + # define XSUM_IS_CONSOLE(stdStream) isatty(fileno(stdStream)) + #elif defined(MSDOS) || defined(OS2) +@@ -135,6 +140,13 @@ static int XSUM_stat(const char* infilename, XSUM_stat + #ifndef XSUM_NO_MAIN + int main(int argc, const char* argv[]) + { ++#ifdef __OpenBSD__ ++ if (pledge("stdio rpath", NULL) == -1) { ++ XSUM_log("pledge: %s\n", strerror(errno)); ++ return 1; ++ } ++#endif ++ + return XSUM_main(argc, argv); + } + #endif Index: patches/patch-tests_sanity_test_c =================================================================== RCS file: patches/patch-tests_sanity_test_c diff -N patches/patch-tests_sanity_test_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-tests_sanity_test_c 20 Aug 2023 21:17:10 -0000 @@ -0,0 +1,19 @@ +Use pledge(2), the sanity test does even not read files. + +Index: tests/sanity_test.c +--- tests/sanity_test.c.orig ++++ tests/sanity_test.c +@@ -639,6 +639,13 @@ int main(int argc, const char* argv[]) + (void) argc; + (void) argv; + ++#ifdef __OpenBSD__ ++ if (pledge("stdio", NULL) == -1) { ++ XSUM_log("pledge: %s\n", strerror(errno)); ++ return EXIT_FAILURE; ++ } ++#endif ++ + { + /* XXH32 */ + size_t const n = sizeof(XSUM_XXH32_testdata) / sizeof(XSUM_XXH32_testdata[0]);