From owner-dev-commits-src-branches@freebsd.org Sat Aug 21 17:59:13 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 694796762D8; Sat, 21 Aug 2021 17:59:13 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GsR8d2Nz7z4Vk7; Sat, 21 Aug 2021 17:59:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 32DA7114F4; Sat, 21 Aug 2021 17:59:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17LHxDgm008107; Sat, 21 Aug 2021 17:59:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17LHxDBw008106; Sat, 21 Aug 2021 17:59:13 GMT (envelope-from git) Date: Sat, 21 Aug 2021 17:59:13 GMT Message-Id: <202108211759.17LHxDBw008106@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 9bfe19ff8253 - stable/13 - tail: Fix -f with stdin MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9bfe19ff8253d08482cbbbf59cca435c4de87ac5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Aug 2021 17:59:13 -0000 The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9bfe19ff8253d08482cbbbf59cca435c4de87ac5 commit 9bfe19ff8253d08482cbbbf59cca435c4de87ac5 Author: Mark Johnston AuthorDate: 2021-07-08 21:40:59 +0000 Commit: Mark Johnston CommitDate: 2021-08-21 16:18:17 +0000 tail: Fix -f with stdin Based on a patch from swills@. (cherry picked from commit 7e11889959a6c92f05e1c1949deb73295ce60bac) --- usr.bin/tail/extern.h | 2 +- usr.bin/tail/tail.c | 43 ++++++++++++++++++++----------------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/usr.bin/tail/extern.h b/usr.bin/tail/extern.h index 65ddb519dc61..3d8c12629682 100644 --- a/usr.bin/tail/extern.h +++ b/usr.bin/tail/extern.h @@ -56,7 +56,7 @@ struct mapinfo { struct file_info { FILE *fp; - char *file_name; + const char *file_name; struct stat st; }; diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c index b52043c5e580..874557f105ec 100644 --- a/usr.bin/tail/tail.c +++ b/usr.bin/tail/tail.c @@ -67,8 +67,6 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; int Fflag, fflag, qflag, rflag, rval, no_files; fileargs_t *fa; -static file_info_t *files; - static void obsolete(char **); static void usage(void); @@ -88,8 +86,8 @@ main(int argc, char *argv[]) FILE *fp; off_t off; enum STYLE style; - int i, ch, first; - file_info_t *file; + int ch, first; + file_info_t file, *filep, *files; char *p; cap_rights_t rights; @@ -206,30 +204,24 @@ main(int argc, char *argv[]) } if (*argv && fflag) { - files = (struct file_info *) malloc(no_files * - sizeof(struct file_info)); - if (!files) + files = malloc(no_files * sizeof(struct file_info)); + if (files == NULL) err(1, "Couldn't malloc space for file descriptors."); - for (file = files; (fn = *argv++); file++) { - file->file_name = strdup(fn); - if (! file->file_name) - errx(1, "Couldn't malloc space for file name."); - file->fp = fileargs_fopen(fa, file->file_name, "r"); - if (file->fp == NULL || - fstat(fileno(file->fp), &file->st)) { - if (file->fp != NULL) { - fclose(file->fp); - file->fp = NULL; + for (filep = files; (fn = *argv++); filep++) { + filep->file_name = fn; + filep->fp = fileargs_fopen(fa, filep->file_name, "r"); + if (filep->fp == NULL || + fstat(fileno(filep->fp), &filep->st)) { + if (filep->fp != NULL) { + fclose(filep->fp); + filep->fp = NULL; } if (!Fflag || errno != ENOENT) - ierr(file->file_name); + ierr(filep->file_name); } } follow(files, style, off); - for (i = 0, file = files; i < no_files; i++, file++) { - free(file->file_name); - } free(files); } else if (*argv) { for (first = 1; (fn = *argv++);) { @@ -266,10 +258,15 @@ main(int argc, char *argv[]) fflag = 0; /* POSIX.2 requires this. */ } - if (rflag) + if (rflag) { reverse(stdin, fn, style, off, &sb); - else + } else if (fflag) { + file.file_name = fn; + file.fp = stdin; + follow(&file, style, off); + } else { forward(stdin, fn, style, off, &sb); + } } fileargs_free(fa); exit(rval);