error out if stdout is a tty

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-07-28 16:58:47 +02:00
parent 117a1591c5
commit d82afec5de
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1
3 changed files with 21 additions and 2 deletions

View file

@ -322,3 +322,5 @@ Modes: fakechroot
Test: dev-ptmx
Modes: root unshare
Needs-QEMU: true
Test: error-if-stdout-is-tty

View file

@ -37,7 +37,8 @@ use Cwd qw(abs_path getcwd);
require "syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
use Fcntl qw(S_IFCHR S_IFBLK FD_CLOEXEC F_GETFD F_SETFD);
use List::Util qw(any none);
use POSIX qw(SIGINT SIGHUP SIGPIPE SIGTERM SIG_BLOCK SIG_UNBLOCK strftime);
use POSIX
qw(SIGINT SIGHUP SIGPIPE SIGTERM SIG_BLOCK SIG_UNBLOCK strftime isatty);
use Carp;
use Term::ANSIColor;
use Socket;
@ -5126,7 +5127,11 @@ sub main() {
$options->{sourceslists} = $sourceslists;
}
if ($options->{target} ne '-') {
if ($options->{target} eq '-') {
if (POSIX::isatty STDOUT) {
error "stdout is a an interactive tty";
}
} else {
my $abs_path = abs_path($options->{target});
if (!defined $abs_path) {
error "unable to get absolute path of target directory"

View file

@ -0,0 +1,12 @@
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
ret=0
script -qfec "{{ CMD }} --mode={{ MODE }} --variant=apt {{ DIST }} - {{ MIRROR }}" /dev/null || ret=$?
if [ "$ret" = 0 ]; then
echo expected failure but got exit $ret >&2
exit 1
fi