From owner-p4-projects@FreeBSD.ORG Sun May 30 23:53:41 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BA0861065757; Sun, 30 May 2010 23:53:41 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7DF271065768 for ; Sun, 30 May 2010 23:53:41 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 61E9F8FC14 for ; Sun, 30 May 2010 23:53:41 +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 o4UNrfFv031101 for ; Sun, 30 May 2010 23:53:41 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4UNrfMu031099 for perforce@freebsd.org; Sun, 30 May 2010 23:53:41 GMT (envelope-from gcooper@FreeBSD.org) Date: Sun, 30 May 2010 23:53:41 GMT Message-Id: <201005302353.o4UNrfMu031099@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 178985 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: Sun, 30 May 2010 23:53:42 -0000 http://p4web.freebsd.org/@@178985?ac=10 Change 178985 by gcooper@gcooper-bayonetta on 2010/05/30 23:53:38 Purely style(9) fixes. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#18 edit .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/global.c#3 edit .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/match.c#3 edit .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pen.c#6 edit .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/url.c#3 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/file.c#18 (text+ko) ==== @@ -381,7 +381,7 @@ errno = serrno; } - return buf; + return (buf); } @@ -563,7 +563,7 @@ if (0 <= archive_fd) close(archive_fd); - return fd; + return (fd); } ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/global.c#3 (text+ko) ==== @@ -28,4 +28,4 @@ Boolean Quiet = FALSE; Boolean Fake = FALSE; Boolean Force = FALSE; -int Verbose = 0; /* Allow multiple levels of verbose. */ +int Verbose = 0; /* Allow multiple levels of verbose. */ ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/match.c#3 (text+ko) ==== @@ -57,136 +57,154 @@ char ** matchinstalled(match_t MatchType, char **patterns, int *retval) { - int i, errcode, len; - char *matched; - const char *paths[2] = {LOG_DIR, NULL}; - static struct store *store = NULL; - FTS *ftsp; - FTSENT *f; - Boolean *lmatched = NULL; + static struct store *store = NULL; + FTS *ftsp; + FTSENT *f; + char *matched; + const char *paths[2] = {LOG_DIR, NULL}; + int i; + int errcode; + int len; + Boolean *lmatched = NULL; + + store = storecreate(store); + if (store == NULL) { + if (retval != NULL) + *retval = 1; + return (NULL); + } - store = storecreate(store); - if (store == NULL) { if (retval != NULL) - *retval = 1; - return NULL; - } + *retval = 0; + + if (!isdir(paths[0])) { + if (retval != NULL) + *retval = 1; + return (NULL); + } + + /* Count number of patterns */ + if (patterns != NULL) { - if (retval != NULL) - *retval = 0; + for (len = 0; patterns[len]; len++) ; - if (!isdir(paths[0])) { - if (retval != NULL) - *retval = 1; - return NULL; - /* Not reached */ - } + lmatched = alloca(sizeof(*lmatched) * len); + if (lmatched == NULL) { + warn("%s(): alloca() failed", __func__); + if (retval != NULL) + *retval = 1; + return (NULL); + } - /* Count number of patterns */ - if (patterns != NULL) { - for (len = 0; patterns[len]; len++) {} - lmatched = alloca(sizeof(*lmatched) * len); - if (lmatched == NULL) { - warnx("%s(): alloca() failed", __func__); - if (retval != NULL) - *retval = 1; - return NULL; - } - } else - len = 0; + } else + len = 0; - for (i = 0; i < len; i++) - lmatched[i] = FALSE; + for (i = 0; i < len; i++) + lmatched[i] = FALSE; + + ftsp = fts_open((char * const *)(uintptr_t)paths, + FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, fname_cmp); + + if (ftsp != NULL) { + + while ((f = fts_read(ftsp)) != NULL) { + + if (f->fts_info == FTS_D && f->fts_level == 1) { + + fts_set(ftsp, f, FTS_SKIP); + matched = NULL; + errcode = 0; + + if (MatchType == MATCH_ALL) + matched = f->fts_name; + else + for (i = 0; patterns[i]; i++) { + errcode = pattern_match( + MatchType, patterns[i], + f->fts_name); + if (errcode == 1) { + matched = f->fts_name; + lmatched[i] = TRUE; + errcode = 0; + } + if (matched != NULL || + errcode != 0) + break; + } + + if (errcode == 0 && matched != NULL) + errcode = storeappend(store, matched); + if (errcode != 0) { + if (retval != NULL) + *retval = 1; + return (NULL); + } - ftsp = fts_open((char * const *)(uintptr_t)paths, FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, fname_cmp); - if (ftsp != NULL) { - while ((f = fts_read(ftsp)) != NULL) { - if (f->fts_info == FTS_D && f->fts_level == 1) { - fts_set(ftsp, f, FTS_SKIP); - matched = NULL; - errcode = 0; - if (MatchType == MATCH_ALL) - matched = f->fts_name; - else - for (i = 0; patterns[i]; i++) { - errcode = pattern_match(MatchType, patterns[i], f->fts_name); - if (errcode == 1) { - matched = f->fts_name; - lmatched[i] = TRUE; - errcode = 0; } - if (matched != NULL || errcode != 0) - break; - } - if (errcode == 0 && matched != NULL) - errcode = storeappend(store, matched); - if (errcode != 0) { - if (retval != NULL) - *retval = 1; - return NULL; - /* Not reached */ + } - } + + fts_close(ftsp); + } - fts_close(ftsp); - } - if (MatchType == MATCH_GLOB) { - for (i = 0; i < len; i++) - if (lmatched[i] == FALSE) - storeappend(store, patterns[i]); - } + /* XXX (gcooper): check for return code from storeappend here? */ + if (MatchType == MATCH_GLOB) + for (i = 0; i < len; i++) + if (lmatched[i] == FALSE) + storeappend(store, patterns[i]); - if (store->used == 0) - return NULL; - else - return store->store; + if (store->used == 0) + return (NULL); + else + return (store->store); } int pattern_match(match_t MatchType, char *pattern, const char *pkgname) { - int errcode = 0; - const char *fname = pkgname; - char basefname[PATH_MAX]; - char condchar = '\0'; - char *condition; + char basefname[PATH_MAX]; + char condchar = '\0'; + char *condition; + const char *ch; + const char *fname = pkgname; + int errcode = 0; - /* do we have an appended condition? */ - condition = strpbrk(pattern, "<>="); - if (condition) { - const char *ch; - /* yes, isolate the pattern from the condition ... */ - if (condition > pattern && condition[-1] == '!') - condition--; - condchar = *condition; - *condition = '\0'; - /* ... and compare the name without version */ - ch = strrchr(fname, '-'); - if (ch && ch - fname < PATH_MAX) { - strlcpy(basefname, fname, ch - fname + 1); - fname = basefname; + /* do we have an appended condition? */ + condition = strpbrk(pattern, "<>="); + if (condition) { + /* yes, isolate the pattern from the condition ... */ + if (condition > pattern && condition[-1] == '!') + condition--; + condchar = *condition; + *condition = '\0'; + /* ... and compare the name without version */ + ch = strrchr(fname, '-'); + if (ch != NULL && ch - fname < PATH_MAX) { + strlcpy(basefname, fname, ch - fname + 1); + fname = basefname; + } } - } - switch (MatchType) { - case MATCH_EREGEX: - case MATCH_REGEX: - errcode = rex_match(pattern, fname, MatchType == MATCH_EREGEX ? 1 : 0); - break; - case MATCH_NGLOB: - case MATCH_GLOB: - errcode = (csh_match(pattern, fname, 0) == 0) ? 1 : 0; - break; - case MATCH_EXACT: - errcode = (strcmp(pattern, fname) == 0) ? 1 : 0; - break; - case MATCH_ALL: - errcode = 1; - break; - default: - break; - } + switch (MatchType) { + case MATCH_EREGEX: + case MATCH_REGEX: + errcode = rex_match(pattern, fname, + MatchType == MATCH_EREGEX ? 1 : 0); + break; + case MATCH_NGLOB: + case MATCH_GLOB: + errcode = (csh_match(pattern, fname, 0) == 0) ? 1 : 0; + break; + case MATCH_EXACT: + errcode = (strcmp(pattern, fname) == 0) ? 1 : 0; + break; + case MATCH_ALL: + errcode = 1; + break; + default: + break; + } /* loop over all appended conditions */ while (condition) { @@ -366,53 +384,53 @@ int isinstalledpkg(const char *name) { - int result; - char *buf, *buf2; - struct iip_memo *memo; + struct iip_memo *memo; + int result; + char *buf, *buf2; + + LIST_FOREACH(memo, &iip_memo, iip_link) { + if (strcmp(memo->iip_name, name) == 0) + return (memo->iip_result); + } - LIST_FOREACH(memo, &iip_memo, iip_link) { - if (strcmp(memo->iip_name, name) == 0) - return memo->iip_result; - } - - buf2 = NULL; - asprintf(&buf, "%s/%s", LOG_DIR, name); - if (buf == NULL) - goto errout; - if (!isdir(buf) || access(buf, R_OK) == -1) { - result = 0; - } else { - asprintf(&buf2, "%s/%s", buf, CONTENTS_FNAME); - if (buf2 == NULL) - goto errout; + buf2 = NULL; + asprintf(&buf, "%s/%s", LOG_DIR, name); + if (buf == NULL) + goto errout; + if (!isdir(buf) || access(buf, R_OK) == -1) + result = 0; + else { + asprintf(&buf2, "%s/%s", buf, CONTENTS_FNAME); + if (buf2 == NULL) + goto errout; - if (!isfile(buf2) || access(buf2, R_OK) == -1) - result = -1; - else - result = 1; - } + if (!isfile(buf2) || access(buf2, R_OK) == -1) + result = -1; + else + result = 1; + } - free(buf); - buf = strdup(name); - if (buf == NULL) - goto errout; - free(buf2); - buf2 = NULL; + free(buf); + buf = strdup(name); + if (buf == NULL) + goto errout; + free(buf2); + buf2 = NULL; - memo = malloc(sizeof *memo); - if (memo == NULL) - goto errout; - memo->iip_name = buf; - memo->iip_result = result; - LIST_INSERT_HEAD(&iip_memo, memo, iip_link); - return result; + memo = malloc(sizeof *memo); + if (memo == NULL) + goto errout; + memo->iip_name = buf; + memo->iip_result = result; + LIST_INSERT_HEAD(&iip_memo, memo, iip_link); + return (result); errout: - if (buf != NULL) - free(buf); - if (buf2 != NULL) - free(buf2); - return -1; + if (buf != NULL) + free(buf); + if (buf2 != NULL) + free(buf2); + return (-1); } /* @@ -423,28 +441,30 @@ static int rex_match(const char *pattern, const char *pkgname, int extended) { - char errbuf[128]; - int errcode; - int retval; - regex_t rex; + char errbuf[128]; + int errcode; + int retval; + regex_t rex; + + retval = 0; - retval = 0; + errcode = regcomp(&rex, pattern, + (extended ? REG_EXTENDED : REG_BASIC) | REG_NOSUB); + if (errcode == 0) + errcode = regexec(&rex, pkgname, 0, NULL, 0); - errcode = regcomp(&rex, pattern, (extended ? REG_EXTENDED : REG_BASIC) | REG_NOSUB); - if (errcode == 0) - errcode = regexec(&rex, pkgname, 0, NULL, 0); + if (errcode == 0) + retval = 1; + else if (errcode != REG_NOMATCH) { + regerror(errcode, &rex, errbuf, sizeof(errbuf)); + warnx("%s: %s", pattern, errbuf); + retval = -1; + } - if (errcode == 0) { - retval = 1; - } else if (errcode != REG_NOMATCH) { - regerror(errcode, &rex, errbuf, sizeof(errbuf)); - warnx("%s: %s", pattern, errbuf); - retval = -1; - } + regfree(&rex); - regfree(&rex); + return (retval); - return retval; } /* @@ -455,89 +475,106 @@ static int csh_match(const char *pattern, const char *string, int flags) { - int ret = FNM_NOMATCH; + + Boolean quoted; + + const char *current = NULL; + const char *eb; + const char *nextchoice = pattern; + const char *pos; + const char *postfix; + char buf[FILENAME_MAX]; + + int prefixlen = -1; + int currentlen = 0; + int level = 0; + int ret = FNM_NOMATCH; + + do { + + pos = nextchoice; + postfix = NULL; + + quoted = FALSE; + + nextchoice = NULL; + + do { + + if (*pos == '\0') + postfix = pos; + else if (quoted == TRUE) + quoted = FALSE; + else { + + switch (*pos) { + case '{': + ++level; + if (level == 1) { + current = pos + 1; + prefixlen = pos - pattern; + } + break; + case ',': + if (level == 1 && !nextchoice) { + nextchoice = pos + 1; + currentlen = pos - current; + } + break; + case '}': + if (level == 1) { + postfix = pos+1; + if (!nextchoice) { + currentlen = + pos - current; + } + } + level--; + break; + case '[': + eb = pos + 1; + if (*eb == '!' || *eb == '^') + eb++; + if (*eb == ']') + eb++; + while (*eb && *eb != ']') + eb++; + if (*eb) + pos = eb; + break; + case '\\': + quoted = TRUE; + break; + default: + break; + } + + } + pos++; - const char *nextchoice = pattern; - const char *current = NULL; + } while (postfix == NULL); - int prefixlen = -1; - int currentlen = 0; + if (current) { - int level = 0; + snprintf(buf, sizeof(buf), "%.*s%.*s%s", + prefixlen, pattern, currentlen, current, postfix); - do { - const char *pos = nextchoice; - const char *postfix = NULL; + ret = csh_match(buf, string, flags); - Boolean quoted = FALSE; + if (ret) { + current = nextchoice; + level = 1; + } else + current = NULL; - nextchoice = NULL; + } else + ret = fnmatch(pattern, string, flags); - do { - const char *eb; - if (!*pos) { - postfix = pos; - } else if (quoted) { - quoted = FALSE; - } else { - switch (*pos) { - case '{': - ++level; - if (level == 1) { - current = pos+1; - prefixlen = pos-pattern; - } - break; - case ',': - if (level == 1 && !nextchoice) { - nextchoice = pos+1; - currentlen = pos-current; - } - break; - case '}': - if (level == 1) { - postfix = pos+1; - if (!nextchoice) - currentlen = pos-current; - } - level--; - break; - case '[': - eb = pos+1; - if (*eb == '!' || *eb == '^') - eb++; - if (*eb == ']') - eb++; - while(*eb && *eb != ']') - eb++; - if (*eb) - pos=eb; - break; - case '\\': - quoted = TRUE; - break; - default: - ; - } - } - pos++; - } while (!postfix); + } while (current); - if (current) { - char buf[FILENAME_MAX]; - snprintf(buf, sizeof(buf), "%.*s%.*s%s", prefixlen, pattern, currentlen, current, postfix); - ret = csh_match(buf, string, flags); - if (ret) { - current = nextchoice; - level = 1; - } else - current = NULL; - } else - ret = fnmatch(pattern, string, flags); - } while (current); + return (ret); - return ret; } /* @@ -547,57 +584,74 @@ struct store * storecreate(struct store *store) { - int i; + int i; - if (store == NULL) { - store = malloc(sizeof *store); if (store == NULL) { - warnx("%s(): malloc() failed", __func__); - return NULL; + store = malloc(sizeof *store); + if (store == NULL) { + warn("%s(): malloc() failed", __func__); + return (NULL); + } + store->currlen = 0; + store->store = NULL; + } else if (store->store != NULL) { + /* Free previously allocated memory */ + for (i = 0; store->store[i] != NULL; i++) + free(store->store[i]); + store->store[0] = NULL; } - store->currlen = 0; - store->store = NULL; - } else if (store->store != NULL) { - /* Free previously allocated memory */ - for (i = 0; store->store[i] != NULL; i++) - free(store->store[i]); - store->store[0] = NULL; - } - store->used = 0; + store->used = 0; - return store; + return (store); } /* * Append specified element to the provided store. + * + * Return 0 on success, return 1 on error. */ static int storeappend(struct store *store, const char *item) { - if (store->used + 2 > store->currlen) { - store->currlen += 16; - store->store = reallocf(store->store, - store->currlen * sizeof(*(store->store))); - if (store->store == NULL) { - store->currlen = 0; - warnx("%s(): reallocf() failed", __func__); - return 1; + int retcode = 0; + + if (store->used + 2 > store->currlen) { + + store->currlen += 16; + store->store = reallocf(store->store, + store->currlen * sizeof(*(store->store))); + + if (store->store == NULL) { + store->currlen = 0; + warn("%s(): reallocf() failed", __func__); + retcode = -1; + } + + } + + if (retcode == 0) { + + asprintf(&(store->store[store->used]), "%s", item); + /* + * XXX (gcooper): should the entire store be invalidated here, + * i.e. free store->store? + */ + if (store->store[store->used] == NULL) { + warn("%s(): malloc() failed", __func__); + retcode = -1; + } else { + store->used++; + store->store[store->used] = NULL; + } + } - } - asprintf(&(store->store[store->used]), "%s", item); - if (store->store[store->used] == NULL) { - warnx("%s(): malloc() failed", __func__); - return 1; - } - store->used++; - store->store[store->used] = NULL; + return (retcode); - return 0; } static int fname_cmp(const FTSENT * const *a, const FTSENT * const *b) { - return strcmp((*a)->fts_name, (*b)->fts_name); + return (strcmp((*a)->fts_name, (*b)->fts_name)); } ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/pen.c#6 (text+ko) ==== @@ -37,7 +37,7 @@ char * where_playpen(void) { - return PenLocation; + return (PenLocation); } /* Find a good place to play. */ @@ -49,7 +49,7 @@ if (pen[0] != '\0' && isdir(dirname(pen)) == TRUE && (min_free(dirname(pen)) >= sz)) - return pen; + return (pen); else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) == 0 && (min_free(cp) >= sz)) sprintf(pen, "%s/instmp.XXXXXX", cp); @@ -65,9 +65,9 @@ strcpy(pen, "/usr/tmp/instmp.XXXXXX"); else { errno = ENOSPC; - return NULL; + return (NULL); } - return pen; + return (pen); } #define MAX_STACK 20 @@ -81,7 +81,7 @@ errx(2, "%s: stack overflow.\n", __func__); pstack[pdepth] = strdup(pen); - return pstack[pdepth]; + return (pstack[pdepth]); } static void @@ -118,7 +118,7 @@ } - return pen_location; + return (pen_location); } @@ -155,7 +155,7 @@ } - return rc; + return (rc); } @@ -166,7 +166,7 @@ if (statfs(tmpdir, &buf) != 0) { warn("statfs"); - return -1; + return (-1); } - return (off_t)buf.f_bavail * (off_t)buf.f_bsize; + return ((off_t)buf.f_bavail * (off_t)buf.f_bsize); } ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/lib/libpkg/url.c#3 (text+ko) ==== @@ -21,12 +21,13 @@ #include __FBSDID("$FreeBSD: src/lib/libpkg/url.c,v 1.1 2010/04/23 11:07:43 flz Exp $"); -#include "pkg.h" +#include +#include #include -#include #include -#include #include +#include /* NOTE: stdio must come before fetch. */ +#include "pkg.h" /* * Try and fetch a file by URL, returning the directory name for where @@ -75,7 +76,7 @@ strcat(cp, ".tbz"); } else - return NULL; + return (NULL); } else if (hint != NULL) { /* @@ -88,7 +89,7 @@ } else - return NULL; + return (NULL); } else @@ -104,7 +105,7 @@ if ((pkgfd = open(pkg, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { warn("Error: Unable to open %s", pkg); - return NULL; + return (NULL); } } @@ -118,7 +119,7 @@ warnx("failed to remove partially fetched package: %s", pkg); } - return NULL; + return (NULL); } if (isatty(0) || Verbose) { @@ -178,6 +179,6 @@ if (0 < pkgfd) close(pkgfd); - return rp; + return (rp); }