From f2baad8df4494e9e943374d9bdc43f70d3ee77a9 Mon Sep 17 00:00:00 2001 From: czarkoff Date: Mon, 18 May 2015 20:26:16 +0000 Subject: [PATCH] Make TAPE=- mean stdout in tar Some scripts and GUI ssh clients assume that tar writes to standard output by default. This changes allows enforcing such behavior by setting TAPE="-" in user profile. Also, this makes parsing argument to "-f" option and contents of TAPE environment variable consistent. OK guenther@, jmc@ and sthen@ --- bin/pax/options.c | 17 +++++++++++------ bin/pax/tar.1 | 13 +++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/pax/options.c b/bin/pax/options.c index be2ffb2c245..2b15d395203 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.90 2015/04/18 18:28:37 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.91 2015/05/18 20:26:16 czarkoff Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -877,6 +877,16 @@ tar_options(int argc, char **argv) argc -= optind; argv += optind; + if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) { + arcname = getenv("TAPE"); + if ((arcname == NULL) || (*arcname == '\0')) + arcname = _PATH_DEFTAPE; + else if ((arcname[0] == '-') && (arcname[1]== '\0')) { + arcname = NULL; + fstdin = 1; + } + } + /* Traditional tar behaviour (pax uses stderr unless in list mode) */ if (fstdin == 1 && act == ARCHIVE) listf = stderr; @@ -1030,11 +1040,6 @@ tar_options(int argc, char **argv) maxflt = 0; break; } - if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) { - arcname = getenv("TAPE"); - if ((arcname == NULL) || (*arcname == '\0')) - arcname = _PATH_DEFTAPE; - } } int mkpath(char *); diff --git a/bin/pax/tar.1 b/bin/pax/tar.1 index c4c10834f88..ba487d4233f 100644 --- a/bin/pax/tar.1 +++ b/bin/pax/tar.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tar.1,v 1.57 2015/01/15 19:06:31 schwarze Exp $ +.\" $OpenBSD: tar.1,v 1.58 2015/05/18 20:26:16 czarkoff Exp $ .\" .\" Copyright (c) 1996 SigmaSoft, Th. Lockert .\" All rights reserved. @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: January 15 2015 $ +.Dd $Mdocdate: May 18 2015 $ .Dt TAR 1 .Os .Sh NAME @@ -145,6 +145,12 @@ Stop after the first error. Filename where the archive is stored. Defaults to .Pa /dev/rst0 . +If set to hyphen +.Pq Sq - +standard output is used. +See also the +.Ev TAPE +environment variable. .It Fl H Follow symlinks given on the command line only. .It Fl h @@ -287,6 +293,9 @@ Path in which to store temporary files. .It Ev TAPE Default tape device to use instead of .Pa /dev/rst0 . +If set to hyphen +.Pq Sq - +standard output is used. .El .Sh FILES .Bl -tag -width "/dev/rst0" -- 2.20.1