1 /*
2 * CDDL HEADER START
3 *
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.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /*
28 * This plugin creates the PICL nodes and properties specified in
29 * configuration file.
30 * It is used to create the FRU tree for a platform.
31 * The configuration file for FRU tree is called "piclfrutree.conf".
32 */
33
34
35 #include <stdio.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <errno.h>
40 #include <string.h>
41 #include <syslog.h>
42 #include <alloca.h>
43 #include <limits.h>
44 #include <sys/utsname.h>
45 #include <sys/systeminfo.h>
46 #include <sys/stat.h>
47 #include <libintl.h>
48 #include <picl.h>
49 #include <picltree.h>
50 #include "picld_pluginutil.h"
51
52 #define EM_FAIL gettext("SUNW_piclfrutree PICL plugin module failed")
53
54 static void piclfrutree_register(void);
55 static void piclfrutree_init(void);
56 static void piclfrutree_fini(void);
57
58 #define FRUTREE_CONFFILE_NAME "piclfrutree.conf"
59
60 #pragma init(piclfrutree_register)
61
62 static picld_plugin_reg_t my_reg_info = {
63 PICLD_PLUGIN_VERSION_1,
64 PICLD_PLUGIN_NON_CRITICAL,
65 "SUNW_piclfrutree",
66 piclfrutree_init,
67 piclfrutree_fini
68 };
69
70 static void
piclfrutree_register(void)71 piclfrutree_register(void)
72 {
73 (void) picld_plugin_register(&my_reg_info);
74 }
75
76 /*
77 * Search for the frutree config file from the platform specific
78 * directory to the common directory.
79 *
80 * The size of outfilename must be PATH_MAX
81 */
82 static int
get_config_file(char * outfilename)83 get_config_file(char *outfilename)
84 {
85 char nmbuf[SYS_NMLN];
86 char pname[PATH_MAX];
87
88 if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
89 (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
90 (void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
91 if (access(pname, R_OK) == 0) {
92 (void) strlcpy(outfilename, pname, PATH_MAX);
93 return (0);
94 }
95 }
96
97 if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
98 (void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
99 (void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
100 if (access(pname, R_OK) == 0) {
101 (void) strlcpy(outfilename, pname, PATH_MAX);
102 return (0);
103 }
104 }
105
106 (void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
107 FRUTREE_CONFFILE_NAME);
108
109 if (access(pname, R_OK) == 0) {
110 (void) strlcpy(outfilename, pname, PATH_MAX);
111 return (0);
112 }
113
114 return (-1);
115 }
116
117 static void
piclfrutree_init(void)118 piclfrutree_init(void)
119 {
120 char fullfilename[PATH_MAX];
121 picl_nodehdl_t rooth;
122
123 if (get_config_file(fullfilename) < 0)
124 return;
125
126 if (ptree_get_root(&rooth) != PICL_SUCCESS)
127 return;
128
129 if (picld_pluginutil_parse_config_file(rooth, fullfilename) !=
130 PICL_SUCCESS)
131 syslog(LOG_ERR, EM_FAIL);
132 }
133
134 static void
piclfrutree_fini(void)135 piclfrutree_fini(void)
136 {
137 }
138