Print this page
2249 libbrand suppresses libxml2 errors
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Eric Shrock <eric.schrock@delphix.com>
Reviewed by: Milan Jurik <milan.jurik@xylab.cz>


   4  * The contents of this file are subject to the terms of the
   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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 #include <assert.h>
  27 #include <dirent.h>
  28 #include <errno.h>
  29 #include <fnmatch.h>
  30 #include <signal.h>
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 #include <strings.h>
  34 #include <synch.h>
  35 #include <sys/brand.h>
  36 #include <sys/fcntl.h>
  37 #include <sys/param.h>
  38 #include <sys/stat.h>
  39 #include <sys/systeminfo.h>
  40 #include <sys/types.h>
  41 #include <thread.h>
  42 #include <zone.h>
  43 


  85 #define DTD_ATTR_IPTYPE         ((const xmlChar *) "ip-type")
  86 #define DTD_ATTR_MATCH          ((const xmlChar *) "match")
  87 #define DTD_ATTR_MODE           ((const xmlChar *) "mode")
  88 #define DTD_ATTR_NAME           ((const xmlChar *) "name")
  89 #define DTD_ATTR_OPT            ((const xmlChar *) "opt")
  90 #define DTD_ATTR_PATH           ((const xmlChar *) "path")
  91 #define DTD_ATTR_SET            ((const xmlChar *) "set")
  92 #define DTD_ATTR_SOURCE         ((const xmlChar *) "source")
  93 #define DTD_ATTR_SPECIAL        ((const xmlChar *) "special")
  94 #define DTD_ATTR_TARGET         ((const xmlChar *) "target")
  95 #define DTD_ATTR_TYPE           ((const xmlChar *) "type")
  96 
  97 #define DTD_ENTITY_TRUE         "true"
  98 
  99 static volatile boolean_t       libbrand_initialized = B_FALSE;
 100 static char                     i_curr_arch[MAXNAMELEN];
 101 static char                     i_curr_zone[ZONENAME_MAX];
 102 
 103 /*ARGSUSED*/
 104 static void
 105 brand_error_func(void *ctx, const char *msg, ...)
 106 {
 107         /*
 108          * Ignore error messages from libxml
 109          */
 110 }
 111 











 112 static boolean_t
 113 libbrand_initialize()
 114 {
 115         static mutex_t initialize_lock = DEFAULTMUTEX;
 116 
 117         (void) mutex_lock(&initialize_lock);
 118 
 119         if (libbrand_initialized) {
 120                 (void) mutex_unlock(&initialize_lock);
 121                 return (B_TRUE);
 122         }
 123 
 124         if (sysinfo(SI_ARCHITECTURE, i_curr_arch, sizeof (i_curr_arch)) < 0) {
 125                 (void) mutex_unlock(&initialize_lock);
 126                 return (B_FALSE);
 127         }
 128 
 129         if (getzonenamebyid(getzoneid(), i_curr_zone,
 130             sizeof (i_curr_zone)) < 0) {
 131                 (void) mutex_unlock(&initialize_lock);


 185         xmlValidCtxtPtr cvp;
 186         int valid;
 187 
 188         if (!libbrand_initialize())
 189                 return (NULL);
 190 
 191         /*
 192          * Parse the file
 193          */
 194         if ((doc = xmlParseFile(file)) == NULL)
 195                 return (NULL);
 196 
 197         /*
 198          * Validate the file
 199          */
 200         if ((cvp = xmlNewValidCtxt()) == NULL) {
 201                 xmlFreeDoc(doc);
 202                 return (NULL);
 203         }
 204         cvp->error = brand_error_func;
 205         cvp->warning = brand_error_func;
 206         valid = xmlValidateDocument(cvp, doc);
 207         xmlFreeValidCtxt(cvp);
 208         if (valid == 0) {
 209                 xmlFreeDoc(doc);
 210                 return (NULL);
 211         }
 212 
 213         return (doc);
 214 }
 215 /*
 216  * Open a handle to the named brand.
 217  *
 218  * Returns a handle to the named brand, which is used for all subsequent brand
 219  * interaction, or NULL if unable to open or initialize the brand.
 220  */
 221 brand_handle_t
 222 brand_open(const char *name)
 223 {
 224         struct brand_handle *bhp;
 225         char path[MAXPATHLEN];




   4  * The contents of this file are subject to the terms of the
   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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 #include <assert.h>
  28 #include <dirent.h>
  29 #include <errno.h>
  30 #include <fnmatch.h>
  31 #include <signal.h>
  32 #include <stdlib.h>
  33 #include <unistd.h>
  34 #include <strings.h>
  35 #include <synch.h>
  36 #include <sys/brand.h>
  37 #include <sys/fcntl.h>
  38 #include <sys/param.h>
  39 #include <sys/stat.h>
  40 #include <sys/systeminfo.h>
  41 #include <sys/types.h>
  42 #include <thread.h>
  43 #include <zone.h>
  44 


  86 #define DTD_ATTR_IPTYPE         ((const xmlChar *) "ip-type")
  87 #define DTD_ATTR_MATCH          ((const xmlChar *) "match")
  88 #define DTD_ATTR_MODE           ((const xmlChar *) "mode")
  89 #define DTD_ATTR_NAME           ((const xmlChar *) "name")
  90 #define DTD_ATTR_OPT            ((const xmlChar *) "opt")
  91 #define DTD_ATTR_PATH           ((const xmlChar *) "path")
  92 #define DTD_ATTR_SET            ((const xmlChar *) "set")
  93 #define DTD_ATTR_SOURCE         ((const xmlChar *) "source")
  94 #define DTD_ATTR_SPECIAL        ((const xmlChar *) "special")
  95 #define DTD_ATTR_TARGET         ((const xmlChar *) "target")
  96 #define DTD_ATTR_TYPE           ((const xmlChar *) "type")
  97 
  98 #define DTD_ENTITY_TRUE         "true"
  99 
 100 static volatile boolean_t       libbrand_initialized = B_FALSE;
 101 static char                     i_curr_arch[MAXNAMELEN];
 102 static char                     i_curr_zone[ZONENAME_MAX];
 103 
 104 /*ARGSUSED*/
 105 static void
 106 brand_warning_func(void *ctx, const char *msg, ...)
 107 {
 108         /*
 109          * Ignore warning messages from libxml
 110          */
 111 }
 112 
 113 /*ARGSUSED*/
 114 static void
 115 brand_error_func(void *ctx, const char *msg, ...)
 116 {
 117         va_list args;
 118 
 119         va_start(args, msg);
 120         (void) vfprintf(stderr, msg, args);
 121         va_end(args);
 122 }
 123 
 124 static boolean_t
 125 libbrand_initialize()
 126 {
 127         static mutex_t initialize_lock = DEFAULTMUTEX;
 128 
 129         (void) mutex_lock(&initialize_lock);
 130 
 131         if (libbrand_initialized) {
 132                 (void) mutex_unlock(&initialize_lock);
 133                 return (B_TRUE);
 134         }
 135 
 136         if (sysinfo(SI_ARCHITECTURE, i_curr_arch, sizeof (i_curr_arch)) < 0) {
 137                 (void) mutex_unlock(&initialize_lock);
 138                 return (B_FALSE);
 139         }
 140 
 141         if (getzonenamebyid(getzoneid(), i_curr_zone,
 142             sizeof (i_curr_zone)) < 0) {
 143                 (void) mutex_unlock(&initialize_lock);


 197         xmlValidCtxtPtr cvp;
 198         int valid;
 199 
 200         if (!libbrand_initialize())
 201                 return (NULL);
 202 
 203         /*
 204          * Parse the file
 205          */
 206         if ((doc = xmlParseFile(file)) == NULL)
 207                 return (NULL);
 208 
 209         /*
 210          * Validate the file
 211          */
 212         if ((cvp = xmlNewValidCtxt()) == NULL) {
 213                 xmlFreeDoc(doc);
 214                 return (NULL);
 215         }
 216         cvp->error = brand_error_func;
 217         cvp->warning = brand_warning_func;
 218         valid = xmlValidateDocument(cvp, doc);
 219         xmlFreeValidCtxt(cvp);
 220         if (valid == 0) {
 221                 xmlFreeDoc(doc);
 222                 return (NULL);
 223         }
 224 
 225         return (doc);
 226 }
 227 /*
 228  * Open a handle to the named brand.
 229  *
 230  * Returns a handle to the named brand, which is used for all subsequent brand
 231  * interaction, or NULL if unable to open or initialize the brand.
 232  */
 233 brand_handle_t
 234 brand_open(const char *name)
 235 {
 236         struct brand_handle *bhp;
 237         char path[MAXPATHLEN];