From owner-p4-projects Wed Nov 13 15:13:32 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A3DFB37B404; Wed, 13 Nov 2002 15:13:27 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2492137B401 for ; Wed, 13 Nov 2002 15:13:27 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C527243E7B for ; Wed, 13 Nov 2002 15:13:26 -0800 (PST) (envelope-from green@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id gADNAvmV078626 for ; Wed, 13 Nov 2002 15:10:57 -0800 (PST) (envelope-from green@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id gADNAvZv078623 for perforce@freebsd.org; Wed, 13 Nov 2002 15:10:57 -0800 (PST) Date: Wed, 13 Nov 2002 15:10:57 -0800 (PST) Message-Id: <200211132310.gADNAvZv078623@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to green@freebsd.org using -f From: Brian Feldman Subject: PERFORCE change 21052 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://perforce.freebsd.org/chv.cgi?CH=21052 Change 21052 by green@green_laptop_2 on 2002/11/13 15:10:13 Optimization: treat labeling operations as a transaction so that setfsmac(8) will no label an entire filesystem more quickly. Affected files ... .. //depot/projects/trustedbsd/mac/sbin/setfsmac/setfsmac.c#4 edit Differences ... ==== //depot/projects/trustedbsd/mac/sbin/setfsmac/setfsmac.c#4 (text+ko) ==== @@ -19,10 +19,11 @@ char *regexstr; /* uncompiled regular expression */ mode_t mode; /* mode to possibly match */ char *modestr; /* print-worthy ",-?" mode string */ - mac_t mac; /* MAC label to apply */ + char *mactext; /* MAC label to apply */ int flags; /* miscellaneous flags */ #define F_DONTLABEL 0x01 - } *entries; + } *entries, /* entries[0..nentries] */ + *match; /* cached decision for MAC label to apply */ size_t nentries; /* size of entries list */ STAILQ_ENTRY(label_spec) link; }; @@ -211,7 +212,7 @@ add_spec_line(const char *file, int is_sebsd, struct label_spec_entry *entry, char *line) { - char *regexstr, *modestr, *macstr, *regerrorstr, *sebsdstr; + char *regexstr, *modestr, *macstr, *regerrorstr; size_t size; int error; @@ -242,17 +243,14 @@ errx(1, "%s: %s: %s", file, entry->regexstr, regerrorstr); } if (!is_sebsd) { - if (mac_from_text(&entry->mac, macstr)) - err(1, "%s: mac_from_text(%s)", file, macstr); + entry->mactext = strdup(macstr); + if (entry->mactext == NULL) + err(1, "strdup"); } else { - if (asprintf(&sebsdstr, "sebsd/%s", macstr) == -1) + if (asprintf(&entry->mactext, "sebsd/%s", macstr) == -1) err(1, "asprintf"); - if (mac_from_text(&entry->mac, sebsdstr)) - err(1, "%s: mac_from_text(%s)", file, sebsdstr); - if (strcmp(macstr, "<>") == 0) + if (strcmp(entry->mactext, "<>") == 0) entry->flags |= F_DONTLABEL; - free(sebsdstr); - } if (modestr != NULL) { if (strlen(modestr) != 2 || modestr[0] != '-') @@ -300,8 +298,9 @@ regmatch_t pmatch; struct label_spec *ls; struct label_spec_entry *ent; - char *regerrorstr, *mactext; + char *regerrorstr, *macstr; size_t size; + mac_t mac; int error, matchedby; /* @@ -311,8 +310,8 @@ */ matchedby = 0; STAILQ_FOREACH(ls, &specs->head, link) { - for (ent = ls->entries; ent < &ls->entries[ls->nentries]; - ent++) { + for (ls->match = NULL, ent = ls->entries; + ent < &ls->entries[ls->nentries]; ent++) { if (ent->mode != 0 && (ftsent->fts_statp->st_mode & S_IFMT) != ent->mode) continue; @@ -324,6 +323,7 @@ case REG_NOMATCH: continue; case 0: + ls->match = ent; break; default: size = regerror(error, &ent->regex, NULL, 0); @@ -341,28 +341,48 @@ ftsent->fts_path); matchedby = 1; } - if (mac_to_text(ent->mac, &mactext) != 0) - err(1, "mac_to_text"); printf("%s(%s%s,%s)", matchedby == 2 ? "," : "", - ent->regexstr, ent->modestr, mactext); + ent->regexstr, ent->modestr, ent->mactext); if (matchedby == 1) matchedby = 2; - free(mactext); - } - if ((ent->flags & F_DONTLABEL) == 0 && - mac_set_link(ftsent->fts_accpath, ent->mac) != 0) { - if (errno == EOPNOTSUPP) - return (1); - if (vflag) - printf("\n"); - err(1, "mac_set_link(%.*s)", - ftsent->fts_pathlen, ftsent->fts_path); } break; } } if (vflag && matchedby) printf("\n"); + size = 0; + STAILQ_FOREACH(ls, &specs->head, link) { + /* cached match decision */ + if (ls->match && (ls->match->flags & F_DONTLABEL) == 0) + /* add length of "x\0"/"y," */ + size += strlen(ls->match->mactext) + 1; + } + macstr = malloc(size); + if (macstr == NULL) + err(1, "malloc"); + *macstr = '\0'; + STAILQ_FOREACH(ls, &specs->head, link) { + /* cached match decision */ + if (ls->match && (ls->match->flags & F_DONTLABEL) == 0) { + if (*macstr != '\0') + strcat(macstr, ","); + strcat(macstr, ls->match->mactext); + } + } + if (mac_from_text(&mac, macstr)) + err(1, "mac_from_text(%s)", macstr); + if (mac_set_link(ftsent->fts_accpath, mac) != 0) { + if (errno == EOPNOTSUPP) { + mac_free(mac); + free(macstr); + return (1); + } + err(1, "mac_set_link(%.*s, %s)", ftsent->fts_pathlen, + ftsent->fts_path, macstr); + } + mac_free(mac); + free(macstr); return (0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message