xref: /illumos-gate/usr/src/cmd/fm/fmadm/common/config.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <fmadm.h>
28 
29 /*ARGSUSED*/
30 static int
config_modinfo(const fmd_adm_modinfo_t * ami,void * unused)31 config_modinfo(const fmd_adm_modinfo_t *ami, void *unused)
32 {
33 	const char *state;
34 
35 	if (ami->ami_flags & FMD_ADM_MOD_FAILED)
36 		state = "failed";
37 	else
38 		state = "active";
39 
40 	(void) printf("%-24s %-7s %-6s  %s\n",
41 	    ami->ami_name, ami->ami_vers, state, ami->ami_desc);
42 
43 	return (0);
44 }
45 
46 /*ARGSUSED*/
47 int
cmd_config(fmd_adm_t * adm,int argc,char * argv[])48 cmd_config(fmd_adm_t *adm, int argc, char *argv[])
49 {
50 	if (argc != 1)
51 		return (FMADM_EXIT_USAGE);
52 
53 	(void) printf("%-24s %-7s %-6s  %s\n",
54 	    "MODULE", "VERSION", "STATUS", "DESCRIPTION");
55 
56 	if (fmd_adm_module_iter(adm, config_modinfo, NULL) != 0)
57 		die("failed to retrieve configuration");
58 
59 	return (FMADM_EXIT_SUCCESS);
60 }
61 
62 int
cmd_rotate(fmd_adm_t * adm,int argc,char * argv[])63 cmd_rotate(fmd_adm_t *adm, int argc, char *argv[])
64 {
65 	if (argc != 2)
66 		return (FMADM_EXIT_USAGE);
67 
68 	if (fmd_adm_log_rotate(adm, argv[1]) != 0)
69 		die("failed to rotate %s", argv[1]);
70 
71 	note("%s has been rotated out and can now be archived\n", argv[1]);
72 	return (FMADM_EXIT_SUCCESS);
73 }
74