From owner-p4-projects@FreeBSD.ORG Fri May 7 11:25:07 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 50052106567B; Fri, 7 May 2010 11:25:07 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id ED5A31065677 for ; Fri, 7 May 2010 11:25:06 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id DB2E68FC15 for ; Fri, 7 May 2010 11:25:06 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o47BP6AQ089250 for ; Fri, 7 May 2010 11:25:06 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o47BP6uW089248 for perforce@freebsd.org; Fri, 7 May 2010 11:25:06 GMT (envelope-from gcooper@FreeBSD.org) Date: Fri, 7 May 2010 11:25:06 GMT Message-Id: <201005071125.o47BP6uW089248@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 177895 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2010 11:25:07 -0000 http://p4web.freebsd.org/@@177895?ac=10 Change 177895 by gcooper@gcooper-bayonetta on 2010/05/07 11:24:07 u Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/main.c#5 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/main.c#5 (text+ko) ==== @@ -150,13 +150,21 @@ n = strlcpy(tmp_file + n, "/", sizeof(tmp_file) - n); n = strlcat(tmp_file + n, pkgdbdir->d_name, sizeof(tmp_file) - n); - if (stat(tmp_file, &attribute) == -1) { - fprintf(stderr, "can't open %s: %s\n", - tmp_file, strerror(errno)); - return EXIT_FAILURE; + /* + * XXX (gcooper): convert code to use + * fstat(2), open(2), etc to avoid race + * conditions. + */ + if (stat(tmp_file, &attribute) == -1) + err(EXIT_FAILURE, + "could not stat %s", + tmp_file); + if (S_ISREG(attribute.st_mode)) { + /* XXX (gcooper): drop continue. */ + (void)closedir(dir); + continue; } - if (attribute.st_mode & S_IFREG) - continue; + /* XXX (gcooper): check return codes. */ (void)strlcat(tmp_file + n, "/", sizeof(tmp_file) - n); (void)strlcat(tmp_file + n, CONTENTS_FNAME, @@ -165,8 +173,10 @@ /* Open +CONTENT file */ fd = fopen(tmp_file, "r"); if (fd == NULL) { - fprintf(stderr, "warning: can't open %s: %s\n", - tmp_file, strerror(errno)); + /* XXX (gcooper): drop continue. */ + (void)closedir(dir); + warn("can't open %s: %s", + tmp_file); continue; } @@ -186,20 +196,29 @@ (void)exit(EXIT_FAILURE); if (pname[strlen(pname) - 1] == '\n') pname[strlen(pname) - 1] = '\0'; + /* + * XXX (gcooper): check + * return code. + */ strlcpy (curr->name, pname, strlen(pname)+1); curr->next = head; head = curr; } } - if (ferror(fd)) - err(EXIT_FAILURE, - "error reading input"); + if (ferror(fd)) { + serrno = errno; + (void)fclose(fd); + (void)closedir(dir); + errx(EXIT_FAILURE, + "error reading input: %s", + strerror(serrno)); + } (void)fclose(fd); } } - closedir(dir); + (void) closedir(dir); } } @@ -223,17 +242,18 @@ if (tmpline1 != NULL) { curr = head; while (curr != NULL) { - tmpline2 = strstr(updatingline, curr->name); + tmpline2 = strstr(updatingline, + curr->name); if (tmpline2 != NULL) break; curr = curr->next; } if (tmpline2 != NULL) { /* If -d is set, check if entry is newer than the date. */ - if ((dflag == 1) && (strncmp(dateline, date, 8) < 0)) + if ((dflag == 1) && + (strncmp(dateline, date, 8) < 0)) continue; - printf("%s", dateline); - printf("%s", updatingline); + printf("%s%s", dateline, updatingline); found = 1; } }