[Ferm] [PATCH] Allow stdin to be used as an inputfile
Faidon Liambotis
paravoid at debian.org
Wed Jul 6 22:58:40 CEST 2011
Use "-" as an stdin shortcut. This allows constructs such as:
echo "chain INPUT proto tcp dport 22 DROP;" | ferm --noflush -
to actually work.
These may be useful for testing, running from shell scripts etc.
Combining it with @include and ferm functions could be especially
useful.
---
src/ferm | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/ferm b/src/ferm
index 6dcd24f..4455960 100755
--- a/src/ferm
+++ b/src/ferm
@@ -788,9 +788,18 @@ sub open_script($) {
if $s->{filename} eq $filename;
}
- local *FILE;
- open FILE, "$filename" or die("Failed to open $filename: $!\n");
- my $handle = *FILE;
+ my $handle;
+ if ($filename eq '-') {
+ # Note that this only allowed in the command-line argument and not
+ # @includes, since those are filtered by collect_filenames()
+ $handle = *STDIN;
+ # also set a filename label so that error messages are more helpful
+ $filename = "<stdin>";
+ } else {
+ local *FILE;
+ open FILE, "$filename" or die("Failed to open $filename: $!\n");
+ $handle = *FILE;
+ }
$script = { filename => $filename,
handle => $handle,
--
1.7.2.5
More information about the Ferm
mailing list