diff options
author | eota <none@none> | 2006-09-26 14:29:13 -0700 |
---|---|---|
committer | eota <none@none> | 2006-09-26 14:29:13 -0700 |
commit | 1ca932730d3439e527d5fe4a15444600d0df7e7e (patch) | |
tree | 021f725c3677f6b8619e3ef76fb7720c121e0520 /usr/src | |
parent | 23b5c241225a8ade2b6b9f06ebb891ee459e3b02 (diff) | |
download | illumos-joyent-1ca932730d3439e527d5fe4a15444600d0df7e7e.tar.gz |
6311701 /etc/minor_perm is ignored if it contains comments
6459253 i.nametomajor holds the obsolete shell function
6460892 add_drv and update_drv can accept the invalid names
6462571 should clean up duplicate code in update_minor_entry()
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/devfsadm/devfsadm.c | 46 | ||||
-rw-r--r-- | usr/src/cmd/getmajor/getmajor.sh | 18 | ||||
-rw-r--r-- | usr/src/cmd/modload/drvsubr.c | 190 | ||||
-rw-r--r-- | usr/src/cmd/modload/errmsg.h | 8 | ||||
-rw-r--r-- | usr/src/cmd/pcmciad/pcmciad.c | 39 | ||||
-rw-r--r-- | usr/src/lib/libdevinfo/devinfo_devperm.c | 27 | ||||
-rw-r--r-- | usr/src/lib/lvm/libpreen/common/mdpreen.c | 28 | ||||
-rw-r--r-- | usr/src/lib/lvm/libsvm/common/getdrvname.c | 35 | ||||
-rw-r--r-- | usr/src/lib/lvm/libsvm/common/metaconf.c | 32 | ||||
-rw-r--r-- | usr/src/pkgdefs/common_files/i.drvalias | 214 | ||||
-rw-r--r-- | usr/src/pkgdefs/common_files/i.nametomajor | 152 | ||||
-rw-r--r-- | usr/src/tools/scripts/bfu.sh | 3 | ||||
-rw-r--r-- | usr/src/ucbcmd/ucblinks/ucblinks.c | 34 | ||||
-rw-r--r-- | usr/src/ucbcmd/ucblinks/ucblinks.sh | 17 | ||||
-rw-r--r-- | usr/src/uts/common/os/modsysfile.c | 25 |
15 files changed, 586 insertions, 282 deletions
diff --git a/usr/src/cmd/devfsadm/devfsadm.c b/usr/src/cmd/devfsadm/devfsadm.c index 02f90cedde..c1ffa5e1aa 100644 --- a/usr/src/cmd/devfsadm/devfsadm.c +++ b/usr/src/cmd/devfsadm/devfsadm.c @@ -239,6 +239,8 @@ static void check_reconfig_state(void); static void devname_setup_nsmaps(void); static int s_stat(const char *, struct stat *); +static int is_blank(char *); + int main(int argc, char *argv[]) { @@ -389,7 +391,6 @@ update_drvconf(major_t major) major); } - static void load_dev_acl() { @@ -5556,7 +5557,7 @@ static int load_n2m_table(char *file) { FILE *fp; - char line[1024]; + char line[1024], *cp; char driver[PATH_MAX + 1]; major_t major; n2m_t *ptr; @@ -5569,9 +5570,13 @@ load_n2m_table(char *file) while (fgets(line, sizeof (line), fp) != NULL) { ln++; - if (line[0] == '#') { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) continue; - } + /* sanity-check */ if (sscanf(line, "%1024s%lu", driver, &major) != 2) { err_print(IGNORING_LINE_IN, ln, file); continue; @@ -5600,7 +5605,7 @@ read_devlinktab_file(void) devlinktab_list_t *entryp; devlinktab_list_t **previous; devlinktab_list_t *save; - char line[MAX_DEVLINK_LINE]; + char line[MAX_DEVLINK_LINE], *cp; char *selector; char *p_link; char *s_link; @@ -5664,10 +5669,12 @@ read_devlinktab_file(void) continue; } - if ((line[0] == '#') || (line[0] == '\0')) { - /* Ignore comments and blank lines */ + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) continue; - } vprint(DEVLINK_MID, "table: %s line %d: '%s'\n", devlinktab_file, devlinktab_line, line); @@ -7085,8 +7092,14 @@ read_driver_aliases_file(void) devfsadm_exit(1); } - while (fgets(line, sizeof (line) - 1, afd) != NULL) { + while (fgets(line, sizeof (line), afd) != NULL) { ln++; + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; cp = line; if (getnexttoken(cp, &cp, &p, &t) == DEVFSADM_FAILURE) { err_print(IGNORING_LINE_IN, ln, ALIASFILE); @@ -8015,6 +8028,21 @@ build_and_log_event(char *class, char *subclass, char *node_path, } } +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} + static int devname_kcall(int subcmd, void *args) { diff --git a/usr/src/cmd/getmajor/getmajor.sh b/usr/src/cmd/getmajor/getmajor.sh index 0796787aeb..2975f9c40d 100644 --- a/usr/src/cmd/getmajor/getmajor.sh +++ b/usr/src/cmd/getmajor/getmajor.sh @@ -3,9 +3,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -21,10 +20,9 @@ # CDDL HEADER END # +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. # -# Copyright (c) 1991, Sun Microsystems Inc. -# - #ident "%Z%%M% %I% %E% SMI" if [ $# -ne 1 ] @@ -33,6 +31,8 @@ then exit 2 fi -exec awk -e "BEGIN {found = 0} -/^$1[ ]/ {print \$2; found = 1; exit 0} -END {if (found == 0) exit 1}" </etc/name_to_major +exec nawk -v a="$1" -v del='#' '$1 !~ /^#|^$/ && $1 == a { \ + num = split($2, maj, del); \ + if (num > 1) { print maj[1] } else { print $2 } \ + found = 1; exit 0 } \ + END {if (!found) exit 1}' < /etc/name_to_major diff --git a/usr/src/cmd/modload/drvsubr.c b/usr/src/cmd/modload/drvsubr.c index 6976f8ee7a..00c4a03786 100644 --- a/usr/src/cmd/modload/drvsubr.c +++ b/usr/src/cmd/modload/drvsubr.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" @@ -28,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include <unistd.h> #include <sys/sysmacros.h> #include <libintl.h> @@ -50,6 +50,8 @@ static int get_cached_n_to_m_file(char *filename, char ***cache); static int get_name_to_major_entry(int *major_no, char *driver_name, char *file_name); +static int is_blank(char *); + /*ARGSUSED*/ void log_minorperm_error(minorperm_err_t err, int key) @@ -207,7 +209,7 @@ delete_entry( int status = NOERR; int drvr_found = 0; boolean_t nomatch = B_TRUE; - char *newfile, *tptr; + char *newfile, *tptr, *cp, *dup; char line[MAX_DBFILE_ENTRY], drv[FILENAME_MAX + 1]; FILE *fp, *newfp; struct group *sysgrp; @@ -260,20 +262,36 @@ delete_entry( } while ((fgets(line, sizeof (line), fp) != NULL) && status == NOERR) { - if (*line == '#' || *line == '\n') { - if ((fputs(line, newfp)) == EOF) { + /* copy the whole line into dup */ + if ((dup = strdup(line)) == NULL) { + perror(NULL); + (void) fprintf(stderr, gettext(ERR_NO_MEM)); + status = ERROR; + break; + } + /* cut off comments starting with '#' */ + if ((cp = strchr(dup, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(dup)) { + if (fputs(line, newfp) == EOF) { (void) fprintf(stderr, gettext(ERR_UPDATE), oldfile); status = ERROR; } + free(dup); continue; } - if (sscanf(line, "%s", drv) != 1) { + + /* get the driver name */ + if (sscanf(dup, "%s", drv) != 1) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), oldfile, line); status = ERROR; + free(dup); + break; } - + free(dup); for (i = strcspn(drv, marker); i < FILENAME_MAX; i++) { drv[i] = '\0'; @@ -415,7 +433,7 @@ get_cached_n_to_m_file(char *filename, char ***cache) FILE *fp; char drv[FILENAME_MAX + 1]; char entry[FILENAME_MAX + 1]; - char line[MAX_N2M_ALIAS_LINE]; + char line[MAX_N2M_ALIAS_LINE], *cp; int maj; int size = 0; @@ -440,6 +458,13 @@ get_cached_n_to_m_file(char *filename, char ***cache) } while (fgets(line, sizeof (line), fp) != NULL) { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%s%s", drv, entry) != 2) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), filename, line); @@ -474,6 +499,13 @@ get_cached_n_to_m_file(char *filename, char ***cache) * number */ while (fgets(line, sizeof (line), fp) != NULL) { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%s%s", drv, entry) != 2) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), filename, line); @@ -581,7 +613,6 @@ get_name_to_major_entry(int *major_no, char *driver_name, char *file_name) return (ret); } - /* * given pointer to member n in space separated list, return pointer * to member n+1, return member n @@ -1065,9 +1096,8 @@ update_minor_entry(char *driver_name, char *perm_list) FILE *newfp; struct group *sysgrp; int match = 0; - char line[MAX_DBFILE_ENTRY]; - char drv[FILENAME_MAX + 1]; - char *drv_minor, new_minor[FILENAME_MAX + 1]; + char line[MAX_DBFILE_ENTRY], *cp, *dup; + char drv[FILENAME_MAX + 1], *drv_minor; char minor[FILENAME_MAX + 1], perm[OPT_LEN + 1]; char own[OPT_LEN + 1], grp[OPT_LEN + 1]; int status = NOERR, i; @@ -1113,43 +1143,75 @@ update_minor_entry(char *driver_name, char *perm_list) status = ERROR; } - (void) sscanf(perm_list, "%s%s%s%s", minor, perm, own, grp); - while ((fgets(line, sizeof (line), fp) != NULL) && status == NOERR) { - if (*line == '#' || *line == '\n') { - if ((fputs(line, newfp)) == EOF) { + /* copy the whole line into dup */ + if ((dup = strdup(line)) == NULL) { + perror(NULL); + (void) fprintf(stderr, gettext(ERR_NO_MEM)); + status = ERROR; + break; + } + /* cut off comments starting with '#' */ + if ((cp = strchr(dup, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(dup)) { + if (fputs(line, newfp) == EOF) { (void) fprintf(stderr, gettext(ERR_UPDATE), minor_perm); status = ERROR; } + free(dup); continue; } - if (sscanf(line, "%s", drv) != 1) { + /* get the driver name */ + if (sscanf(dup, "%s", drv) != 1) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), minor_perm, line); status = ERROR; - } - for (i = strcspn(drv, ":"); i < FILENAME_MAX; i++) { - drv[i] = '\0'; + free(dup); + break; } - if (sscanf(line, "%s", new_minor) != 1) { + /* + * get the minor name; place the NULL character at the + * end of the driver name, then make the drv_minor + * point to the first character of the minor name. + * the line missing ':' must be treated as a broken one. + */ + i = strcspn(drv, ":"); + if (i == strlen(drv)) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), minor_perm, line); status = ERROR; + free(dup); + break; } + drv[i] = '\0'; + drv_minor = &drv[strlen(drv) + 1]; - drv_minor = &new_minor[strlen(drv) + 1]; - - /* replace it */ + /* + * compare both of the driver name and the minor name. + * then the new line should be written to the file if + * both of them match + */ if ((strcmp(drv, driver_name) == 0) && (strcmp(minor, drv_minor) == 0)) { - (void) sprintf(line, "%s:%s %s %s %s\n", - drv, minor, perm, own, grp); + /* if it has a comment, keep it */ + if (cp != NULL) { + cp++; /* skip a terminator */ + (void) sprintf(line, "%s:%s %s %s %s #%s\n", + drv, minor, perm, own, grp, cp); + } else { + (void) sprintf(line, "%s:%s %s %s %s\n", + drv, minor, perm, own, grp); + } match = 1; } + free(dup); + /* update the file */ if ((fputs(line, newfp)) == EOF) { (void) fprintf(stderr, gettext(ERR_UPDATE), minor_perm); @@ -1229,7 +1291,7 @@ list_entry( { FILE *fp; int i; - char line[MAX_DBFILE_ENTRY]; + char line[MAX_DBFILE_ENTRY], *cp; char drv[FILENAME_MAX + 1]; if ((fp = fopen(oldfile, "r")) == NULL) { @@ -1240,10 +1302,13 @@ list_entry( } while (fgets(line, sizeof (line), fp) != NULL) { - if (*line == '#' || *line == '\n') { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) continue; - } - + /* sanity-check */ if (sscanf(line, "%s", drv) != 1) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), oldfile, line); @@ -1261,6 +1326,25 @@ list_entry( (void) fclose(fp); } +static boolean_t +is_token(char *tok) +{ + /* + * Check the token here. According to IEEE1275 Open Firmware Boot + * Standard, the name is composed of 1 to 31 letters, + * digits and punctuation characters from the set ",._+-", and + * uppercase and lowercase characters are considered distinct. + * (ie. token := [a-zA-Z0-9,._+-]+, length(token) <= 31) + * However, since either the definition of driver or aliase names is + * not known well, only '#' is avoided explicitly. (the kernel lexical + * analyzer treats it as a start of a comment) + */ + for (/* nothing */; *tok != '\0'; tok++) + if (*tok == '#' || iscntrl(*tok)) + return (B_FALSE); + + return (B_TRUE); +} /* * check each entry in perm_list for: @@ -1326,7 +1410,6 @@ check_perm_opts(char *perm_list) (void) fprintf(stderr, gettext(ERR_BAD_MODE), perm); status = ERROR; } - } free(one_entry); @@ -1384,6 +1467,13 @@ aliases_unique(char *aliases) return (ERROR); } + if (!is_token(one_entry)) { + (void) fprintf(stderr, gettext(ERR_BAD_TOK), + "-i", one_entry); + free(one_entry); + return (ERROR); + } + } while (*current_head != '\0'); free(one_entry); @@ -1409,7 +1499,7 @@ unique_drv_alias(char *drv_alias) { FILE *fp; char drv[FILENAME_MAX + 1]; - char line[MAX_N2M_ALIAS_LINE + 1]; + char line[MAX_N2M_ALIAS_LINE + 1], *cp; char alias[FILENAME_MAX + 1]; int status = NOERR; @@ -1418,6 +1508,13 @@ unique_drv_alias(char *drv_alias) if (fp != NULL) { while ((fgets(line, sizeof (line), fp) != 0) && status != ERROR) { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%s %s", drv, alias) != 2) (void) fprintf(stderr, gettext(ERR_BAD_LINE), driver_aliases, line); @@ -1684,7 +1781,7 @@ int fill_n2m_array(char *filename, char **array, int *nelems) { FILE *fp; - char line[MAX_N2M_ALIAS_LINE + 1]; + char line[MAX_N2M_ALIAS_LINE + 1], *cp; char drv[FILENAME_MAX + 1]; u_longlong_t dnum; major_t drv_majnum; @@ -1700,7 +1797,13 @@ fill_n2m_array(char *filename, char **array, int *nelems) } while (fgets(line, sizeof (line), fp) != 0) { - + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%s %llu", drv, &dnum) != 2) { (void) fprintf(stderr, gettext(ERR_BAD_LINE), filename, line); @@ -1749,3 +1852,18 @@ do_the_update(char *driver_name, char *major_number) return (append_to_file(driver_name, major_number, name_to_major, ' ', " ")); } + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} diff --git a/usr/src/cmd/modload/errmsg.h b/usr/src/cmd/modload/errmsg.h index adaaf90cde..bc41755678 100644 --- a/usr/src/cmd/modload/errmsg.h +++ b/usr/src/cmd/modload/errmsg.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -68,6 +67,7 @@ extern "C" { #define ERR_BAD_LINE "Bad line in file %s : %s\n" #define ERR_CANNOT_OPEN "Cannot open (%s): %s.\n" #define ERR_MIS_TOK "Option (%s) : missing token: (%s)\n" +#define ERR_BAD_TOK "Option (%s) : bad token: (%s)\n" #define ERR_TOO_MANY_ARGS "Option (%s) : too many arguments: (%s)\n" #define ERR_BAD_MODE "Bad mode: (%s)\n" #define ERR_CANT_OPEN "Cannot open (%s)\n" diff --git a/usr/src/cmd/pcmciad/pcmciad.c b/usr/src/cmd/pcmciad/pcmciad.c index be65746dab..d99ca96101 100644 --- a/usr/src/cmd/pcmciad/pcmciad.c +++ b/usr/src/cmd/pcmciad/pcmciad.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -60,6 +59,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <ctype.h> #include <fcntl.h> #include <sys/types.h> #include <sys/fcntl.h> @@ -252,6 +252,8 @@ static void *event_read(void *); static void task_create(int); static void task_init(int); +static int is_blank(char *); + int main(int argc, char *argv[]) { @@ -342,6 +344,21 @@ main(int argc, char *argv[]) } /* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} + +/* * alias handling * we need to be able to find the mapping between certain * device names and the appropriate driver. This code @@ -361,14 +378,22 @@ static void init_aliases(char *path) { FILE *file; - char name[128], alias[128]; + char name[128], alias[128], line[256], *cp; int i, len; struct driver_aliases *nalias; file = fopen(path, "r"); if (file != NULL) { - while (fscanf(file, "%s %[^\n]\n", name, alias) - != EOF) { + while (fgets(line, sizeof (line), file) != NULL) { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ + if (sscanf(line, "%s %[^\n]\n", name, alias) != 2) + continue; if (alias[0] == '"') { len = strlen(alias); for (i = 1; i < len; i++) diff --git a/usr/src/lib/libdevinfo/devinfo_devperm.c b/usr/src/lib/libdevinfo/devinfo_devperm.c index 5a52fc2a6c..412eb74fc8 100644 --- a/usr/src/lib/libdevinfo/devinfo_devperm.c +++ b/usr/src/lib/libdevinfo/devinfo_devperm.c @@ -32,6 +32,7 @@ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include <string.h> #include <unistd.h> #include <dirent.h> @@ -64,6 +65,8 @@ static int dir_dev_acc(char *, char *, uid_t, gid_t, mode_t, char *line, static int setdevaccess(char *, uid_t, gid_t, mode_t, void (*)()); static void logerror(char *); +static int is_blank(char *); + #define MAX_LINELEN 256 #define LOGINDEVPERM "/etc/logindevperm" #define DIRWILD "/*" /* directory wildcard */ @@ -772,14 +775,21 @@ i_devfs_read_minor_perm(char *drvname, void (*errcb)(minorperm_err_t, int)) (*errcb)(MP_FOPEN_ERR, errno); return (NULL); } - while (fgets(line, MAX_MINOR_PERM_LINE - 1, pfd) != NULL) { + while (fgets(line, MAX_MINOR_PERM_LINE, pfd) != NULL) { ln++; + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; mp = (struct mperm *)calloc(1, sizeof (struct mperm)); if (mp == NULL) { (*errcb)(MP_ALLOC_ERR, sizeof (struct mperm)); continue; } cp = line; + /* sanity-check */ if (getnexttoken(cp, &cp, &p, &t) == 0) { (*errcb)(MP_IGNORING_LINE_ERR, ln); devfs_free_minor_perm(mp); @@ -1057,3 +1067,18 @@ devfs_rm_minor_perm(char *drv, { return (i_devfs_update_minor_perm(drv, MODREMMINORPERM, errcb)); } + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} diff --git a/usr/src/lib/lvm/libpreen/common/mdpreen.c b/usr/src/lib/lvm/libpreen/common/mdpreen.c index 6b659dc154..252a1b2768 100644 --- a/usr/src/lib/lvm/libpreen/common/mdpreen.c +++ b/usr/src/lib/lvm/libpreen/common/mdpreen.c @@ -36,6 +36,7 @@ * filesystems that are on top of metadevices. */ +#include <ctype.h> #include <meta.h> #include <limits.h> #include <sys/types.h> @@ -61,6 +62,23 @@ extern void preen_addunit(void *cookie, char *dname, int (*cf)(), void *datap, uint_t unit); extern int preen_subdev(char *name, struct dk_cinfo *dkiop, void *dp); +static int is_blank(char *); + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} + static int get_major_from_n2m(char *modname, int *major) { @@ -68,7 +86,7 @@ get_major_from_n2m(char *modname, int *major) char drv[FILENAME_MAX + 1]; int entry; int found = 0; - char line[MAX_N2M_ALIAS_LINE]; + char line[MAX_N2M_ALIAS_LINE], *cp; int status = 0; if ((fp = fopen(NAME_TO_MAJOR, "r")) == NULL) { @@ -77,7 +95,13 @@ get_major_from_n2m(char *modname, int *major) while ((fgets(line, sizeof (line), fp) != NULL) && status == 0) { - + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%" VAL2STR(FILENAME_MAX) "s %d", drv, &entry) != 2) { status = -1; diff --git a/usr/src/lib/lvm/libsvm/common/getdrvname.c b/usr/src/lib/lvm/libsvm/common/getdrvname.c index 9bef7fa115..a24b85e040 100644 --- a/usr/src/lib/lvm/libsvm/common/getdrvname.c +++ b/usr/src/lib/lvm/libsvm/common/getdrvname.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -28,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include <string.h> #include <limits.h> #include <sys/types.h> @@ -42,6 +42,23 @@ #define QUOTE(x) #x #define VAL2STR(x) QUOTE(x) +static int is_blank(char *); + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} + /* * FUNCTION: * Return the driver name for a major number @@ -61,7 +78,7 @@ get_drv_name(major_t major, char *mnt, char *buf) FILE *fp; char drv[FILENAME_MAX + 1]; char entry[FILENAME_MAX + 1]; - char line[MAX_N2M_ALIAS_LINE]; + char line[MAX_N2M_ALIAS_LINE], *cp; char fname[PATH_MAX]; int status = RET_NOERROR; @@ -73,6 +90,13 @@ get_drv_name(major_t major, char *mnt, char *buf) while ((fgets(line, sizeof (line), fp) != NULL) && status == RET_NOERROR) { + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) + continue; + /* sanity-check */ if (sscanf(line, "%" VAL2STR(FILENAME_MAX) "s %" VAL2STR(FILENAME_MAX) "s", drv, entry) != 2) { @@ -80,7 +104,6 @@ get_drv_name(major_t major, char *mnt, char *buf) } if (atoi(entry) == major) break; - } if (status == RET_NOERROR) diff --git a/usr/src/lib/lvm/libsvm/common/metaconf.c b/usr/src/lib/lvm/libsvm/common/metaconf.c index 504f38ba73..11bca39ed8 100644 --- a/usr/src/lib/lvm/libsvm/common/metaconf.c +++ b/usr/src/lib/lvm/libsvm/common/metaconf.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -46,13 +45,20 @@ extern int _map_to_effective_dev(); -int -is_blankline(char *buf) +static int is_blank(char *); + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) { - for (; *buf != 0; buf++) { - if (!isspace(*buf)) + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) return (0); - } return (1); } @@ -87,9 +93,11 @@ write_targ_nm_table(char *path) while (fgets(buf, PATH_MAX, targfp) != NULL && (retval == RET_SUCCESS)) { - cp = strrchr(buf, '\n'); - *cp = 0; - if (is_blankline(buf)) + /* cut off comments starting with '#' */ + if ((cp = strchr(buf, '#')) != NULL) + *cp = 0; + /* ignore comment or blank lines */ + if (is_blank(buf)) continue; if (first_entry) { if (fprintf(mdfp, "md_targ_nm_table=\"%s\"", buf) < 0) diff --git a/usr/src/pkgdefs/common_files/i.drvalias b/usr/src/pkgdefs/common_files/i.drvalias index 6bbb36b283..d630cb49d3 100644 --- a/usr/src/pkgdefs/common_files/i.drvalias +++ b/usr/src/pkgdefs/common_files/i.drvalias @@ -34,72 +34,151 @@ PATH=/usr/bin:/usr/sbin:$PATH; export PATH # obsolete_sparc() { - sed -e '/^cpu modi4v0m[ ]*$/d' \ - -e '/^PFUaga PFU,aga[ ]*$/d' \ - -e '/^dbri SUNW,DBRIs3[ ]*$/d' \ - -e '/^dbri SUNW,DBRId[ ]*$/d' \ - -e '/^dbri SUNW,DBRIe[ ]*$/d' \ - -e '/^dbri SUNW,DBRIf[ ]*$/d' \ - -e '/^leo SUNW,leo104[ ]*$/d' \ - -e '/^atapicd "ide-cdrom"[ ]*$/d' \ - -e '/^cpu TI,TMS390Z50[ ]*$/d' \ - -e '/^obio bootbus[ ]*$/d' \ - -e '/^sw drum[ ]*$/d' \ - -e '/^ie sie[ ]*$/d' \ - -e '/^sbus sbi[ ]*$/d' \ - -e '/^pn SUNW,pn[ ]*$/d' \ - -e '/^glm SUNW,glm[ ]*$/d' \ - -e '/^gpio_87317 "gpio"[ ]*$/d' \ - -e '/^pci SUNW,pci[ ]*$/d' \ - -e '/^pci "pci108e,8000"[ ]*$/d' \ - -e '/^pci "pci108e,a000"[ ]*$/d' \ - -e '/^pci "pciclass,060000"[ ]*$/d' \ - -e '/^px "pci108e,80f0"[ ]*$/d' \ - -e '/^px_pci "pci1033,124"[ ]*$/d' \ - -e '/^px_pci "pci1033,125"[ ]*$/d' \ - -e '/^px_pci "pci8086,340"[ ]*$/d' \ - -e '/^px_pci "pci8086,341"[ ]*$/d' \ - -e '/^px_pci "pci10b5,8532"[ ]*$/d' \ - -e '/^px_pci "pci10b5,8516"[ ]*$/d' \ - -e '/^sx SUNW,sx[ ]*$/d' \ - -e '/^sx "SUNW,sx"[ ]*$/d' \ - -e '/^xbox SUNW,xbox[ ]*$/d' \ - -e '/^xbox "SUNW,xbox"[ ]*$/d' \ - -e '/^stc SUNW,spif[ ]*$/d' \ - -e '/^fjulsa "pci13e9,30"[ ]*$/d' \ - -e '/^fjulsa "pci1000,30"[ ]*$/d' \ - -e '/^cpu TI,TMS390Z55[ ]*$/d' \ - -e '/^mic SUNW,mic[ ]*$/d' \ - -e '/^pln SUNW,pln[ ]*$/d' \ - -e '/^soc SUNW,soc[ ]*$/d' \ - -e '/^sc_nct "nct-ds80ch11-smc"[ ]*$/d' \ - -e '/^tomtppm jbus-ppm[ ]*$/d' + sed \ + -e '/^[ ]*cpu[ ][ ]*modi4v0m$/d' \ + -e '/^[ ]*cpu[ ][ ]*modi4v0m[ #].*$/d' \ + -e '/^[ ]*PFUaga[ ][ ]*PFU,aga$/d' \ + -e '/^[ ]*PFUaga[ ][ ]*PFU,aga[ #].*$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIs3$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIs3[ #].*$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRId$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRId[ #].*$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIe$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIe[ #].*$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIf$/d' \ + -e '/^[ ]*dbri[ ][ ]*SUNW,DBRIf[ #].*$/d' \ + -e '/^[ ]*leo[ ][ ]*SUNW,leo104$/d' \ + -e '/^[ ]*leo[ ][ ]*SUNW,leo104[ #].*$/d' \ + -e '/^[ ]*atapicd[ ][ ]*"ide-cdrom"$/d' \ + -e '/^[ ]*atapicd[ ][ ]*"ide-cdrom"[ #].*$/d' \ + -e '/^[ ]*cpu[ ][ ]*TI,TMS390Z50$/d' \ + -e '/^[ ]*cpu[ ][ ]*TI,TMS390Z50[ #].*$/d' \ + -e '/^[ ]*obio[ ][ ]*bootbus$/d' \ + -e '/^[ ]*obio[ ][ ]*bootbus[ #].*$/d' \ + -e '/^[ ]*sw[ ][ ]*drum$/d' \ + -e '/^[ ]*sw[ ][ ]*drum[ #].*$/d' \ + -e '/^[ ]*ie[ ][ ]*sie$/d' \ + -e '/^[ ]*ie[ ][ ]*sie[ #].*$/d' \ + -e '/^[ ]*sbus[ ][ ]*sbi$/d' \ + -e '/^[ ]*sbus[ ][ ]*sbi[ #].*$/d' \ + -e '/^[ ]*pn[ ][ ]*SUNW,pn$/d' \ + -e '/^[ ]*pn[ ][ ]*SUNW,pn[ #].*$/d' \ + -e '/^[ ]*glm[ ][ ]*SUNW,glm$/d' \ + -e '/^[ ]*glm[ ][ ]*SUNW,glm[ #].*$/d' \ + -e '/^[ ]*gpio_87317[ ][ ]*"gpio"$/d' \ + -e '/^[ ]*gpio_87317[ ][ ]*"gpio"[ #].*$/d' \ + -e '/^[ ]*pci[ ][ ]*SUNW,pci$/d' \ + -e '/^[ ]*pci[ ][ ]*SUNW,pci[ #].*$/d' \ + -e '/^[ ]*pci[ ][ ]*"pci108e,8000"$/d' \ + -e '/^[ ]*pci[ ][ ]*"pci108e,8000"[ #].*$/d' \ + -e '/^[ ]*pci[ ][ ]*"pci108e,a000"$/d' \ + -e '/^[ ]*pci[ ][ ]*"pci108e,a000"[ #].*$/d' \ + -e '/^[ ]*pci[ ][ ]*"pciclass,060000"$/d' \ + -e '/^[ ]*pci[ ][ ]*"pciclass,060000"[ #].*$/d' \ + -e '/^[ ]*px[ ][ ]*"pci108e,80f0"$/d' \ + -e '/^[ ]*px[ ][ ]*"pci108e,80f0"[ #].*$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci1033,124"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci1033,124"[ #].*$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci1033,125"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci1033,125"[ #].*/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci8086,340"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci8086,340"[ #].*$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci8086,341"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci8086,341"[ #].*$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci10b5,8532"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci10b5,8532"[ #].*$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci10b5,8516"$/d' \ + -e '/^[ ]*px_pci[ ][ ]*"pci10b5,8516"[ #].*$/d' \ + -e '/^[ ]*sx[ ][ ]*SUNW,sx$/d' \ + -e '/^[ ]*sx[ ][ ]*SUNW,sx[ #].*$/d' \ + -e '/^[ ]*sx[ ][ ]*"SUNW,sx"$/d' \ + -e '/^[ ]*sx[ ][ ]*"SUNW,sx"[ #].*$/d' \ + -e '/^[ ]*xbox[ ][ ]*SUNW,xbox$/d' \ + -e '/^[ ]*xbox[ ][ ]*SUNW,xbox[ #].*$/d' \ + -e '/^[ ]*xbox[ ][ ]*"SUNW,xbox"$/d' \ + -e '/^[ ]*xbox[ ][ ]*"SUNW,xbox"[ #].*$/d' \ + -e '/^[ ]*stc[ ][ ]*SUNW,spif$/d' \ + -e '/^[ ]*stc[ ][ ]*SUNW,spif[ #].*$/d' \ + -e '/^[ ]*fjulsa[ ][ ]*"pci13e9,30"$/d' \ + -e '/^[ ]*fjulsa[ ][ ]*"pci13e9,30"[ #].*$/d' \ + -e '/^[ ]*fjulsa[ ][ ]*"pci1000,30"$/d' \ + -e '/^[ ]*fjulsa[ ][ ]*"pci1000,30"[ #].*$/d' \ + -e '/^[ ]*cpu[ ][ ]*TI,TMS390Z55$/d' \ + -e '/^[ ]*cpu[ ][ ]*TI,TMS390Z55[ #].*$/d' \ + -e '/^[ ]*mic[ ][ ]*SUNW,mic$/d' \ + -e '/^[ ]*mic[ ][ ]*SUNW,mic[ #].*$/d' \ + -e '/^[ ]*pln[ ][ ]*SUNW,pln$/d' \ + -e '/^[ ]*pln[ ][ ]*SUNW,pln[ #].*$/d' \ + -e '/^[ ]*soc[ ][ ]*SUNW,soc$/d' \ + -e '/^[ ]*soc[ ][ ]*SUNW,soc[ #].*$/d' \ + -e '/^[ ]*sc_nct[ ][ ]*"nct-ds80ch11-smc"$/d' \ + -e '/^[ ]*sc_nct[ ][ ]*"nct-ds80ch11-smc"[ #].*$/d' \ + -e '/^[ ]*tomtppm[ ][ ]*jbus-ppm$/d' \ + -e '/^[ ]*tomtppm[ ][ ]*jbus-ppm[ #].*$/d' } # # obsolete_i386 - Filter function to remove obsolete i386 driver aliases. # obsolete_i386() { - sed -e '/^elx[^l].*10b7,9000.*$/d' \ - -e '/^elx[^l].*10b7,9050.*$/d' \ - -e '/^dpt[ ]*"pci1044,a400"[ ]*$/d' \ - -e '/^audiocs[ ]*"SUNW,CS4231"[ ]*$/d' \ - -e '/^blogic[ ]*"pci104b,1040"[ ]*$/d' \ - -e '/^mega[ ]*"pci101e,9010"[ ]*$/d' \ - -e '/^mlx[ ]*"pci1069,1"[ ]*$/d' \ - -e '/^mlx[ ]*"pci1069,2"[ ]*$/d' \ - -e '/^mlx[ ]*"pci1069,10"[ ]*$/d' \ - -e '/^mlx[ ]*"pci1069,11"[ ]*$/d' \ - -e '/^p9000[ ]*"pci100e,9001"[ ]*$/d' \ - -e '/^p9100[ ]*"pci100e,9100"[ ]*$/d' \ - -e '/^pcie_pci[ ]*"pciex1011,1"[ ]*$/d' \ - -e '/^pcie_pci[ ]*"pciex1011,21"[ ]*$/d' \ - -e '/^pcie_pci[ ]*"pciex1014,22"[ ]*$/d' \ - -e '/^spwr[ ]*"pci10b8,0005"[ ]*$/d' \ - -e '/^chs[ ]*"pci1014,2e"[ ]*$/d' \ - -e '/^cpqncr[ ]*"pcie11,7004"[ ]*$/d' \ - -e '/^smartii[ ]*"pcie11,4030"[ ]*$/d' \ - -e '/^smartii[ ]*"pcie11,4031"[ ]*$/d' + sed \ + -e '/^[ ]*elx[^l].*10b7,9000.*/d' \ + -e '/^[ ]*elx[^l].*10b7,9050.*/d' \ + -e '/^[ ]*dpt[ ][ ]*"pci1044,a400"$/d' \ + -e '/^[ ]*dpt[ ][ ]*"pci1044,a400"[ #].*$/d' \ + -e '/^[ ]*audiocs[ ][ ]*"SUNW,CS4231"$/d' \ + -e '/^[ ]*audiocs[ ][ ]*"SUNW,CS4231"[ #].*$/d' \ + -e '/^[ ]*blogic[ ][ ]*"pci104b,1040"$/d' \ + -e '/^[ ]*blogic[ ][ ]*"pci104b,1040"[ #].*$/d' \ + -e '/^[ ]*mega[ ][ ]*"pci101e,9010"$/d' \ + -e '/^[ ]*mega[ ][ ]*"pci101e,9010"[ #].*$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,1"$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,1"[ #].*$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,2"$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,2"[ #].*$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,10"$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,10"[ #].*$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,11"$/d' \ + -e '/^[ ]*mlx[ ][ ]*"pci1069,11"[ #].*$/d' \ + -e '/^[ ]*p9000[ ][ ]*"pci100e,9001"$/d' \ + -e '/^[ ]*p9000[ ][ ]*"pci100e,9001"[ #].*$/d' \ + -e '/^[ ]*p9100[ ][ ]*"pci100e,9100"$/d' \ + -e '/^[ ]*p9100[ ][ ]*"pci100e,9100"[ #].*$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1011,1"$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1011,1"[ #].*$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1011,21"$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1011,21"[ #].*$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1014,22"$/d' \ + -e '/^[ ]*pcie_pci[ ][ ]*"pciex1014,22"[ #].*$/d' \ + -e '/^[ ]*spwr[ ][ ]*"pci10b8,0005"$/d' \ + -e '/^[ ]*spwr[ ][ ]*"pci10b8,0005"[ #].*$/d' \ + -e '/^[ ]*chs[ ][ ]*"pci1014,2e"$/d' \ + -e '/^[ ]*chs[ ][ ]*"pci1014,2e"[ #].*$/d' \ + -e '/^[ ]*cpqncr[ ][ ]*"pcie11,7004"$/d' \ + -e '/^[ ]*cpqncr[ ][ ]*"pcie11,7004"[ #].*$/d' \ + -e '/^[ ]*smartii[ ][ ]*"pcie11,4030"$/d' \ + -e '/^[ ]*smartii[ ][ ]*"pcie11,4030"[ #].*$/d' \ + -e '/^[ ]*smartii[ ][ ]*"pcie11,4031"$/d' \ + -e '/^[ ]*smartii[ ][ ]*"pcie11,4031"[ #].*$/d' +} + +# +# check if the driver aliase specified is already installed. +# ignore a comment if exists. +# +is_installed () +{ + file=$3 + nawk -v driver=$1 -v alias=$2 -v delimiter='#' ' \ + $1 == driver && $2 == alias \ + { found = 1; exit 0 } \ + $1 == driver \ + { num = split($2, a_array, delimiter); \ + if (num > 1 && a_array[1] == alias) \ + { found = 1; exit 0 } \ + } \ + END { if (!found) exit 1 } ' $file + return $? } # @@ -124,15 +203,20 @@ while read src dest; do cp /tmp/oda.$$.tmp $dest rm -f /tmp/oda.$$.tmp fi - + # + # Remove comment and/or blank lines before reading + # + egrep -v -e "^[ ]*#.*$|^[ ]*$" $src | \ + sed -e 's/#.*$//' > /tmp/oda.$$.tmp # # If the alias is not present in the driver_aliases # file, then append it: # - while read alias driver; do - grep "^$alias[ ][ ]*$driver[ ]*" $dest \ - >/dev/null 2>&1 || echo "$alias $driver" >>$dest - done < $src + while read driver alias; do + is_installed $driver $alias $dest \ + >/dev/null 2>&1 || echo "$driver $alias" >>$dest + done < /tmp/oda.$$.tmp + rm -f /tmp/oda.$$.tmp else # # If no driver_aliases is present on the target system, diff --git a/usr/src/pkgdefs/common_files/i.nametomajor b/usr/src/pkgdefs/common_files/i.nametomajor index c6b6a58547..1a9fa954cc 100644 --- a/usr/src/pkgdefs/common_files/i.nametomajor +++ b/usr/src/pkgdefs/common_files/i.nametomajor @@ -21,7 +21,7 @@ # # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident "%Z%%M% %I% %E% SMI" @@ -29,75 +29,6 @@ PATH=/usr/bin:/usr/sbin:$PATH; export PATH # -# add_major - adds new major numbers to system for device drivers on older -# Solaris systems where add_drv -b was not available or had bugs. This -# code will be removed when doing a server_upgrade on systems with missing -# or broken add_drv is eventually EOL'd. DO NOT COPY THIS CODE TO OTHER -# PACKAGE SCRIPTS! -# -add_major() -{ - tmpfile=/tmp/nm.$$.tmp - - if [ -f $BASEDIR/etc/rem_name_to_major ]; then - rem_file="$BASEDIR/etc/rem_name_to_major" - fi - - sort +1 -2n $dest $rem_file | nawk '# -BEGIN {oldmajor = -1} -NR == 1 {n=split(namelist,x) - if (n < 1) - exit(1) - for (i=1; i<=n; i++) - chklist[x[i]]++ - } - {for (name in chklist) - { - if ($1 == name) - delete chklist[name] - } - if (($2 - oldmajor) > 1) - { - gap++ - gaplist[gap] = oldmajor " " $2; - } - oldmajor = $2; - } -END {addsize=1 - for (name in chklist) - addlist[addsize++] = name - - addidx = 1 - for (i=1; i<=gap && addidx < addsize; i++) - { - split(gaplist[i],x) - begmajor = x[1] - endmajor = x[2] - for (begmajor++;begmajor < endmajor && addidx < addsize;) - { - printf "%s %d\n",addlist[addidx],begmajor - addidx++ - begmajor++ - } - } - for (; addidx < addsize; addidx++) - { - oldmajor++ - printf "%s %d\n",addlist[addidx],oldmajor - } - } -' namelist="$*" - > $tmpfile - - if [ -s $tmpfile ]; then - echo "Adding the following devices to $dest :" - cat $tmpfile - sort +1 -2n $dest $tmpfile -o $dest - fi - - rm -f $tmpfile -} - -# # obsolete_sparc - Filter function to remove obsolete SPARC driver entries. # We define an associative array of bad driver names, and then nawk out # lines where the first token is defined in our array. @@ -173,7 +104,7 @@ obsolete_sparc() obs["soc"] = 1; obs["sc_nct"] = 1; obs["tomtppm"] = 1; - } !($1 in obs) { print $1, $2 }' + } !($1 in obs) { print $0 }' } # @@ -244,7 +175,7 @@ obsolete_i386() obs["tiqmouse"] = 1; obs["tr"] = 1; obs["trantor"] = 1; - } !($1 in obs) { print $1, $2 }' + } !($1 in obs) { print $0 }' } # @@ -258,6 +189,26 @@ for file in driver_aliases driver_classes minor_perm name_to_major; do done # +# check if the driver specified is already installed. +# the second token must be the decimal digit. +# ignore a comment if exists. +# +is_installed () +{ + file=$2 + nawk -v driver=$1 -v delimiter='#' ' \ + $1 == driver && $2 ~ /^[0-9][0-9]*$/ \ + { found = 1; exit 0 } \ + $1 == driver \ + { num = split($2, n_array, delimiter); \ + if (num > 1 && n_array[1] ~ /^[0-9][0-9]*$/) \ + { found = 1; exit 0 } \ + } \ + END { if (!found) exit 1 } ' $file + return $? +} + +# # Add_drv needs /etc/driver_aliases in order to work properly; if for # some reason it has been removed, create an empty one at this time. # Recall that in SUNWcsr's pkginfo.tmpl, the driver_aliases class-action @@ -290,52 +241,31 @@ while read src dest; do cp /tmp/onm.$$.tmp $dest rm -f /tmp/onm.$$.tmp - # PKG_CLIENT_VERSION is provided by PSARC 2001/472 for allowing - # package developers to inspect a client's OS VERSION from - # within a package procedure script. It returns following - # possible OS VERSION #'s(up to S10): 2.3, 2.4, 2.5, 2.5.1, 2.6 - # 2.7, 8, 9, 10... - if [ "$PKG_CLIENT_VERSION" ]; then - # remove the leading "2.", if any - os_rev=`echo $PKG_CLIENT_VERSION | sed -e 's/^2\.//'` - else - # fall back to use "uname" and remove the leading "5." - os_rev=`uname -r | sed -e 's/^5\.//'` - fi - + # + # Remove comment and/or blank lines before reading + # + nawk '$1 !~ /^#|^$/ {print $0}' $src | sed -e 's/#.*$//' | \ while read name major; do # # If the driver is already present in name_to_major, # leave the existing number and continue # - grep -w $name $dest >/dev/null 2>&1 && continue - + is_installed $name $dest >/dev/null 2>&1 && continue # # Otherwise add the driver to name_to_major using - # add_major or add_drv: + # add_drv. add_drv produces spurious output even on + # success, so save its output in a temporary + # file in case an error occurs. # - case $os_rev in - "3") add_major $name;; - "4") add_major $name;; - "5") add_major $name;; - "5.1") add_major $name;; - *) - # - # add_drv produces spurious output even on - # success, so save its output in a temporary - # file in case an error occurs. - # - if add_drv -b $BASEDIR $name \ - >/tmp/ad.$$.tmp 2>&1; then - echo "added $name to $dest" - else - echo "$PKG: failed to add $name to " \ - "$dest:" >& 2 - cat /tmp/ad.$$.tmp >& 2 - fi - ;; - esac - done < $src + if add_drv -b $BASEDIR $name \ + >/tmp/ad.$$.tmp 2>&1; then + echo "added $name to $dest" + else + echo "$PKG: failed to add $name to " \ + "$dest:" >& 2 + cat /tmp/ad.$$.tmp >& 2 + fi + done rm -f /tmp/ad.$$.tmp else # @@ -344,7 +274,5 @@ while read src dest; do # cp -p $src $dest fi - - sort +1 -2n -o $dest $dest done exit 0 diff --git a/usr/src/tools/scripts/bfu.sh b/usr/src/tools/scripts/bfu.sh index 8e30a7c410..8c97cd0017 100644 --- a/usr/src/tools/scripts/bfu.sh +++ b/usr/src/tools/scripts/bfu.sh @@ -3690,7 +3690,8 @@ then # Load modules and drivers here not to reload them when you access # /devices or its subdirectories later. # - cut -d' ' -f1 /etc/name_to_major | while read driver + nawk '$1 !~ /^#|^$/ {print $1}' /etc/name_to_major | \ + sed -e 's/#.*$//' | while read driver do modload -p drv/${driver} >/dev/null 2>&1 done diff --git a/usr/src/ucbcmd/ucblinks/ucblinks.c b/usr/src/ucbcmd/ucblinks/ucblinks.c index 1f96a85f2b..92e3357ed3 100644 --- a/usr/src/ucbcmd/ucblinks/ucblinks.c +++ b/usr/src/ucbcmd/ucblinks/ucblinks.c @@ -199,6 +199,7 @@ static void set_depth(void); static void get_devices(void); static void get_dev_links(void); static void call_device_rules(void); +static int is_blank(char *); /* * The command-line arguments to ucblinks are: @@ -381,8 +382,8 @@ static void get_major_nums(void) { FILE *fp; - char line[80]; - char *name, *maj, *end; + char line[FILENAME_MAX*2 + 1]; /* use the same size as add_drv does */ + char *name, *maj, *end, *cp; int majnum; struct drvinfo *drp; @@ -394,18 +395,18 @@ get_major_nums(void) } while (fgets(line, sizeof (line), fp) != NULL) { - name = strtok(line, " \t"); - if (name == NULL) + /* cut off comments starting with '#' */ + if ((cp = strchr(line, '#')) != NULL) + *cp = '\0'; + /* ignore comment or blank lines */ + if (is_blank(line)) continue; - - maj = strtok(NULL, "\n"); - if (maj == NULL) + name = strtok(line, " \t"); /* must not be NULL */ + if ((maj = strtok(NULL, "\n")) == NULL) continue; - majnum = strtol(maj, &end, 10); if (end == maj) continue; - /* * Compare against our list and set the major * number it it's a name we care about. @@ -1484,3 +1485,18 @@ rule_zs(struct devices_ent *dep) (void) closedir(dirp); } + +/* + * is_blank() returns 1 (true) if a line specified is composed of + * whitespace characters only. otherwise, it returns 0 (false). + * + * Note. the argument (line) must be null-terminated. + */ +static int +is_blank(char *line) +{ + for (/* nothing */; *line != '\0'; line++) + if (!isspace(*line)) + return (0); + return (1); +} diff --git a/usr/src/ucbcmd/ucblinks/ucblinks.sh b/usr/src/ucbcmd/ucblinks/ucblinks.sh index 974b542d82..ce5f5a88f7 100644 --- a/usr/src/ucbcmd/ucblinks/ucblinks.sh +++ b/usr/src/ucbcmd/ucblinks/ucblinks.sh @@ -3,9 +3,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,11 +19,11 @@ # # CDDL HEADER END # -# -# Copyright (c) 1991 by Sun Microsystems, Inc. + +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. # #ident "%Z%%M% %I% %E% SMI" -# PATH=/sbin:/usr/sbin:/usr/bin:/etc export PATH @@ -168,7 +167,11 @@ cat <<\!EOD >$GENSED # "major number" field into its corresponding 'name'. This is so that # the difference in major-numbers among different machines can be hidden. # -grep -v '^#' /etc/name_to_major | sed -e '1,$s-^\([^ ]*\)[ ][ ]*\([^ ][^ ]*\)$-/^\2 /s/^\2 /\1 /-' >>$GENSED +nawk -v del='#' '$1 !~ /^#|^$/ { \ + num = split($2, maj, del); \ + if (num > 1) { printf("/^%s\t/ s/^%s\t/%s\t/\n", maj[1], maj[1], $1) } \ + else { printf("/^%s\t/ s/^%s\t/%s\t/\n", $2, $2, $1) } \ +} ' /etc/name_to_major >> $GENSED # #---------------------------------------------------------------------- diff --git a/usr/src/uts/common/os/modsysfile.c b/usr/src/uts/common/os/modsysfile.c index 647f59412e..6e94457e95 100644 --- a/usr/src/uts/common/os/modsysfile.c +++ b/usr/src/uts/common/os/modsysfile.c @@ -1921,6 +1921,9 @@ get_hwc_spec(struct _buf *file, char *tokbuf, size_t linesize) kobj_newline(file); break; case POUND: + /* + * Skip comments. + */ kobj_find_eol(file); break; case EOF: @@ -2169,7 +2172,9 @@ make_aliases(struct bind **bhash) token = kobj_lex(file, tokbuf, sizeof (tokbuf)); switch (token) { case POUND: - state = AL_NEW; + /* + * Skip comments. + */ kobj_find_eol(file); break; case NAME: @@ -2202,6 +2207,11 @@ make_aliases(struct bind **bhash) != 0) { cmn_err(CE_WARN, dupwarn, drvbuf); } + /* + * copy this token just in case that there + * are multiple names on the same line. + */ + (void) strcpy(drvbuf, tokbuf); break; } break; @@ -2288,7 +2298,9 @@ read_binding_file(char *bindfile, struct bind **hashtab, switch (token) { case POUND: - state = B_NEW; + /* + * Skip comments. + */ kobj_find_eol(file); break; case NAME: @@ -2831,6 +2843,9 @@ read_class_file(void) switch (token) { case POUND: + /* + * Skip comments. + */ kobj_find_eol(file); break; case NAME: @@ -2958,6 +2973,9 @@ open_mach_list(void) while ((token = kobj_lex(file, tokbuf, sizeof (tokbuf))) != EOF) { switch (token) { case POUND: + /* + * Skip comments. + */ kobj_find_eol(file); break; case NAME: @@ -3041,6 +3059,9 @@ process_rtc_config_file(void) switch (token) { case POUND: + /* + * Skip comments. + */ kobj_find_eol(file); break; case NAME: |