From c9f7267c6bc6f5bc93109a8d71f73a26aae6e088 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 9 Dec 1998 12:40:15 +0000 Subject: [PATCH] Print a clear error message when the reason for not being able to create the password lock is other than EEXIST. --- usr.sbin/vipw/vipw.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c index 552fc3503db8..08d57ee5156a 100644 --- a/usr.sbin/vipw/vipw.c +++ b/usr.sbin/vipw/vipw.c @@ -1,4 +1,4 @@ -/* $NetBSD: vipw.c,v 1.5 1997/10/17 14:31:13 lukem Exp $ */ +/* $NetBSD: vipw.c,v 1.6 1998/12/09 12:40:15 christos Exp $ */ /* * Copyright (c) 1987, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\n\ #if 0 static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94"; #else -__RCSID("$NetBSD: vipw.c,v 1.5 1997/10/17 14:31:13 lukem Exp $"); +__RCSID("$NetBSD: vipw.c,v 1.6 1998/12/09 12:40:15 christos Exp $"); #endif #endif /* not lint */ @@ -57,11 +57,12 @@ __RCSID("$NetBSD: vipw.c,v 1.5 1997/10/17 14:31:13 lukem Exp $"); #include #include #include +#include #include -void copyfile __P((int, int)); int main __P((int, char **)); -void usage __P((void)); +static void copyfile __P((int, int)); +static void usage __P((void)); int main(argc, argv) @@ -87,8 +88,13 @@ main(argc, argv) pw_init(); tfd = pw_lock(0); - if (tfd < 0) - errx(1, "the passwd file is busy."); + if (tfd < 0) { + if (errno == EEXIST) + errx(1, "the passwd file is busy."); + else + err(1, "%s", _PATH_MASTERPASSWD_LOCK); + } + pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0); if (pfd < 0) pw_error(_PATH_MASTERPASSWD, 1, 1); @@ -109,10 +115,10 @@ main(argc, argv) break; pw_prompt(); } - exit(0); + return 0; } -void +static void copyfile(from, to) int from, to; { @@ -127,10 +133,11 @@ copyfile(from, to) pw_error(_PATH_MASTERPASSWD, 1, 1); } -void +static void usage() { + extern char *__progname; - (void)fprintf(stderr, "usage: vipw\n"); + (void)fprintf(stderr, "Usage: %s\n", __progname); exit(1); }