Bug 40572 - vipw(8) prints silly message if $EDITOR fails
Summary: vipw(8) prints silly message if $EDITOR fails
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Fernando Apesteguía
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-14 22:50 UTC by Ian Jackson
Modified: 2020-06-22 16:06 UTC (History)
3 users (show)

See Also:


Attachments
patch to lib/libutil/pw_util.c (832 bytes, patch)
2018-02-19 18:47 UTC, Fernando Apesteguía
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Jackson 2002-07-14 22:50:01 UTC
when the external EDITOR invoked by vipw fails (exits nonzero),
vipw prints a message involving strerror(errno), instead of the
exit status of the failed program.

Fix: 

src/lib/libutil/pw_util.c:pw_edit and all its callers would have to
be changed to allow it other error returns besides -1 setting errno.
How-To-Repeat: bash-2.05# EDITOR=false vipw
vipw: false: Operation not permitted
vipw: /etc/master.passwd: unchanged
bash-2.05#
Comment 1 Baptiste Daroussin freebsd_committer freebsd_triage 2014-10-02 07:30:02 UTC
It now says
vipw: pw_edit(): No such file or directory
 which is not better
Comment 2 Fernando Apesteguía freebsd_committer freebsd_triage 2018-02-19 18:47:22 UTC
Created attachment 190815 [details]
patch to lib/libutil/pw_util.c

With this patch, we have a nicer output. The point is to return 0 (file not modified) if the processes exited abnormally. I think it is pretty much the correct behavior. With this patch, on -CURRENT, this is the output:

# export EDITOR=false
# vipw
'false' failed with error code 1: Operation not permitted
vipw: no changes made

# export EDITOR=/home/test/idontexist
# vipw
'/home/test/idontexist' failed with error code 2: No such file or directory
vipw: no changes made

# export EDITOR=vim
# vipw
(I write the file)
vipw: password list updated

# vipw
(I do not write the file)
vipw: no changes made

The patch can me MFC'd to 11 cleanly.
Comment 3 Fernando Apesteguía freebsd_committer freebsd_triage 2020-03-21 19:08:48 UTC
Can anyone have a look at this?

I'm willing to improve the patch if necessary.

Cheers
Comment 4 Piotr Pawel Stefaniak freebsd_committer freebsd_triage 2020-06-21 17:02:17 UTC
I wasn't aware of this PR until now. This should be fixed by https://svnweb.freebsd.org/changeset/base/362430
Comment 5 Fernando Apesteguía freebsd_committer freebsd_triage 2020-06-22 16:06:02 UTC
It is, confirmed in 13-current r362494

Thanks