Print this page
9696 add /etc/system.d support
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Cynthia Eastham <cynthia.eastham@nexenta.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2016 Nexenta Systems, Inc.
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <sys/inttypes.h>
  30 #include <sys/param.h>
  31 #include <sys/systm.h>
  32 #include <sys/user.h>
  33 #include <sys/disp.h>
  34 #include <sys/conf.h>
  35 #include <sys/bootconf.h>
  36 #include <sys/sysconf.h>
  37 #include <sys/sunddi.h>
  38 #include <sys/esunddi.h>
  39 #include <sys/ddi_impldefs.h>
  40 #include <sys/kmem.h>
  41 #include <sys/vmem.h>
  42 #include <sys/fs/ufs_fsdir.h>
  43 #include <sys/hwconf.h>
  44 #include <sys/modctl.h>
  45 #include <sys/cmn_err.h>


  47 #include <sys/kobj_lex.h>
  48 #include <sys/errno.h>
  49 #include <sys/debug.h>
  50 #include <sys/autoconf.h>
  51 #include <sys/callb.h>
  52 #include <sys/sysmacros.h>
  53 #include <sys/dacf.h>
  54 #include <vm/seg_kmem.h>
  55 
  56 struct hwc_class *hcl_head;     /* head of list of classes */
  57 static kmutex_t hcl_lock;       /* for accessing list of classes */
  58 
  59 #define DAFILE          "/etc/driver_aliases"
  60 #define CLASSFILE       "/etc/driver_classes"
  61 #define DACFFILE        "/etc/dacf.conf"
  62 
  63 static char class_file[] = CLASSFILE;
  64 static char dafile[] = DAFILE;
  65 static char dacffile[] = DACFFILE;
  66 

  67 char *systemfile = "/etc/system";       /* name of ascii system file */
  68 
  69 static struct sysparam *sysparam_hd;    /* head of parameters list */
  70 static struct sysparam *sysparam_tl;    /* tail of parameters list */
  71 static vmem_t *mod_sysfile_arena;       /* parser memory */
  72 
  73 char obp_bootpath[BO_MAXOBJNAME];       /* bootpath from obp */
  74 
  75 #if defined(_PSM_MODULES)
  76 
  77 struct psm_mach {
  78         struct psm_mach *m_next;
  79         char            *m_machname;
  80 };
  81 
  82 static struct psm_mach *pmach_head;     /* head of list of classes */
  83 
  84 #define MACHFILE        "/etc/mach"
  85 static char mach_file[] = MACHFILE;
  86 


 734                 *cp = '\0';
 735 
 736                 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(tok1) + 1,
 737                     VM_SLEEP);
 738                 (void) strcpy(sysp->sys_ptr, tok1);
 739                 break;
 740 
 741         case MOD_UNKNOWN:
 742         default:
 743                 kobj_file_err(CE_WARN, file, "unknown command '%s'", cmd);
 744                 goto bad;
 745         }
 746 
 747         return (sysp);
 748 
 749 bad:
 750         kobj_find_eol(file);
 751         return (NULL);
 752 }
 753 
 754 void
 755 mod_read_system_file(int ask)
 756 {
 757         register struct sysparam *sp;
 758         register struct _buf *file;
 759         register token_t token, last_tok;
 760         char tokval[MAXLINESIZE];
 761 
 762         mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
 763             segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
 764 
 765         if (ask)
 766                 mod_askparams();
 767 
 768         if (systemfile != NULL) {
 769 
 770                 if ((file = kobj_open_file(systemfile)) ==
 771                     (struct _buf *)-1) {

 772                         cmn_err(CE_WARN, "cannot open system file: %s",
 773                             systemfile);
 774                 } else {

 775                         sysparam_tl = (struct sysparam *)&sysparam_hd;
 776 
 777                         last_tok = NEWLINE;
 778                         while ((token = kobj_lex(file, tokval,
 779                             sizeof (tokval))) != EOF) {
 780                                 switch (token) {
 781                                 case STAR:
 782                                 case POUND:
 783                                         /*
 784                                          * Skip comments.
 785                                          */
 786                                         kobj_find_eol(file);
 787                                         break;
 788                                 case NEWLINE:
 789                                         kobj_newline(file);
 790                                         last_tok = NEWLINE;
 791                                         break;
 792                                 case NAME:
 793                                         if (last_tok != NEWLINE) {
 794                                                 kobj_file_err(CE_WARN, file,
 795                                                     extra_err, tokval);
 796                                                 kobj_find_eol(file);
 797                                         } else if ((sp = do_sysfile_cmd(file,
 798                                             tokval)) != NULL) {
 799                                                 sp->sys_next = NULL;
 800                                                 sysparam_tl->sys_next = sp;
 801                                                 sysparam_tl = sp;
 802                                         }
 803                                         last_tok = NAME;
 804                                         break;
 805                                 default:
 806                                         kobj_file_err(CE_WARN,
 807                                             file, tok_err, tokval);
 808                                         kobj_find_eol(file);
 809                                         break;
 810                                 }
 811                         }
 812                         kobj_close_file(file);
 813                 }
 814         }
 815 









 816         /*










 817          * Sanity check of /etc/system.
 818          */
 819         check_system_file();
 820 
 821         param_preset();
 822         (void) mod_sysctl(SYS_SET_KVAR, NULL);
 823         param_check();
 824 
 825         if (ask == 0)
 826                 setparams();
 827 }
 828 
 829 /*
 830  * Search for a specific module variable assignment in /etc/system.  If
 831  * successful, 1 is returned and the value is stored in '*value'.
 832  * Otherwise 0 is returned and '*value' isn't modified.  If 'module' is
 833  * NULL we look for global definitions.
 834  *
 835  * This is useful if the value of an assignment is needed before a
 836  * module is loaded (e.g. to obtain a default privileged rctl limit).




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2017 Nexenta Systems, Inc.
  26  */
  27 
  28 #include <sys/types.h>
  29 #include <sys/inttypes.h>
  30 #include <sys/param.h>
  31 #include <sys/systm.h>
  32 #include <sys/user.h>
  33 #include <sys/disp.h>
  34 #include <sys/conf.h>
  35 #include <sys/bootconf.h>
  36 #include <sys/sysconf.h>
  37 #include <sys/sunddi.h>
  38 #include <sys/esunddi.h>
  39 #include <sys/ddi_impldefs.h>
  40 #include <sys/kmem.h>
  41 #include <sys/vmem.h>
  42 #include <sys/fs/ufs_fsdir.h>
  43 #include <sys/hwconf.h>
  44 #include <sys/modctl.h>
  45 #include <sys/cmn_err.h>


  47 #include <sys/kobj_lex.h>
  48 #include <sys/errno.h>
  49 #include <sys/debug.h>
  50 #include <sys/autoconf.h>
  51 #include <sys/callb.h>
  52 #include <sys/sysmacros.h>
  53 #include <sys/dacf.h>
  54 #include <vm/seg_kmem.h>
  55 
  56 struct hwc_class *hcl_head;     /* head of list of classes */
  57 static kmutex_t hcl_lock;       /* for accessing list of classes */
  58 
  59 #define DAFILE          "/etc/driver_aliases"
  60 #define CLASSFILE       "/etc/driver_classes"
  61 #define DACFFILE        "/etc/dacf.conf"
  62 
  63 static char class_file[] = CLASSFILE;
  64 static char dafile[] = DAFILE;
  65 static char dacffile[] = DACFFILE;
  66 
  67 char *self_assembly = "/etc/system.d/.self-assembly";
  68 char *systemfile = "/etc/system";       /* name of ascii system file */
  69 
  70 static struct sysparam *sysparam_hd;    /* head of parameters list */
  71 static struct sysparam *sysparam_tl;    /* tail of parameters list */
  72 static vmem_t *mod_sysfile_arena;       /* parser memory */
  73 
  74 char obp_bootpath[BO_MAXOBJNAME];       /* bootpath from obp */
  75 
  76 #if defined(_PSM_MODULES)
  77 
  78 struct psm_mach {
  79         struct psm_mach *m_next;
  80         char            *m_machname;
  81 };
  82 
  83 static struct psm_mach *pmach_head;     /* head of list of classes */
  84 
  85 #define MACHFILE        "/etc/mach"
  86 static char mach_file[] = MACHFILE;
  87 


 735                 *cp = '\0';
 736 
 737                 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(tok1) + 1,
 738                     VM_SLEEP);
 739                 (void) strcpy(sysp->sys_ptr, tok1);
 740                 break;
 741 
 742         case MOD_UNKNOWN:
 743         default:
 744                 kobj_file_err(CE_WARN, file, "unknown command '%s'", cmd);
 745                 goto bad;
 746         }
 747 
 748         return (sysp);
 749 
 750 bad:
 751         kobj_find_eol(file);
 752         return (NULL);
 753 }
 754 
 755 static void
 756 read_system_file(char *name)
 757 {
 758         register struct sysparam *sp;
 759         register struct _buf *file;
 760         register token_t token, last_tok;
 761         char tokval[MAXLINESIZE];
 762 
 763         if ((file = kobj_open_file(name)) ==








 764             (struct _buf *)-1) {
 765                 if (strcmp(name, systemfile) == 0)
 766                         cmn_err(CE_WARN, "cannot open system file: %s",
 767                             name);
 768         } else {
 769                 if (sysparam_tl == NULL)
 770                         sysparam_tl = (struct sysparam *)&sysparam_hd;
 771 
 772                 last_tok = NEWLINE;
 773                 while ((token = kobj_lex(file, tokval,
 774                     sizeof (tokval))) != EOF) {
 775                         switch (token) {
 776                         case STAR:
 777                         case POUND:
 778                                 /*
 779                                  * Skip comments.
 780                                  */
 781                                 kobj_find_eol(file);
 782                                 break;
 783                         case NEWLINE:
 784                                 kobj_newline(file);
 785                                 last_tok = NEWLINE;
 786                                 break;
 787                         case NAME:
 788                                 if (last_tok != NEWLINE) {
 789                                         kobj_file_err(CE_WARN, file,
 790                                             extra_err, tokval);
 791                                         kobj_find_eol(file);
 792                                 } else if ((sp = do_sysfile_cmd(file,
 793                                     tokval)) != NULL) {
 794                                         sp->sys_next = NULL;
 795                                         sysparam_tl->sys_next = sp;
 796                                         sysparam_tl = sp;
 797                                 }
 798                                 last_tok = NAME;
 799                                 break;
 800                         default:
 801                                 kobj_file_err(CE_WARN,
 802                                     file, tok_err, tokval);
 803                                 kobj_find_eol(file);
 804                                 break;
 805                         }
 806                 }
 807                 kobj_close_file(file);
 808         }
 809 }
 810 
 811 void
 812 mod_read_system_file(int ask)
 813 {
 814         mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
 815             segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
 816 
 817         if (ask)
 818                 mod_askparams();
 819 
 820         /*
 821          * Read the user self-assembly file first
 822          * to preserve existing system settings.
 823          */
 824         if (self_assembly != NULL)
 825                 read_system_file(self_assembly);
 826 
 827         if (systemfile != NULL)
 828                 read_system_file(systemfile);
 829 
 830         /*
 831          * Sanity check of /etc/system.
 832          */
 833         check_system_file();
 834 
 835         param_preset();
 836         (void) mod_sysctl(SYS_SET_KVAR, NULL);
 837         param_check();
 838 
 839         if (ask == 0)
 840                 setparams();
 841 }
 842 
 843 /*
 844  * Search for a specific module variable assignment in /etc/system.  If
 845  * successful, 1 is returned and the value is stored in '*value'.
 846  * Otherwise 0 is returned and '*value' isn't modified.  If 'module' is
 847  * NULL we look for global definitions.
 848  *
 849  * This is useful if the value of an assignment is needed before a
 850  * module is loaded (e.g. to obtain a default privileged rctl limit).