xref: /titanic_50/usr/src/cmd/ldmad/ldma_system.c (revision 5829b1c983804e9f5553f65d47f088a97a89700b)
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 (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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Logical Domains System Agent
29  */
30 
31 #include <errno.h>
32 #include <libds.h>
33 #include <stdio.h>
34 #include <strings.h>
35 #include <sys/utsname.h>
36 
37 #include "ldma.h"
38 
39 #define	LDMA_MODULE	LDMA_NAME_SYSTEM
40 
41 #define	LDMA_NVERSIONS	(sizeof (ldma_versions) / sizeof (ds_ver_t))
42 #define	LDMA_NHANDLERS	(sizeof (ldma_handlers) / sizeof (ldma_msg_handler_t))
43 
44 static ldm_msg_func_t ldma_sys_get_sysinfo;
45 
46 static ds_ver_t ldma_versions[] = { { 1, 0 } };
47 
48 static ldma_msg_handler_t ldma_handlers[] = {
49 	{ LDMA_MSGSYS_GET_SYSINFO, ldma_sys_get_sysinfo }
50 };
51 
52 ldma_agent_info_t ldma_system_info = {
53 	LDMA_NAME_SYSTEM,
54 	ldma_versions, LDMA_NVERSIONS,
55 	ldma_handlers, LDMA_NHANDLERS
56 };
57 
58 /*ARGSUSED*/
59 static ldma_request_status_t
60 ldma_sys_get_sysinfo(ds_ver_t *ver, ldma_message_header_t *request,
61     size_t request_dlen, ldma_message_header_t **replyp, size_t *reply_dlenp)
62 {
63 	ldma_message_header_t *reply;
64 	struct utsname name;
65 	size_t syslen, nodlen, rellen, maclen, verlen;
66 	size_t rlen;
67 	char *data;
68 	int status;
69 
70 	LDMA_DBG("GET_SYSINFO");
71 
72 	if (request->msg_info != 0 || request_dlen != 0) {
73 		status = LDMA_REQ_INVALID;
74 		goto done;
75 	}
76 
77 	if (uname(&name) == -1) {
78 		LDMA_DBG("GET_SYSINFO: uname failed with error %d", errno);
79 		status = LDMA_REQ_FAILED;
80 		goto done;
81 	}
82 
83 	syslen = strlen(name.sysname) + 1;
84 	nodlen = strlen(name.nodename) + 1;
85 	rellen = strlen(name.release) + 1;
86 	verlen = strlen(name.version) + 1;
87 	maclen = strlen(name.machine) + 1;
88 
89 	rlen = syslen + nodlen + rellen + verlen + maclen;
90 
91 	reply = ldma_alloc_result_msg(request, rlen);
92 
93 	if (reply == NULL) {
94 		status = LDMA_REQ_FAILED;
95 		goto done;
96 	}
97 
98 	reply->msg_info = rlen;
99 
100 	data = LDMA_HDR2DATA(reply);
101 
102 	(void) strcpy(data, name.sysname);
103 	data += syslen;
104 
105 	(void) strcpy(data, name.nodename);
106 	data += nodlen;
107 
108 	(void) strcpy(data, name.release);
109 	data += rellen;
110 
111 	(void) strcpy(data, name.version);
112 	data += verlen;
113 
114 	(void) strcpy(data, name.machine);
115 
116 	LDMA_DBG("GET_SYSINFO: return info=%u, {%s, %s, %s, %s, %s}", rlen,
117 	    name.sysname, name.nodename, name.release, name.version,
118 	    name.machine);
119 
120 	*replyp = reply;
121 	*reply_dlenp = rlen;
122 
123 	return (LDMA_REQ_COMPLETED);
124 
125 done:
126 	LDMA_DBG("GET_SYSINFO: return error %d", status);
127 	return (status);
128 }
129