From owner-svn-src-all@FreeBSD.ORG Thu Oct 21 15:10:35 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B67A6106566B; Thu, 21 Oct 2010 15:10:35 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 641F08FC17; Thu, 21 Oct 2010 15:10:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9LFAZdD094085; Thu, 21 Oct 2010 15:10:35 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9LFAZ5Y094083; Thu, 21 Oct 2010 15:10:35 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201010211510.o9LFAZ5Y094083@svn.freebsd.org> From: Ed Schouten Date: Thu, 21 Oct 2010 15:10:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214134 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Oct 2010 15:10:35 -0000 Author: ed Date: Thu Oct 21 15:10:35 2010 New Revision: 214134 URL: http://svn.freebsd.org/changeset/base/214134 Log: Fix error handling logic of pututxline(3). Instead of only returning NULL when the entry is invalid and can't be matched against the current database, also return it when it cannot open the log files properly. Modified: head/lib/libc/gen/pututxline.c Modified: head/lib/libc/gen/pututxline.c ============================================================================== --- head/lib/libc/gen/pututxline.c Thu Oct 21 12:58:26 2010 (r214133) +++ head/lib/libc/gen/pututxline.c Thu Oct 21 15:10:35 2010 (r214134) @@ -65,7 +65,7 @@ futx_open(const char *file) return (fp); } -static void +static int utx_active_add(const struct futx *fu) { FILE *fp; @@ -78,7 +78,7 @@ utx_active_add(const struct futx *fu) */ fp = futx_open(_PATH_UTX_ACTIVE); if (fp == NULL) - return; + return (1); while (fread(&fe, sizeof fe, 1, fp) == 1) { switch (fe.fu_type) { case USER_PROCESS: @@ -110,6 +110,7 @@ utx_active_add(const struct futx *fu) exact: fwrite(fu, sizeof *fu, 1, fp); fclose(fp); + return (0); } static int @@ -123,7 +124,7 @@ utx_active_remove(struct futx *fu) */ fp = futx_open(_PATH_UTX_ACTIVE); if (fp == NULL) - return (0); + return (1); while (fread(&fe, sizeof fe, 1, fp) == 1) { switch (fe.fu_type) { case USER_PROCESS: @@ -151,7 +152,7 @@ utx_active_purge(void) truncate(_PATH_UTX_ACTIVE, 0); } -static void +static int utx_lastlogin_add(const struct futx *fu) { FILE *fp; @@ -164,7 +165,7 @@ utx_lastlogin_add(const struct futx *fu) */ fp = futx_open(_PATH_UTX_LASTLOGIN); if (fp == NULL) - return; + return (1); while (fread(&fe, sizeof fe, 1, fp) == 1) { if (strncmp(fu->fu_user, fe.fu_user, sizeof fe.fu_user) != 0) continue; @@ -175,6 +176,7 @@ utx_lastlogin_add(const struct futx *fu) } fwrite(fu, sizeof *fu, 1, fp); fclose(fp); + return (0); } static void @@ -197,7 +199,7 @@ utx_lastlogin_upgrade(void) _close(fd); } -static void +static int utx_log_add(const struct futx *fu) { int fd; @@ -219,15 +221,17 @@ utx_log_add(const struct futx *fu) fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND, 0644); if (fd < 0) - return; + return (1); _writev(fd, vec, 2); _close(fd); + return (0); } struct utmpx * pututxline(const struct utmpx *utmpx) { struct futx fu; + int bad = 0; utx_to_futx(utmpx, &fu); @@ -241,16 +245,21 @@ pututxline(const struct utmpx *utmpx) case NEW_TIME: break; case USER_PROCESS: - utx_active_add(&fu); - utx_lastlogin_add(&fu); + bad |= utx_active_add(&fu); + bad |= utx_lastlogin_add(&fu); break; #if 0 /* XXX: Are these records of any use to us? */ case INIT_PROCESS: case LOGIN_PROCESS: - utx_active_add(&fu); + bad |= utx_active_add(&fu); break; #endif case DEAD_PROCESS: + /* + * In case writing a logout entry fails, never attempt + * to write it to utx.log. The logout entry's ut_id + * might be invalid. + */ if (utx_active_remove(&fu) != 0) return (NULL); break; @@ -258,6 +267,6 @@ pututxline(const struct utmpx *utmpx) return (NULL); } - utx_log_add(&fu); - return (futx_to_utx(&fu)); + bad |= utx_log_add(&fu); + return (bad ? NULL : futx_to_utx(&fu)); }