From owner-p4-projects@FreeBSD.ORG Mon May 10 07:20:27 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E23CB1065677; Mon, 10 May 2010 07:20:26 +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 A64501065674 for ; Mon, 10 May 2010 07:20:26 +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 8A4D58FC21 for ; Mon, 10 May 2010 07:20:26 +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 o4A7KQsL046668 for ; Mon, 10 May 2010 07:20:26 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4A7KQiO046666 for perforce@freebsd.org; Mon, 10 May 2010 07:20:26 GMT (envelope-from gcooper@FreeBSD.org) Date: Mon, 10 May 2010 07:20:26 GMT Message-Id: <201005100720.o4A7KQiO046666@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 178027 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: Mon, 10 May 2010 07:20:27 -0000 http://p4web.freebsd.org/@@178027?ac=10 Change 178027 by gcooper@gcooper-bayonetta on 2010/05/10 07:20:24 Update some comments, group the prefix == NULL functionality together better, convert some callocs to mallocs, and fix @srcdir. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#10 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#10 (text+ko) ==== @@ -406,11 +406,15 @@ if (Regenerate == FALSE) archive_open_flags |= O_CREAT; - if ((destfile = calloc(PATH_MAX, sizeof(char))) == NULL || + /* + * NOTE (gcooper): No sense in calloc'ing destfile or srcfile as the + * first byte is zeroed out below in the archive add loop. + */ + if ((destfile = malloc(PATH_MAX, sizeof(char))) == NULL || (destbase = calloc(PATH_MAX, sizeof(char))) == NULL || (prefix = calloc(PATH_MAX, sizeof(char))) == NULL || (srcbase = calloc(PATH_MAX, sizeof(char))) == NULL || - (srcfile = calloc(PATH_MAX, sizeof(char))) == NULL) + (srcfile = malloc(PATH_MAX, sizeof(char))) == NULL) error = strerror(errno); /* * If the package tarball exists already, and we are running in @@ -513,6 +517,10 @@ destfile[0] = srcfile[0] = '\0'; + /* + * File is based off the current working directory if + * NULL. + */ if (destbase != NULL) if (strlcat(destfile, destbase, PATH_MAX) > PATH_MAX) @@ -539,6 +547,7 @@ case PLIST_CWD: + /* Reset to / */ if (p->name == NULL) { /* * Broken plist; prefix must be defined before @@ -553,22 +562,39 @@ error = strerror(ENAMETOOLONG); /* Reset srcbase */ - if (strlcpy(srcbase, BaseDir, PATH_MAX) > - PATH_MAX) - error = strerror(ENAMETOOLONG); - else if (strlcpy(srcbase, prefix, PATH_MAX) > - PATH_MAX) - error = strerror(ENAMETOOLONG); - - } else { - /* Tack BaseDir on the front if defined. */ if (BaseDir != NULL) { if (strlcpy(srcbase, BaseDir, PATH_MAX) > PATH_MAX) error = strerror(ENAMETOOLONG); - } else - srcbase[0] = '\0'; + if (strlcpy(srcbase, prefix, PATH_MAX) > + PATH_MAX) + error = strerror(ENAMETOOLONG); + + } + /* + * 1. Accumulate the directory argument. or + * 2. Set the prefix as this is the first @cwd. + */ + else { + + /* First @cwd -- wewt! */ + if (prefix == NULL) { + + prefix = p->name; + + /* + * Tack BaseDir on the front if + * defined and this is the first run. + */ + if (BaseDir != NULL) { + if (strlcpy(srcbase, BaseDir, + PATH_MAX) > PATH_MAX) + error = strerror(ENAMETOOLONG); + } else + srcbase[0] = '\0'; + + } if (strlcat(destbase, p->name, PATH_MAX) > PATH_MAX) @@ -578,10 +604,6 @@ PATH_MAX) error = strerror(ENAMETOOLONG); - /* First @cwd statement. */ - if (prefix == NULL) - prefix = p->name; - } /* @@ -623,12 +645,10 @@ assert(p->name != NULL); /* - * Set the appropriate prefix for the next file to - * install (only for @srcdir). - * - * Reset to '' + * Set the appropriate prefix for the next `@cwd' + * call. */ - if (strlcpy(srcbase, p->name, PATH_MAX) > + if (strlcpy(prefix, p->name, PATH_MAX) > PATH_MAX) error = strerror(ENAMETOOLONG);