diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-08-27 02:57:08 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-08-27 02:57:08 +0000 |
commit | 1defc1e9c00f64228ef1a61ee2dc0717cf485b4e (patch) | |
tree | 2648bed0ddacc0c105a78af32a160a0b90023b29 | |
parent | 5b135cfa879ad2271736b3d7c562f84c0bc58e76 (diff) |
Instead of prompting the user whether or not they wish to continue to
wait for the lock on password file just tell the user to interrupt with
^C. This simplifies the locking loop a bit.
Update man page to this effect.
-rw-r--r-- | usr.bin/chpass/chpass.1 | 23 | ||||
-rw-r--r-- | usr.bin/chpass/chpass.c | 49 | ||||
-rw-r--r-- | usr.bin/passwd/local_passwd.c | 76 | ||||
-rw-r--r-- | usr.bin/passwd/passwd.1 | 24 |
4 files changed, 79 insertions, 93 deletions
diff --git a/usr.bin/chpass/chpass.1 b/usr.bin/chpass/chpass.1 index d2d2d5100c8..9b3471804b1 100644 --- a/usr.bin/chpass/chpass.1 +++ b/usr.bin/chpass/chpass.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: chpass.1,v 1.25 2001/08/20 05:57:55 mpech Exp $ +.\" $OpenBSD: chpass.1,v 1.26 2001/08/27 02:57:07 millert Exp $ .\" $NetBSD: chpass.1,v 1.7 1996/05/15 21:50:40 jtc Exp $ .\" .\" Copyright (c) 1988, 1990, 1993 @@ -217,10 +217,21 @@ uses to update the user database. .Sh DIAGNOSTICS .Bl -diag -.It "The passwd file is busy..." -The password file is currently locked by another process, or a -process previously holding the lock was prematurely terminated. -To determine whether another process is holding the lock, the +.It "Attempting lock password file, please wait or press ^C to abort" +.Pp +The password file is currently locked by another process; +.Nm +will keep trying to lock the password file until it succeeds or +the user hits the interupt character (control-C by default). +If +.Nm +is interrupted while trying to gain the lock any changes made will be lost. +.Pp +If the process holding the lock was prematurely terminated the lock +file may be stale and +.Nm +will wait forever trying to lock the password file. +To determine whether a live process is actually holding the lock, the admin may run the following: .Bd -literal -offset indent fstat /etc/ptmp @@ -228,7 +239,7 @@ fstat /etc/ptmp .Pp If no process is listed, it is safe to remove the .Pa /etc/ptmp -file to get rid of this error. +file to clear the error. .El .Sh ENVIRONMENT The diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c index bdb3a1b3cb7..d41925acb61 100644 --- a/usr.bin/chpass/chpass.c +++ b/usr.bin/chpass/chpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chpass.c,v 1.19 2001/08/16 18:29:27 millert Exp $ */ +/* $OpenBSD: chpass.c,v 1.20 2001/08/27 02:57:07 millert Exp $ */ /* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: chpass.c,v 1.19 2001/08/16 18:29:27 millert Exp $"; +static char rcsid[] = "$OpenBSD: chpass.c,v 1.20 2001/08/27 02:57:07 millert Exp $"; #endif #endif /* not lint */ @@ -54,7 +54,6 @@ static char rcsid[] = "$OpenBSD: chpass.c,v 1.19 2001/08/16 18:29:27 millert Exp #include <sys/time.h> #include <sys/uio.h> -#include <ctype.h> #include <err.h> #include <errno.h> #include <fcntl.h> @@ -94,9 +93,8 @@ main(argc, argv) char **argv; { struct passwd *pw, lpw; - int ch, pfd, tfd, dfd; + int i, ch, pfd, tfd, dfd; char *arg; - char *s = NULL; sigset_t fullset; #ifdef YP @@ -203,41 +201,18 @@ main(argc, argv) /* Get the passwd lock file and open the passwd file for reading. */ pw_init(); - for (;;) { - int i, c, d; - - for (i = 0; i < (s ? 64 : 8) && (tfd = pw_lock(0)) == -1; i++) { - if (i == 0) - (void)fputs("Please wait", stderr); - (void)signal(SIGINT, kbintr); - fputc('.', stderr); - usleep(250000); - (void)signal(SIGINT, SIG_IGN); - } - if (i) - fputc('\n', stderr); - if (tfd != -1) - break; - - /* Unable to lock passwd file, let the user decide. */ - if (errno == EEXIST) { - if (s == NULL) - s = "The passwd file is busy,"; - else - s = "The passwd file is still busy,"; - } else - s = "Unable to open passwd temp file,"; - (void)fprintf(stderr, - "%s do you want to wait until it is available? [y/n] ", s); + for (i = 1; (tfd = pw_lock(0)) == -1; i++) { + if (i == 4) + (void)fputs("Attempting lock password file, " + "please wait or press ^C to abort", stderr); (void)signal(SIGINT, kbintr); - c = getchar(); + if (i % 16 == 0) + fputc('.', stderr); + usleep(250000); (void)signal(SIGINT, SIG_IGN); - if (c != '\n') - while ((d = getchar()) != '\n' && d != EOF) - ; - if (tolower(c) != 'y') - pw_error(NULL, 0, 1); } + if (i >= 4) + fputc('\n', stderr); pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0); if (pfd == -1 || fcntl(pfd, F_SETFD, 1) == -1) pw_error(_PATH_MASTERPASSWD, 1, 1); diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c index 231570ae3d8..97dc5098ae8 100644 --- a/usr.bin/passwd/local_passwd.c +++ b/usr.bin/passwd/local_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: local_passwd.c,v 1.20 2001/08/26 03:28:30 millert Exp $ */ +/* $OpenBSD: local_passwd.c,v 1.21 2001/08/27 02:57:07 millert Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,20 +35,21 @@ #ifndef lint /*static const char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";*/ -static const char rcsid[] = "$OpenBSD: local_passwd.c,v 1.20 2001/08/26 03:28:30 millert Exp $"; +static const char rcsid[] = "$OpenBSD: local_passwd.c,v 1.21 2001/08/27 02:57:07 millert Exp $"; #endif /* not lint */ #include <sys/types.h> #include <sys/stat.h> -#include <pwd.h> +#include <sys/uio.h> + #include <err.h> #include <errno.h> +#include <fcntl.h> +#include <pwd.h> #include <stdio.h> +#include <signal.h> #include <string.h> #include <unistd.h> -#include <ctype.h> -#include <fcntl.h> -#include <signal.h> #include <util.h> #include <login_cap.h> @@ -69,9 +70,8 @@ local_passwd(uname, authenticated) login_cap_t *lc; sigset_t fullset; time_t period; - int pfd, tfd = -1; + int i, pfd, tfd = -1; int pwflags = _PASSWORD_OMITV7; - char *s = NULL; if (!(pw = getpwnam(uname))) { #ifdef YP @@ -118,43 +118,18 @@ local_passwd(uname, authenticated) /* Get a lock on the passwd file and open it. */ pw_init(); - for (;;) { - int i, c, d; - - for (i = 0; i < (s ? 64 : 8) && (tfd = pw_lock(0)) == -1; i++) { - if (i == 0) - (void)fputs("Please wait", stderr); - (void)signal(SIGINT, kbintr); - fputc('.', stderr); - usleep(250000); - (void)signal(SIGINT, SIG_IGN); - } - if (i) - fputc('\n', stderr); - if (tfd != -1) - break; - - /* Unable to lock passwd file, let the user decide. */ - if (errno == EEXIST) { - if (s == NULL) - s = "The passwd file is busy,"; - else - s = "The passwd file is still busy,"; - } else - s = "Unable to open passwd temp file,"; - (void)fprintf(stderr, - "%s do you want to wait until it is available? [y/n] ", s); + for (i = 1; (tfd = pw_lock(0)) == -1; i++) { + if (i == 4) + (void)fputs("Attempting lock password file, " + "please wait or press ^C to abort", stderr); (void)signal(SIGINT, kbintr); - c = getchar(); + if (i % 16 == 0) + fputc('.', stderr); + usleep(250000); (void)signal(SIGINT, SIG_IGN); - if (c != '\n') - while ((d = getchar()) != '\n' && d != EOF) - ; - if (tolower(c) != 'y') { - printf("Password unchanged\n"); - exit(1); - } } + if (i >= 4) + fputc('\n', stderr); pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0); if (pfd < 0 || fcntl(pfd, F_SETFD, 1) == -1) pw_error(_PATH_MASTERPASSWD, 1, 1); @@ -219,8 +194,21 @@ void kbintr(signo) int signo; { - char msg[] = "\nPassword unchanged\n"; + char msg[] = "\nPassword unchanged.\n"; + struct iovec iv[5]; + extern char *__progname; + + iv[0].iov_base = "\nPassword unchanged.\n"; + iv[0].iov_len = sizeof(msg) - 1; + iv[1].iov_base = __progname; + iv[1].iov_len = strlen(__progname); + iv[2].iov_base = ": "; + iv[2].iov_len = 2; + iv[3].iov_base = _PATH_MASTERPASSWD; + iv[3].iov_len = sizeof(_PATH_MASTERPASSWD) - 1; + iv[4].iov_base = " unchanged\n"; + iv[4].iov_len = 11; + writev(STDERR_FILENO, iv, 5); - write(STDOUT_FILENO, msg, sizeof(msg) - 1); _exit(1); } diff --git a/usr.bin/passwd/passwd.1 b/usr.bin/passwd/passwd.1 index 44806970c9c..b8558634021 100644 --- a/usr.bin/passwd/passwd.1 +++ b/usr.bin/passwd/passwd.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: passwd.1,v 1.19 2001/08/03 16:03:02 mpech Exp $ +.\" $OpenBSD: passwd.1,v 1.20 2001/08/27 02:57:07 millert Exp $ .\" .\" Copyright (c) 1990 The Regents of the University of California. .\" All rights reserved. @@ -144,10 +144,22 @@ and YP passwords. .Sh DIAGNOSTICS .Bl -diag -.It "The passwd file is busy..." -The password file is currently locked by another process, or a -process previously holding the lock was prematurely terminated. -To determine whether another process is holding the lock, the +.It "Attempting lock password file, please wait or press ^C to abort" +.Pp +The password file is currently locked by another process; +.Nm +will keep trying to lock the password file until it succeeds or +you hit the interupt character (control-C by default). +If +.Nm +is interrupted while trying to gain the lock the password changed will +be lost. +.Pp +If the process holding the lock was prematurely terminated the lock +file may be stale and +.Nm +will wait forever trying to lock the password file. +To determine whether a live process is actually holding the lock, the admin may run the following: .Bd -literal -offset indent fstat /etc/ptmp @@ -155,7 +167,7 @@ fstat /etc/ptmp .Pp If no process is listed, it is safe to remove the .Pa /etc/ptmp -file to get rid of this error. +file to clear the error. .El .Sh FILES .Bl -tag -width /etc/master.passwd -compact |