Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
Improved error handling in case target device is full and document
ainsl exit codes (thanks Rob <rclemley@booksys.com>).
  • Loading branch information
Thomas Lange committed Feb 5, 2012
1 parent 27c7da5 commit 0a43764
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/ainsl
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ exit 0 if $found; # nothing to append
print "ainsl: appending to $filename: $line\n" if $verbose;
exit 0 if $opt_n;
open (INFILE, ">>$filename") or die "ainsl: can't open $filename for writing. $!";
print INFILE $line,"\n";
close(INFILE);
print INFILE $line,"\n" || die "ainsl: cannot print to file $filename: $!";
close(INFILE) or die "ainsl: error saving file $filename: $!";
19 changes: 19 additions & 0 deletions man/ainsl.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ are only treated specialy at the beginning or end of the pattern and
are used for matching, not when adding the line. Additionaly,
the following characters are escaped in LINE: ( ) +

The exit code returned by ainsl is 0 on success and non-zero
on error. See the section EXIT CODES.

.SH OPTIONS
.TP
.B \-a
Expand Down Expand Up @@ -64,6 +67,22 @@ ainsl \-s /etc/exports '/srv/www @linuxhosts(async,rw) backup(async,ro)'

Add exports entry without exactly matching spaces.

.SH EXIT CODES
.TP
.B 0
Success: Either FILE contains the LINE/PATTERN or LINE was appended to FILE.
.TP
.B 13
Permissions do not allow writing to FILE and LINE/PATTERN was not found in file.
.TP
.B 28
FILE cannot written because the filesystem has no space and LINE/PATTERN was not
found in file.
.TP
.B 30
FILE cannot written because the filesystem is read-only and LINE/PATTERN was not
found in file.

.SH NOTES
This is a similar function to AppendIfNoSuchLine from cfengine(8).
.SH SEE ALSO
Expand Down

0 comments on commit 0a43764

Please sign in to comment.