Date: Fri, 7 May 2010 11:25:06 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 177895 for review Message-ID: <201005071125.o47BP6uW089248@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005071125.o47BP6uW089248>