Anonymous | Login | 2024-04-20 07:31 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000478 | [1003.1(2004)/Issue 6] Shell and Utilities | Objection | Clarification Requested | 2011-07-21 11:07 | 2019-06-10 08:55 | ||
Reporter | geoffclare | View Status | public | ||||
Assigned To | ajosey | ||||||
Priority | normal | Resolution | Accepted As Marked | ||||
Status | Closed | ||||||
Name | Geoff Clare | ||||||
Organization | The Open Group | ||||||
User Reference | |||||||
Section | cmp | ||||||
Page Number | 253 | ||||||
Line Number | 9875 | ||||||
Interp Status | Approved | ||||||
Final Accepted Text | See Note: 0000944 | ||||||
Summary | 0000478: Should cmp -s write to stderr when an error occurs? | ||||||
Description |
The description of the cmp -s option is: Write nothing for differing files; return exit status only. Clearly the intention is that "return exit status only" when taken in context is supposed to apply only to the case of differing files. It is saying that, given that nothing is written, the only thing that indicates the files are different is the exit status. However, it could (at a stretch) be misinterpreted as a stand-alone statement that extends the requirement. The intended meaning is confirmed by the statements in the STDOUT section, "No output shall be written to standard output when the -s option is used", and in the STDERR section, "If file1 and file2 are identical for the entire length of the shorter file, in the POSIX locale the following diagnostic message shall be written, unless the -s option is specified" (with no other mention of -s). I.e. the intention is that nothing should be written to stdout or stderr when the exit status is 1, but an error message should still be written to stderr when the exit status is greater than 1. (The intention is the same in Issue 7 although the text in the STDERR section differs as a result of a change related to the -l option.) However, existing practice (on the systems I have tried) is that -s also turns off some, or possibly all, error messages related to opening files. (I tried a non-existent file and an unreadable file.) I also checked behaviour for a read error and got three different results: 1. The error message produced without -s was turned off by -s. 2. The error message was written regardless of whether -s was used. 3. The read error was treated as EOF, which I would say is a bug. The read() error behaviour was tested by causing an EIO using: (trap "" TTIN; cmp [-s] - somefile < /dev/tty) & in a shell with job-control enabled. When I got result 3 I confirmed that the read() call made by cmp did return an EIO error, by using a system call trace utility. Typically when a difference between the standard and existing practice is found, and nothing in the rationale indicates that it was deliberate, the standard is relaxed to allow existing practice. However, for cmp -s I believe there are reasonable grounds for affirming the current requirement. The -s option, as described in the standard, produces a behaviour that is awkward to achieve by other means. For example, this function could be used: silent_cmp() { # compare files with no output except error messages message=$(cmp "$@" 2>&1 >/dev/null) status=$? case $status in (0|1) ;; (*) printf '%s\n' "$message" ;; esac return $status } By contrast, complete silence is easily achieved using simple redirection to /dev/null. I have produced detailed proposed changes for the two most likely options. A third middle-ground option could also be considered where -s is allowed to suppress error messages for non-existent or unreadable files but not for other errors, since applications can easily check for those conditions using "test -r". This would mean systems that produce result type 2 above might not need to change (depending on how they handle other open() errors such as ENFILE). |
||||||
Desired Action |
Option 1: affirm current requirement Issue a "standard is clear, standard is right" interpretation, including rationale that the phrase "return exit status only" in the description of -s, in context, applies only to the case of differing files. The Notes to the Editor should be: The description of -s is considered to be unambiguous, but the following changes are proposed for a future Issue 7 Technical Corrigendum (or for Issue 8 if there are no further TCs) to ensure it is not misinterpreted. On L9875 (L81246 in Issue 7) change the -s description from: Write nothing for differing files; return exit status only. to: Write nothing to standard output or standard error when files differ; indicate differing files through exit status only. After L9964 (L81334 in Issue 7) append to RATIONALE: Historically, the -s option prevented some or all error messages from being written to standard error, not just the "EOF" message. With this behavior, -s was not very useful in portable applications; the only way to ensure consistent behavior of cmp when -s was used was to redirect standard error to /dev/null. The standard requires that -s only suppresses the "EOF" message to standard error (and all output to standard output). If an error is encountered, as indicated by an exit status greater than 1, a diagnostic message must still be written. This change from historical practice is considered to be justified because the required behavior is awkward to achieve by other means. For example, this function could be used: silent_cmp() { # compare files with no output except error messages message=$(cmp "$@" 2>&1 >/dev/null) status=$? case $status in (0|1) ;; (*) printf '%s\n' "$message" ;; esac return $status } Option 2: allow existing practice Issue either a "standard is clear, standard is wrong" or a "standard is unclear" interpretation. The Notes to the Editor should be: On L9875 (L81246 in Issue 7) change the -s description from: Write nothing for differing files; return exit status only. to: Write nothing to standard output or standard error when files differ; indicate differing files through exit status only. It is unspecified whether a diagnostic message is written to standard error when an error is encountered; if a message is not written, the error is indicated through exit status only. After L9924 (L81295 in Issue 7) append to STDERR: If the -s option is used and an error occurs, it is unspecified whether a diagnostic message is written to standard error. After L9944 (L81314 in Issue 7) append to APPLICATION USAGE: Since the behavior of -s differs between implementations as to whether error messages are written, the only way to ensure consistent behavior of cmp when -s is used is to redirect standard error to /dev/null. If error messages are wanted, instead of using -s standard output should be redirected to /dev/null, and anything written to standard error should be discarded if the exit status is 1. For example: silent_cmp() { # compare files with no output except error messages message=$(cmp "$@" 2>&1 >/dev/null) status=$? case $status in (0|1) ;; (*) printf '%s\n' "$message" ;; esac return $status } |
||||||
Tags | tc2-2008 | ||||||
Attached Files | |||||||
|
Issue History | |||
Date Modified | Username | Field | Change |
2011-07-21 11:07 | geoffclare | New Issue | |
2011-07-21 11:07 | geoffclare | Status | New => Under Review |
2011-07-21 11:07 | geoffclare | Assigned To | => ajosey |
2011-07-21 11:07 | geoffclare | Name | => Geoff Clare |
2011-07-21 11:07 | geoffclare | Organization | => The Open Group |
2011-07-21 11:07 | geoffclare | Section | => cmp |
2011-07-21 11:07 | geoffclare | Page Number | => 253 |
2011-07-21 11:07 | geoffclare | Line Number | => 9875 |
2011-07-21 11:07 | geoffclare | Interp Status | => --- |
2011-08-25 16:10 | nick | Note Added: 0000944 | |
2011-08-25 16:10 | nick | Status | Under Review => Interpretation Required |
2011-08-25 16:10 | nick | Resolution | Open => Accepted As Marked |
2011-08-25 16:10 | nick | Description Updated | |
2011-08-25 16:10 | nick | Desired Action Updated | |
2011-08-25 16:11 | nick | Final Accepted Text | => See Note: 0000944 |
2011-08-25 16:11 | nick | Interp Status | --- => Pending |
2011-08-25 16:11 | nick | Tag Attached: tc2-2008 | |
2011-08-25 16:13 | nick | Note Edited: 0000944 | |
2013-09-06 04:49 | ajosey | Note Added: 0001798 | |
2013-09-06 04:49 | ajosey | Status | Interpretation Required => Resolution Proposed |
2013-09-06 05:01 | ajosey | Interp Status | Pending => Proposed |
2013-09-06 05:04 | ajosey | Status | Resolution Proposed => Interpretation Required |
2013-10-14 13:03 | ajosey | Interp Status | Proposed => Approved |
2013-10-14 13:03 | ajosey | Note Added: 0001882 | |
2019-06-10 08:55 | agadmin | Status | Interpretation Required => Closed |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |