diff --git a/wipe.pl b/wipe.pl index 96b1a15..8e7e0a8 100755 --- a/wipe.pl +++ b/wipe.pl @@ -9,16 +9,25 @@ use v5.10; # loose badass and you don't need no stinkin' safety net. use constant CONFIRMATION_PHRASE => "I am a pretty pink pineapple!"; -if ($>) { - say "This program requires root, sorry."; - exit; -} - my $termios = POSIX::Termios->new; $termios->getattr(fileno(STDIN)); # fetch this value once and cache it my $startup_lflag = $termios->getlflag(); +# set termios lflag to not echo keystrokes, and take us out of line mode +$termios->setlflag($startup_lflag & ~(ECHO | ECHOK | ICANON)); +$termios->setattr(fileno(STDIN), TCSANOW); + +END { # reset termios lflag on exit + $termios->setlflag($startup_lflag); + $termios->setattr(fileno(STDIN), TCSANOW); +} + +if ($>) { + say "This program requires root, sorry."; + exit; +} + # define some colors for convenience my %color = ( # use tput to support anything with a terminfo entry @@ -36,15 +45,6 @@ if (!$notreally && CONFIRMATION_PHRASE) { do { say; exit } unless CONFIRMATION_PHRASE eq $confirm; } -# set termios lflag to not echo keystrokes, and take us out of line mode -$termios->setlflag($startup_lflag & ~(ECHO | ECHOK | ICANON)); -$termios->setattr(fileno(STDIN), TCSANOW); - -END { # reset termios lflag on exit - $termios->setlflag($startup_lflag); - $termios->setattr(fileno(STDIN), TCSANOW); -} - # create our random data and store it in RAM so we can keep reusing it open(my $drand, "<", "/dev/urandom"); my $clobber;