Signed-off-by: Marek Polacek <mmpolacek@xxxxxxxxx> --- login-utils/vipw.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-) diff --git a/login-utils/vipw.c b/login-utils/vipw.c index e7247e4..c970820 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -60,6 +60,7 @@ static char version_string[] = "vipw 1.4"; #include <signal.h> #include <fcntl.h> #include <errno.h> +#include <err.h> #include <paths.h> #include <unistd.h> @@ -149,11 +150,9 @@ pw_lock(void) { } #endif - if ((fd = open(tmptmp_file, O_WRONLY|O_CREAT, 0600)) == -1) { - (void)fprintf(stderr, - "%s: %s: %s\n", progname, tmptmp_file, strerror(errno)); - exit(1); - } + if ((fd = open(tmptmp_file, O_WRONLY|O_CREAT, 0600)) == -1) + err(EXIT_FAILURE, _("opening %s failed"), tmptmp_file); + ret = link(tmptmp_file, tmp_file); (void)unlink(tmptmp_file); if (ret == -1) { @@ -168,7 +167,7 @@ pw_lock(void) { (void)fprintf(stderr, _("%s: can't link %s: %s\n"), progname, tmp_file, strerror(errsv)); } - exit(1); + exit(EXIT_FAILURE); } lockfd = open(orig_file, O_RDONLY, 0); @@ -177,13 +176,13 @@ pw_lock(void) { (void)fprintf(stderr, "%s: %s: %s\n", progname, orig_file, strerror(errno)); unlink(tmp_file); - exit(1); + exit(EXIT_FAILURE); } copyfile(lockfd, fd); (void)close(lockfd); (void)close(fd); - return(1); + return 1; } static void @@ -216,7 +215,7 @@ pw_unlock(void) { fprintf(stderr, _("%s: can't unlock %s: %s (your changes are still in %s)\n"), progname, orig_file, strerror(errsv), tmp_file); - exit(1); + exit(EXIT_FAILURE); } unlink(tmp_file); } @@ -236,17 +235,18 @@ pw_edit(int notsetuid) { p = editor; pid = fork(); - if (pid < 0) { - (void)fprintf(stderr, _("%s: Cannot fork\n"), progname); - exit(1); - } + if (pid < 0) + err(EXIT_FAILURE, _("fork failed")); + if (!pid) { if (notsetuid) { (void)setgid(getgid()); (void)setuid(getuid()); } execlp(editor, p, tmp_file, NULL); - _exit(1); + + /* Shouldn't get here */ + _exit(EXIT_FAILURE); } for (;;) { pid = waitpid(pid, &pstat, WUNTRACED); @@ -328,7 +328,7 @@ int main(int argc, char *argv[]) { if ((argc > 1) && (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) { printf("%s\n", version_string); - exit(0); + exit(EXIT_SUCCESS); } edit_file(0); @@ -358,5 +358,5 @@ int main(int argc, char *argv[]) { } } - exit(0); + exit(EXIT_SUCCESS); } -- 1.7.3.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html