From owner-svn-src-all@FreeBSD.ORG Thu Feb 12 19:32:53 2009 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 24908106566C; Thu, 12 Feb 2009 19:32:53 +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 1327D8FC16; Thu, 12 Feb 2009 19:32:53 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1CJWqvc065370; Thu, 12 Feb 2009 19:32:52 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1CJWqAA065369; Thu, 12 Feb 2009 19:32:52 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200902121932.n1CJWqAA065369@svn.freebsd.org> From: Ed Schouten Date: Thu, 12 Feb 2009 19:32:52 +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: r188536 - 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, 12 Feb 2009 19:32:53 -0000 Author: ed Date: Thu Feb 12 19:32:52 2009 New Revision: 188536 URL: http://svn.freebsd.org/changeset/base/188536 Log: Properly invalidate highest pts number when calling setttyent(). When calling setttyent() after calling endttyent(), pts_valid will never be set to 1, because the readdir()-loop will likely never vind a pts that has a higher number than before. Simplify the code by removing pts_valid. We'll just set maxpts to -1 when we don't have a valid count yet. Modified: head/lib/libc/gen/getttyent.c Modified: head/lib/libc/gen/getttyent.c ============================================================================== --- head/lib/libc/gen/getttyent.c Thu Feb 12 19:21:48 2009 (r188535) +++ head/lib/libc/gen/getttyent.c Thu Feb 12 19:32:52 2009 (r188536) @@ -43,9 +43,8 @@ __FBSDID("$FreeBSD$"); static char zapchar; static FILE *tf; -static int maxpts = 0; +static int maxpts = -1; static int curpts = 0; -static int pts_valid = 0; static size_t lbsize; static char *line; @@ -84,7 +83,7 @@ getttyent() return (NULL); for (;;) { if (!fgets(p = line, lbsize, tf)) { - if (pts_valid == 1 && curpts <= maxpts) { + if (curpts <= maxpts) { sprintf(devpts_name, "pts/%d", curpts++); tty.ty_name = devpts_name; tty.ty_getty = tty.ty_type = NULL; @@ -234,12 +233,12 @@ setttyent() if (devpts_dir) { struct dirent *dp; + maxpts = -1; while ((dp = readdir(devpts_dir))) { if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { if (atoi(dp->d_name) > maxpts) { maxpts = atoi(dp->d_name); - pts_valid = 1; curpts = 0; } } @@ -259,7 +258,7 @@ endttyent() { int rval; - pts_valid = 0; + maxpts = -1; /* * NB: Don't free `line' because getttynam() * may still be referencing it