From owner-freebsd-questions@FreeBSD.ORG Wed May 1 09:01:46 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5AE1D1F0 for ; Wed, 1 May 2013 09:01:46 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 2267C12C7 for ; Wed, 1 May 2013 09:01:45 +0000 (UTC) Received: from r56.edvax.de (port-92-195-26-233.dynamic.qsc.de [92.195.26.233]) by mx02.qsc.de (Postfix) with ESMTP id 208D827A48; Wed, 1 May 2013 11:01:38 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r4191lRY005074; Wed, 1 May 2013 11:01:47 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Wed, 1 May 2013 11:01:47 +0200 From: Polytropon To: tak.official@gmail.com Subject: Re: pwd.db/spwd.db file corupption when having unsafe system poweroff Message-Id: <20130501110147.c69f408b.freebsd@edvax.de> In-Reply-To: References: <20130417173544.25266cd6.freebsd@edvax.de> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 May 2013 09:01:46 -0000 On Wed, 1 May 2013 12:58:49 +0430, takCoder wrote: > Excuse me again.. > > i was trying to test the situation explained here, so i just defined a user > with pw command, waited for 2minutes and then power off the system.. Again > i couldn't login anymore.. > > if we assume that, pw is still working with db files after 2 minutes, the > question is that, is it usual for a command to keep db files busy, this > long?? > or is it pw problem? > or is t something else that i'm missing?? For login processes, the plain text files and the database files are involved. The pw command will modify all of them if you add a new user. The "2 minutes problem" should not be related to pw (or pwd_mkdb), but maybe due to syncing. File system access (here: write) is done asynchronously, so the system will decide when it will sync the memory buffers with the (non-volatile) disk content. This task involves both the sync() call and how the actual disk driver acts to it. Note: Just because someone calls sync() does _not_ imply that the synchronisation takes place in that exact moment. But it should not require several minutes to complete the write and bring the files into the required state (on disk). Furthermore, file system corruption due to an abrupt cut of power should be avoided. Whenever the system comes up in a non-clean state, fsck should be run first, _then_ the boot process should continue. Still it's possible that this process leaves truncated files behind (e. g. the binary database files with a length of zero, which implies they will have to be rebuilt by pwd_mkdb). Alternatively to pw, you could try adduser, which is more an interactive program, but can perform the same tasks. Again, it would take care of updating all required files. This is the situation one would expect after the program ended, or at least some seconds after one got back to the root prompt. During the 2 minutes, you could use programs like lsof (it's in ports) to check if a program has a file open, so you could capture the "power off while writing to file" incident. After you could not login again, did you check the files involved in the login process? Those should include: /etc/passwd /etc/master.passwd /etc/group /etc/pwd.db /etc/spwd.db Probably also /etc/login.conf and /etc/login.conf.db, but I think those are not critical to the success of a login attempt per se. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...