xref: /titanic_44/usr/src/cmd/picl/plugins/common/frutree/piclfrutree.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * This plugin creates the PICL nodes and properties specified in
31*7c478bd9Sstevel@tonic-gate  * configuration file.
32*7c478bd9Sstevel@tonic-gate  * It is used to create the FRU tree for a platform.
33*7c478bd9Sstevel@tonic-gate  * The configuration file for FRU tree is called "piclfrutree.conf".
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <stdio.h>
38*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
39*7c478bd9Sstevel@tonic-gate #include <unistd.h>
40*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
41*7c478bd9Sstevel@tonic-gate #include <errno.h>
42*7c478bd9Sstevel@tonic-gate #include <string.h>
43*7c478bd9Sstevel@tonic-gate #include <syslog.h>
44*7c478bd9Sstevel@tonic-gate #include <alloca.h>
45*7c478bd9Sstevel@tonic-gate #include <limits.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
49*7c478bd9Sstevel@tonic-gate #include <libintl.h>
50*7c478bd9Sstevel@tonic-gate #include <picl.h>
51*7c478bd9Sstevel@tonic-gate #include <picltree.h>
52*7c478bd9Sstevel@tonic-gate #include "picld_pluginutil.h"
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #define	EM_FAIL	gettext("SUNW_piclfrutree PICL plugin module failed")
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate static	void	piclfrutree_register(void);
57*7c478bd9Sstevel@tonic-gate static	void	piclfrutree_init(void);
58*7c478bd9Sstevel@tonic-gate static	void	piclfrutree_fini(void);
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate #define	FRUTREE_CONFFILE_NAME		"piclfrutree.conf"
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate #pragma	init(piclfrutree_register)
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate static picld_plugin_reg_t  my_reg_info = {
65*7c478bd9Sstevel@tonic-gate 	PICLD_PLUGIN_VERSION_1,
66*7c478bd9Sstevel@tonic-gate 	PICLD_PLUGIN_NON_CRITICAL,
67*7c478bd9Sstevel@tonic-gate 	"SUNW_piclfrutree",
68*7c478bd9Sstevel@tonic-gate 	piclfrutree_init,
69*7c478bd9Sstevel@tonic-gate 	piclfrutree_fini
70*7c478bd9Sstevel@tonic-gate };
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate static void
piclfrutree_register(void)73*7c478bd9Sstevel@tonic-gate piclfrutree_register(void)
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate 	(void) picld_plugin_register(&my_reg_info);
76*7c478bd9Sstevel@tonic-gate }
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate /*
79*7c478bd9Sstevel@tonic-gate  * Search for the frutree config file from the platform specific
80*7c478bd9Sstevel@tonic-gate  * directory to the common directory.
81*7c478bd9Sstevel@tonic-gate  *
82*7c478bd9Sstevel@tonic-gate  * The size of outfilename must be PATH_MAX
83*7c478bd9Sstevel@tonic-gate  */
84*7c478bd9Sstevel@tonic-gate static int
get_config_file(char * outfilename)85*7c478bd9Sstevel@tonic-gate get_config_file(char *outfilename)
86*7c478bd9Sstevel@tonic-gate {
87*7c478bd9Sstevel@tonic-gate 	char	nmbuf[SYS_NMLN];
88*7c478bd9Sstevel@tonic-gate 	char	pname[PATH_MAX];
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_PLATFORM, nmbuf, sizeof (nmbuf)) != -1) {
91*7c478bd9Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
92*7c478bd9Sstevel@tonic-gate 		(void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
93*7c478bd9Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
94*7c478bd9Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
95*7c478bd9Sstevel@tonic-gate 			return (0);
96*7c478bd9Sstevel@tonic-gate 		}
97*7c478bd9Sstevel@tonic-gate 	}
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	if (sysinfo(SI_MACHINE, nmbuf, sizeof (nmbuf)) != -1) {
100*7c478bd9Sstevel@tonic-gate 		(void) snprintf(pname, PATH_MAX, PICLD_PLAT_PLUGIN_DIRF, nmbuf);
101*7c478bd9Sstevel@tonic-gate 		(void) strlcat(pname, FRUTREE_CONFFILE_NAME, PATH_MAX);
102*7c478bd9Sstevel@tonic-gate 		if (access(pname, R_OK) == 0) {
103*7c478bd9Sstevel@tonic-gate 			(void) strlcpy(outfilename, pname, PATH_MAX);
104*7c478bd9Sstevel@tonic-gate 			return (0);
105*7c478bd9Sstevel@tonic-gate 		}
106*7c478bd9Sstevel@tonic-gate 	}
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	(void) snprintf(pname, PATH_MAX, "%s/%s", PICLD_COMMON_PLUGIN_DIR,
109*7c478bd9Sstevel@tonic-gate 	    FRUTREE_CONFFILE_NAME);
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	if (access(pname, R_OK) == 0) {
112*7c478bd9Sstevel@tonic-gate 		(void) strlcpy(outfilename, pname, PATH_MAX);
113*7c478bd9Sstevel@tonic-gate 		return (0);
114*7c478bd9Sstevel@tonic-gate 	}
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	return (-1);
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate static void
piclfrutree_init(void)120*7c478bd9Sstevel@tonic-gate piclfrutree_init(void)
121*7c478bd9Sstevel@tonic-gate {
122*7c478bd9Sstevel@tonic-gate 	char		fullfilename[PATH_MAX];
123*7c478bd9Sstevel@tonic-gate 	picl_nodehdl_t	rooth;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (get_config_file(fullfilename) < 0)
126*7c478bd9Sstevel@tonic-gate 		return;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (ptree_get_root(&rooth) != PICL_SUCCESS)
129*7c478bd9Sstevel@tonic-gate 		return;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	if (picld_pluginutil_parse_config_file(rooth, fullfilename) !=
132*7c478bd9Sstevel@tonic-gate 	    PICL_SUCCESS)
133*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, EM_FAIL);
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate static void
piclfrutree_fini(void)137*7c478bd9Sstevel@tonic-gate piclfrutree_fini(void)
138*7c478bd9Sstevel@tonic-gate {
139*7c478bd9Sstevel@tonic-gate }
140