A NOTE has been added to this issue. 
====================================================================== 
http://austingroupbugs.net/view.php?id=1161 
====================================================================== 
Reported By:                steffen
Assigned To:                
====================================================================== 
Project:                    1003.1(2016)/Issue7+TC2
Issue ID:                   1161
Category:                   Shell and Utilities
Type:                       Clarification Requested
Severity:                   Editorial
Priority:                   normal
Status:                     New
Name:                       steffen 
Organization:                
User Reference:              
Section:                    command 
Page Number:                2596 
Line Number:                84274 ff. 
Interp Status:              --- 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2017-09-04 13:09 UTC
Last Modified:              2018-04-25 17:57 UTC
====================================================================== 
Summary:                    command -v must find something executable
====================================================================== 

---------------------------------------------------------------------- 
 (0003997) McDutchie (reporter) - 2018-04-25 17:57
 http://austingroupbugs.net/view.php?id=1161#c3997 
---------------------------------------------------------------------- 
Of course, kre is right in that 'command -v' and friends ('command -V' and
'type') cannot be made entirely reliable.

One thing that has not been mentioned is that, even if the result of
'command -v' can be made 100% accurate, it would still be impossible to
eliminate the race condition between that test and the actual attempt to
exec the returned file.

However, I strongly disagree that this means 'command -v' and friends are
not useful at all.

One simple use case is a sanity check when initialising a shell script. A
script that depends on certain utilities may use 'command -v' to check for
their presence and refuse to initialise if they are not found. This would
be much preferable to the program continuing and failing halfway (or, much
worse, *not* failing properly and continuing to run in an inconsistent
state instead, as is all too common for real-world shell scripts).

True, such a sanity check cannot be made "reliable". But it will work fine
in 99.99...% of cases, which is good enough for it to be quite useful
indeed. It should go without saying that this does not remove the need for
proper exception handling.

So the real purpose of 'command -v' is not "can I definitely execute this
utility?" but "can I reasonably expect to succeed at executing this
utility, barring exceptions such as race conditions, I/O errors and ACL
shenanigans?" This is useful data to decide whether or not to attempt to
perform an operation.

Checking for the x bit is a minimum requirement for that use case. Being
aware of things like 'noexec' mounts and ACLs, if present on the system,
would be even better.

Unfortunately, ash and derivatives don't even attempt to check the x bit,
so their 'command -v' commonly returns files that you cannot reasonably
expect to execute. 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2017-09-04 13:09 steffen        New Issue                                    
2017-09-04 13:09 steffen        Name                      => steffen         
2017-09-04 13:09 steffen        Section                   => command         
2017-09-04 13:09 steffen        Page Number               => 2596            
2017-09-04 13:09 steffen        Line Number               => 84274 ff.       
2017-09-04 15:49 kre            Note Added: 0003821                          
2017-09-05 06:58 stephane       Note Added: 0003823                          
2017-09-05 08:30 stephane       Note Added: 0003824                          
2017-09-05 12:34 steffen        Note Added: 0003825                          
2017-09-05 12:39 steffen        Note Added: 0003826                          
2017-09-05 12:47 kre            Note Added: 0003827                          
2017-09-05 13:37 steffen        Note Added: 0003828                          
2017-09-05 15:37 chet_ramey     Note Added: 0003829                          
2017-09-05 15:41 stephane       Note Added: 0003830                          
2017-09-05 16:01 stephane       Note Added: 0003831                          
2017-09-05 16:36 stephane       Note Added: 0003832                          
2017-09-05 17:30 stephane       Note Added: 0003833                          
2017-09-05 20:17 steffen        Note Added: 0003834                          
2017-09-05 20:19 steffen        Note Added: 0003835                          
2017-09-05 20:27 kre            Note Added: 0003836                          
2017-09-05 20:29 chet_ramey     Note Added: 0003837                          
2017-09-05 21:27 eblake         Note Added: 0003838                          
2017-09-05 21:50 kre            Note Added: 0003839                          
2017-09-05 21:52 kre            Note Edited: 0003839                         
2017-09-05 22:21 eblake         Note Added: 0003840                          
2017-09-05 22:23 Don Cragun     Note Added: 0003841                          
2017-09-05 22:24 Don Cragun     Note Deleted: 0003841                        
2017-09-06 00:00 kre            Note Added: 0003842                          
2017-09-06 00:00 kre            Note Deleted: 0003839                        
2017-09-06 08:30 stephane       Note Added: 0003843                          
2017-09-06 08:32 stephane       Note Edited: 0003843                         
2017-09-06 09:30 stephane       Note Added: 0003844                          
2017-09-06 09:37 stephane       Note Added: 0003845                          
2017-09-06 09:50 joerg          Note Added: 0003846                          
2017-09-06 09:50 joerg          Note Edited: 0003846                         
2017-09-06 09:50 joerg          Note Edited: 0003846                         
2017-09-06 09:54 stephane       Note Edited: 0003845                         
2017-09-06 12:55 steffen        Note Added: 0003847                          
2017-09-06 13:41 stephane       Note Added: 0003848                          
2017-09-07 17:31 kre            Note Deleted: 0003842                        
2017-09-07 17:58 kre            Note Added: 0003849                          
2017-09-07 18:29 chet_ramey     Note Added: 0003850                          
2017-09-07 21:17 kre            Note Added: 0003851                          
2017-09-07 21:18 kre            Note Edited: 0003851                         
2017-09-09 19:10 chet_ramey     Note Added: 0003852                          
2018-04-25 17:57 McDutchie      Note Added: 0003997                          
======================================================================


Reply via email to