Bug 139314

Summary: [patch] install(1): install -d reports success on failure
Product: Base System Reporter: Thomas Swan <thomas.swan>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: In Progress ---    
Severity: Affects Only Me CC: swills
Priority: Normal Keywords: patch
Version: Unspecified   
Hardware: Any   
OS: Any   
URL: https://reviews.freebsd.org/D14626

Description Thomas Swan 2009-10-02 20:20:00 UTC
/usr/bin/install exits zero when it should exit non-zero when installing a directory.  

install should exit non-zero according to the man page.

How-To-Repeat: as root:
# /usr/bin/install -d -m755 /tmp/root-owned

as a mortal:
$ /usr/bin/install -d -m755 /tmp/root-owned
install: chmod 755 /tmp/root-owned: Operation not permitted
$ echo $?
0
Comment 1 Mikolaj Golub 2009-10-13 21:18:39 UTC
On Fri, 2 Oct 2009 19:10:59 GMT Thomas Swan wrote:
 TS> as root:
 TS> # /usr/bin/install -d -m755 /tmp/root-owned

 TS> as a mortal:
 TS> $ /usr/bin/install -d -m755 /tmp/root-owned
 TS> install: chmod 755 /tmp/root-owned: Operation not permitted
 TS> $ echo $?
 TS> 0

Actually I am not 100% sure this is a bug. Please note, the message is that it
was not able to chmod, not to create directory. install(1) considers this is
as a warning, not a error message.

If you try to create new directory then you will get error exit code:

zhuzha:~% /usr/bin/install -d -m755 /tmp/root-owned/test
install: mkdir /tmp/root-owned/test: Permission denied
zhuzha:~% echo $?                                       
71

In the install code warn() is called when chmod() has failed. So if this still
looks like a bug the patch is simple -- just replace warn(...) with
err(EX_OSERR, ...).  But then may be the same thing should be done on chown()
failure (currently warn() is called here too).

-- 
Mikolaj Golub
Comment 2 Volker Werth freebsd_committer freebsd_triage 2010-08-21 20:42:44 UTC
State Changed
From-To: open->analyzed

I'm somewhat undecided about this report. 
IMO if a tool is being told to do one thing and it can't be done, it can be 
seen as a failure. If install is able to install a file / directory but isn't 
able to set modes or owner (when told do set them), it should be seen as a 
failed job (do everything right or signal error, but not do half the way right). 

Changing that may break a lot of places where install is being used. 
I've created a patch for that which is signalling a failure if mode or owner 
can't be set only when -T has been given. 

The patch can be found at: 
http://people.freebsd.org/~vwe/files/patches/pr139314_xinstall.diff 
but I'm really not happy about that. 
Either use something similar to my patch or we can close this PR as WONTFIX.
Comment 3 Steve Wills freebsd_committer freebsd_triage 2018-03-08 16:34:01 UTC
Updated the patch and created a review for it.
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:36:50 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>