From owner-svn-src-head@freebsd.org Thu Jan 16 14:15:01 2020 Return-Path: Delivered-To: svn-src-head@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 59EFA1E8BDB; Thu, 16 Jan 2020 14:15:01 +0000 (UTC) (envelope-from arichardson@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) server-signature RSA-PSS (4096 bits) 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 47z5n10j3Mz43gT; Thu, 16 Jan 2020 14:15:01 +0000 (UTC) (envelope-from arichardson@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 0D24020AD6; Thu, 16 Jan 2020 14:15:01 +0000 (UTC) (envelope-from arichardson@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00GEF0nb078656; Thu, 16 Jan 2020 14:15:00 GMT (envelope-from arichardson@FreeBSD.org) Received: (from arichardson@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00GEF0Qq078653; Thu, 16 Jan 2020 14:15:00 GMT (envelope-from arichardson@FreeBSD.org) Message-Id: <202001161415.00GEF0Qq078653@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arichardson set sender to arichardson@FreeBSD.org using -f From: Alex Richardson Date: Thu, 16 Jan 2020 14:15:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356791 - head/bin/cat X-SVN-Group: head X-SVN-Commit-Author: arichardson X-SVN-Commit-Paths: head/bin/cat X-SVN-Commit-Revision: 356791 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jan 2020 14:15:01 -0000 Author: arichardson Date: Thu Jan 16 14:15:00 2020 New Revision: 356791 URL: https://svnweb.freebsd.org/changeset/base/356791 Log: Allow building bin/cat on non-FreeBSD systems `cat -l` is needed during the installworld phase and other system's cat don't support that flag. To avoid portability issues when compiling on Linux/macOS (such as the the direct access to &fp->_mbstate), we disable the entire multibyte support when building as a boostrap tool. Reviewed By: brooks, emaste Differential Revision: https://reviews.freebsd.org/D13939 Modified: head/bin/cat/Makefile head/bin/cat/cat.c Modified: head/bin/cat/Makefile ============================================================================== --- head/bin/cat/Makefile Thu Jan 16 14:14:55 2020 (r356790) +++ head/bin/cat/Makefile Thu Jan 16 14:15:00 2020 (r356791) @@ -6,6 +6,12 @@ PACKAGE=runtime PROG= cat +.ifdef BOOTSTRAPPING +# For the bootstrap cat we disable all wide char support to allow building +# on Linux/macOS +CFLAGS+=-DBOOTSTRAP_CAT +.endif + HAS_TESTS= SUBDIR.${MK_TESTS}+= tests Modified: head/bin/cat/cat.c ============================================================================== --- head/bin/cat/cat.c Thu Jan 16 14:14:55 2020 (r356790) +++ head/bin/cat/cat.c Thu Jan 16 14:15:00 2020 (r356791) @@ -96,6 +96,20 @@ static int udom_open(const char *path, int flags); */ #define BUFSIZE_SMALL (MAXPHYS) + +/* + * For the bootstrapped cat binary (needed for locked appending to METALOG), we + * disable all flags except -l and -u to avoid non-portable function calls. + * In the future we may instead want to write a small portable bootstrap tool + * that locks the output file before writing to it. However, for now + * bootstrapping cat without multibyte support is the simpler solution. + */ +#ifdef BOOTSTRAP_CAT +#define SUPPORTED_FLAGS "lu" +#else +#define SUPPORTED_FLAGS "belnstuv" +#endif + int main(int argc, char *argv[]) { @@ -104,7 +118,7 @@ main(int argc, char *argv[]) setlocale(LC_CTYPE, ""); - while ((ch = getopt(argc, argv, "belnstuv")) != -1) + while ((ch = getopt(argc, argv, SUPPORTED_FLAGS)) != -1) switch (ch) { case 'b': bflag = nflag = 1; /* -b implies -n */ @@ -158,7 +172,7 @@ static void usage(void) { - fprintf(stderr, "usage: cat [-belnstuv] [file ...]\n"); + fprintf(stderr, "usage: cat [-" SUPPORTED_FLAGS "] [file ...]\n"); exit(1); /* NOTREACHED */ } @@ -187,6 +201,7 @@ scanfiles(char *argv[], int cooked) if (fd < 0) { warn("%s", path); rval = 1; +#ifndef BOOTSTRAP_CAT } else if (cooked) { if (fd == STDIN_FILENO) cook_cat(stdin); @@ -195,6 +210,7 @@ scanfiles(char *argv[], int cooked) cook_cat(fp); fclose(fp); } +#endif } else { raw_cat(fd); if (fd != STDIN_FILENO) @@ -206,6 +222,7 @@ scanfiles(char *argv[], int cooked) } } +#ifndef BOOTSTRAP_CAT static void cook_cat(FILE *fp) { @@ -295,6 +312,7 @@ ilseq: if (ferror(stdout)) err(1, "stdout"); } +#endif /* BOOTSTRAP_CAT */ static void raw_cat(int rfd)