<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 06/14/2010 09:26 AM, Thomas Lange wrote:
<blockquote
cite="mid:19478.15361.158742.84502@suenner.informatik.uni-koeln.de"
type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">On Tue, 01 Jun 2010 20:03:00 -0500, Rob <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:rclemley@booksys.com"><rclemley@booksys.com></a> said:
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""> > 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.
</pre>
</blockquote>
<br>
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.<br>
<br>
Exit code 2 (no such file or directory) comes from line 126:<br>
<blockquote><tt>-f $filename || die "ainsl: target file $filename
does not exist.\n";<br>
<br>
</tt></blockquote>
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.<br>
<br>
Exit code 13 (permission denied) comes from line 141:<br>
<blockquote><tt>open (INFILE, ">>$filename") or die "ainsl:
can't open $filename for writing. $!";</tt><br>
<br>
</blockquote>
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.<br>
<br>
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:<br>
<blockquote><tt>print INFILE $line,"\n" || die "ainsl: cannot print
to file $filename: $!";</tt><br>
<tt>close(INFILE) or die "ainsl: error saving file $filename: $!";</tt><br>
</blockquote>
<br>
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:<br>
<blockquote><tt>.TP<br>
.B 13<br>
Permissions do not allow writing to FILE and LINE/PATTERN was
not found in file.<br>
.TP<br>
.B 28<br>
FILE cannot written because the filesystem has no space and
LINE/PATTERN was not found in file.</tt><tt><br>
.TP<br>
.B 30<br>
FILE cannot written because the filesystem is read-only and
LINE/PATTERN was not found in file.</tt><br>
<br>
</blockquote>
Or, we could be simple and say only that any non-zero means that
ainsl failed to verify or add PATTERN in FILE. Alternative:<br>
<blockquote><tt>.TP</tt><br>
<tt>.B non-zero</tt><br>
<tt>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.</tt><br>
</blockquote>
<br>
In all cases, it seems a good idea to check the return code of the
final print and close statements.<br>
<br>
Thank you,<br>
Rob<br>
<br>
<blockquote
cite="mid:19478.15361.158742.84502@suenner.informatik.uni-koeln.de"
type="cite">
<pre wrap="">+.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.
+
</pre>
</blockquote>
</body>
</html>