Bug 232657

Summary: usr.sbin/sysrc: incorrectly returns return code 0 after failing to modify a file
Product: Base System Reporter: Mateusz Kwiatkowski <kwiat3k>
Component: miscAssignee: freebsd-bugs mailing list <bugs>
Status: Open ---    
Severity: Affects Many People CC: 0mp, vasko.tim
Priority: --- Keywords: needs-patch
Version: 11.2-STABLE   
Hardware: Any   
OS: Any   

Description Mateusz Kwiatkowski 2018-10-24 18:39:11 UTC
To reproduce try to modify file in non existing directory:
$ sysrc -f ./nonexistent/testfile foo="bar"
/usr/sbin/sysrc: cannot create ./nonexistent/testfile: No such file or directory
$ echo $?

The exit code is 0 while I was expecting to see ENOENT (2).

It's the same when I try to modify file that is not accessible:
$ sysrc -f /etc/rc.conf foo=bar
/usr/sbin/sysrc: cannot create /etc/rc.conf: Permission denied
$ echo $?

In this case EACCESS (13) should be returned.

I don't think that distinguishing these errors is needed. Returning anything different than 0 should do the job.