From e210894a523b6d7306ae507ba2f2fe7b14290aad Mon Sep 17 00:00:00 2001 From: Andinus Date: Thu, 11 Jun 2020 02:19:17 +0530 Subject: Require OpenBSD:: only on OpenBSD, re-style code --- pictor.pl | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/pictor.pl b/pictor.pl index bffc7e2..7bfe2ea 100755 --- a/pictor.pl +++ b/pictor.pl @@ -3,19 +3,29 @@ use strict; use warnings; use feature 'say'; -use OpenBSD::Pledge; -use OpenBSD::Unveil; + +use constant is_OpenBSD => $^O eq "openbsd"; +if (is_OpenBSD) { + require OpenBSD::Unveil; + OpenBSD::Unveil->import; + + require OpenBSD::Pledge; + OpenBSD::Pledge->import; +} else { + sub unveil { return 1; } + sub pledge { return 1; } +} # Inititalize pledge. -pledge( qw( stdio rpath unveil ) ) or - die "Unable to pledge: $!"; +pledge( qw( stdio rpath unveil ) ) + or die "Unable to pledge: $!"; # $term will store the user input. my $term; # User must pass at least one argument. -die "usage: pictor term\n" if - @ARGV < 1; +die "usage: pictor term\n" + if @ARGV < 1; # Assume first argument to be term. $term = $ARGV[0]; @@ -23,29 +33,29 @@ $term = $ARGV[0]; # User can rename this program to "wtf" & run "wtf is wtf" instead of # "wtf wtf", "wtf is term" looks better so we use $ARGV[1] as $term if # $ARGV[0] is "is". -$term = $ARGV[1] if - $ARGV[0] eq "is"; +$term = $ARGV[1] + if $ARGV[0] eq "is"; # files contains list of all files to search for acronyms. my @files = ( '/usr/local/share/misc/acronyms', '/usr/local/share/misc/acronyms-o', - '/usr/local/share/misc/acronyms.comp' - ); + '/usr/local/share/misc/acronyms.comp', +); # Unveil each file with only read permission. foreach my $fn (@files) { - unveil( $fn, "r" ) or - die "Unable to unveil: $!"; + unveil( $fn, "r" ) + or die "Unable to unveil: $!"; } # Block further unveil calls. -unveil() or - die "Unable to lock unveil: $!"; +unveil() + or die "Unable to lock unveil: $!"; # Drop unveil permission. -pledge( qw( stdio rpath ) ) or - die "Unable to pledge: $!"; +pledge( qw( stdio rpath ) ) + or die "Unable to pledge: $!"; # $total_acronyms will hold the total number of acronyms we find. my $total_acronyms = 0; @@ -58,7 +68,7 @@ foreach my $fn (@files) { do { warn "Unable to open $fn: $!\n"; next; - }; + }; while (my $line = readline $fh) { # \Q is quotemeta, \E terminates it because otherwise it would @@ -73,13 +83,13 @@ foreach my $fn (@files) { } # Drop rpath permission. -pledge( qw( stdio ) ) or - die "Unable to pledge: $!"; +pledge( qw( stdio ) ) + or die "Unable to pledge: $!"; # die if no match is found. -die "I don't know what '$term' means!\n" unless - $total_acronyms; +die "I don't know what '$term' means!\n" + unless $total_acronyms; # Drop pledge permissions. -pledge() or - die "Unable to pledge: $!"; +pledge() + or die "Unable to pledge: $!"; -- cgit 1.4.1-2-gfad0