FAI ainsl exit code, softupdate, scripts/FAIBASE/10-misc
Rob
rclemley at booksys.com
Tue Jun 22 21:15:07 CEST 2010
On 06/14/2010 09:26 AM, Thomas Lange wrote:
>>>>>> On Tue, 01 Jun 2010 20:03:00 -0500, Rob<rclemley at booksys.com> said:
> > Patch attached. This patch is for the newly modified ainsl(1) command
> > which returns 0 if the LINE/PATTERN was found in the file (revision 5797).
> Hi Rob,
>
> where is exit code 2 or 13 set in ainsl? I cannot find this in the code.
The codes 2 and 13 were determined by manual testing. In several
places ainsl calls the perl "die" function. "die" exits with the
current value of $! (errno). If $! is 0 , exits with the value of
($?>> 8) (backtick `command` status). If ($?>> 8) is 0 , exits with 255.
Exit code 2 (no such file or directory) comes from line 126:
-f $filename || die "ainsl: target file $filename does not exist.\n";
The "-f" test will set the errno to 2 (no such file or directory), which
is then returned by "die". This happens if "autocreate" is not enabled.
Exit code 13 (permission denied) comes from line 141:
open (INFILE, ">>$filename") or die "ainsl: can't open $filename for
writing. $!";
This "die" returns 13 if the permissions prohibit writing. This "open"
statement could also return 30, "Read-only file system", if the target
fs is read-only.
I also noticed a possible not detected error. That is the "print" and
"close" at the end of the ainsl source. If for some reason the target
file system is full, the error returned by print or, more probably
"close" would be ignored. This would return the exit code 28 - No space
left on device. My recommendation would be to add "die" statements to
the last 2 lines of the file:
print INFILE $line,"\n" || die "ainsl: cannot print to file
$filename: $!";
close(INFILE) or die "ainsl: error saving file $filename: $!";
On a full file system, the above "close" will return 28, "No space left
on device". I think that should also be listed in EXIT CODES (if we add
a check for the close return value in ainsl source). So maybe the
document would say:
.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.
Or, we could be simple and say only that any non-zero means that ainsl
failed to verify or add PATTERN in FILE. Alternative:
.TP
.B non-zero
Either FILE does not exist or FILE does not contain PATTERN/LINE and
cannot be written. A diagnostic message will be printed on stderr
which explains the details.
In all cases, it seems a good idea to check the return code of the final
print and close statements.
Thank you,
Rob
> +.SH EXIT CODES
> +.TP
> +.B 0
> +Success: Either FILE contains the LINE/PATTERN or LINE was appended to FILE.
> +.TP
> +.B 2
> +FILE does not exist and the autocreate option (-a) is not present.
> +.TP
> +.B 13
> +FILE cannot be opened for writing and LINE/PATTERN was not found in file.
> +
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.uni-koeln.de/pipermail/linux-fai/attachments/20100622/ad032ed3/attachment.htm
More information about the linux-fai
mailing list