cmd: remove locator
[unleashed.git] / usr / src / cmd / picl / plugins / common / frutree / piclfrutree.c
blob4ddef5ae8c32c120c39e72075bb5814cddb24fee
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This plugin creates the PICL nodes and properties specified in
31 * configuration file.
32 * It is used to create the FRU tree for a platform.
33 * The configuration file for FRU tree is called "piclfrutree.conf".
37 #include <stdio.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 #include <string.h>
43 #include <syslog.h>
44 #include <alloca.h>
45 #include <limits.h>
46 #include <sys/utsname.h>
47 #include <sys/systeminfo.h>
48 #include <sys/stat.h>
49 #include <libintl.h>
50 #include <picl.h>
51 #include <picltree.h>
52 #include "picld_pluginutil.h"
54 #define EM_FAIL gettext("SUNW_piclfrutree PICL plugin module failed")
56 static void piclfrutree_register(void);
57 static void piclfrutree_init(void);
58 static void piclfrutree_fini(void);
60 #define FRUTREE_CONFFILE_NAME "piclfrutree.conf"
62 #pragma init(piclfrutree_register)
64 static picld_plugin_reg_t my_reg_info = {
65 PICLD_PLUGIN_VERSION_1,
66 PICLD_PLUGIN_NON_CRITICAL,
67 "SUNW_piclfrutree",
68 piclfrutree_init,
69 piclfrutree_fini
72 static void
73 piclfrutree_register(void)
75 (void) picld_plugin_register(&my_reg_info);
79 * Search for the frutree config file from the platform specific
80 * directory to the common directory.
82 * The size of outfilename must be PATH_MAX
84 static int
85 get_config_file(char *outfilename)
87 char pname[PATH_MAX];
89 (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_PLAT_PLUGIN_DIR,
90 FRUTREE_CONFFILE_NAME);
92 if (access(pname, R_OK) == 0) {
93 (void) strlcpy(outfilename, pname, PATH_MAX);
94 return (0);
97 (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
98 FRUTREE_CONFFILE_NAME);
100 if (access(pname, R_OK) == 0) {
101 (void) strlcpy(outfilename, pname, PATH_MAX);
102 return (0);
105 return (-1);
108 static void
109 piclfrutree_init(void)
111 char fullfilename[PATH_MAX];
112 picl_nodehdl_t rooth;
114 if (get_config_file(fullfilename) < 0)
115 return;
117 if (ptree_get_root(&rooth) != PICL_SUCCESS)
118 return;
120 if (picld_pluginutil_parse_config_file(rooth, fullfilename) !=
121 PICL_SUCCESS)
122 syslog(LOG_ERR, EM_FAIL);
125 static void
126 piclfrutree_fini(void)