]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
Make vipw error message less cryptic
authorPiotr Pawel Stefaniak <pstef@FreeBSD.org>
Sat, 20 Jun 2020 06:20:00 +0000 (06:20 +0000)
committerPiotr Pawel Stefaniak <pstef@FreeBSD.org>
Sat, 20 Jun 2020 06:20:00 +0000 (06:20 +0000)
Unable to find an editor, vipw would give this error:
# env EDITOR=fnord vipw
vipw: pw_edit(): No such file or directory

vigr or crontab do better:
# env EDITOR=fnord crontab -e
crontab: no crontab for root - using an empty one
crontab: fnord: No such file or directory
crontab: "fnord" exited with status 1

After this change, vipw behaves more like vigr or crontab:
# env EDITOR=fnord vipw
vipw: fnord: No such file or directory
vipw: "fnord" exited with status 1

Reviewed by: rpokala, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D25369

libutil/pw_util.c

index 94db72029062cfacefb1211276119f35fb8b0e4c..4d708c007f448b2395d90ced530300d689ac8d82 100644 (file)
@@ -308,12 +308,13 @@ pw_edit(int notsetuid)
                sigaction(SIGQUIT, &sa_quit, NULL);
                sigprocmask(SIG_SETMASK, &oldsigset, NULL);
                if (notsetuid) {
                sigaction(SIGQUIT, &sa_quit, NULL);
                sigprocmask(SIG_SETMASK, &oldsigset, NULL);
                if (notsetuid) {
-                       (void)setgid(getgid());
-                       (void)setuid(getuid());
+                       if (setgid(getgid()) == -1)
+                               err(1, "setgid");
+                       if (setuid(getuid()) == -1)
+                               err(1, "setuid");
                }
                }
-               errno = 0;
                execlp(editor, editor, tempname, (char *)NULL);
                execlp(editor, editor, tempname, (char *)NULL);
-               _exit(errno);
+               err(1, "%s", editor);
        default:
                /* parent */
                break;
        default:
                /* parent */
                break;
@@ -327,7 +328,9 @@ pw_edit(int notsetuid)
                        break;
                } else if (WIFSTOPPED(pstat)) {
                        raise(WSTOPSIG(pstat));
                        break;
                } else if (WIFSTOPPED(pstat)) {
                        raise(WSTOPSIG(pstat));
-               } else if (WIFEXITED(pstat) && WEXITSTATUS(pstat) == 0) {
+               } else if (WIFEXITED(pstat)) {
+                       if (WEXITSTATUS(pstat) != 0)
+                               errx(1, "\"%s\" exited with status %d", editor, WEXITSTATUS(pstat));
                        editpid = -1;
                        break;
                } else {
                        editpid = -1;
                        break;
                } else {