Date: Tue, 5 Jan 1999 10:43:57 +0100 From: Jos Backus <Jos.Backus@nl.origin-it.com> To: Hidetoshi Shimokawa <simokawa@sat.t.u-tokyo.ac.jp> Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: bin/9247: pw/pwd_mkdb deadlock on /etc/master.passwd Message-ID: <19990105104357.A99381@hal.mpn.cp.philips.com> In-Reply-To: <199901040640.WAA12583@freefall.freebsd.org>; from Hidetoshi Shimokawa on Sun, Jan 03, 1999 at 10:40:01PM -0800 References: <199901040640.WAA12583@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 03, 1999 at 10:40:01PM -0800, Hidetoshi Shimokawa wrote: > We need to unlock(close) before calling "pwd_mkdb" or to have non-lock option > in pwd_mkdb.c. Of course you're right. Here's a better patch. I'm still not really proud of it because it uses a global, but it does work. --- pw.c.orig Tue Jan 5 10:33:27 1999 +++ pw.c Tue Jan 5 10:37:44 1999 @@ -48,9 +48,11 @@ static struct cargs arglist; +int passwd_fd; + static int getindex(const char *words[], const char *word); static void cmdhelp(int mode, int which); -static void filelock(const char *filename); +static int filelock(const char *filename); int @@ -154,8 +156,8 @@ * Try to lock the master passowrd and group files right away (we * don't care if it works, since this is just advisory locking. */ - filelock(_PATH_GROUP); - filelock(_PATH_MASTERPASSWD); + (void)filelock(_PATH_GROUP); + passwd_fd = filelock(_PATH_MASTERPASSWD); ch = funcs[which] (cnf, mode, &arglist); /* @@ -186,10 +188,10 @@ return ch; } -static void +static int filelock(const char *filename) { - open(filename, O_RDONLY | O_EXLOCK, 0); + return open(filename, O_RDONLY | O_EXLOCK, 0); } static int --- pw.h.orig Tue Jan 5 10:33:31 1999 +++ pw.h Tue Jan 5 10:34:21 1999 @@ -125,3 +125,5 @@ extern const char *Modes[]; extern const char *Which[]; + +extern int passwd_fd; --- pwupd.c.orig Tue Jan 5 10:33:43 1999 +++ pwupd.c Tue Jan 5 10:37:25 1999 @@ -109,6 +109,8 @@ int rc = 0; endpwent(); + if (passwd_fd != -1) + close(passwd_fd); /* * First, let's check the see if the database is alright --- pwupd.h.orig Tue Jan 5 10:35:14 1999 +++ pwupd.h Tue Jan 5 10:35:58 1999 @@ -78,4 +78,6 @@ int extendarray __P((char ***buf, int *buflen, int needed)); __END_DECLS +extern int passwd_fd; + #endif /* !_PWUPD_H */ Cheers, -- Jos Backus _/ _/_/_/ "Reliability means never _/ _/ _/ having to say you're sorry." _/ _/_/_/ -- D. J. Bernstein _/ _/ _/ _/ Jos.Backus@nl.origin-it.com _/_/ _/_/_/ use Std::Disclaimer; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990105104357.A99381>