xref: /titanic_41/usr/src/cmd/clinfo/clinfo.c (revision eb0cc229f19c437a6b538d3ac0d0443268290b7e)
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) 1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <locale.h>
35 #include <sys/cladm.h>
36 
37 #if !defined(TEXT_DOMAIN)		/* should be defined by cc -D */
38 #define	TEXT_DOMAIN 	"SYS_TEST"	/* Use this only if it wasn't */
39 #endif
40 
41 static char *cmdname;
42 
43 static void errmsg(char *);
44 static void usage();
45 
46 int
47 main(int argc, char **argv)
48 {
49 	int c, bootflags;
50 	nodeid_t nid, hid;
51 	char *cp = "";
52 
53 	(void) setlocale(LC_ALL, "");
54 	(void) textdomain(TEXT_DOMAIN);
55 
56 	cmdname = argv[0];	/* put actual command name in messages */
57 
58 	if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
59 		errmsg("_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG)");
60 		return (1);
61 	}
62 
63 	while ((c = getopt(argc, argv, "bnh")) != EOF) {
64 		switch (c) {
65 		case 'b':	/* print boot flags */
66 			(void) printf("%s%u\n", cp, bootflags);
67 			break;
68 
69 		case 'n':	/* print our node number */
70 			if (_cladm(CL_CONFIG, CL_NODEID, &nid) != 0) {
71 				errmsg("node is not configured as part of a"
72 				"cluster");
73 				return (1);
74 			}
75 			(void) printf("%s%u\n", cp, nid);
76 			break;
77 
78 		case 'h':	/* print the highest node number */
79 			if (_cladm(CL_CONFIG, CL_HIGHEST_NODEID, &hid) != 0) {
80 				errmsg("node is not booted as part of a "
81 				"cluster");
82 				return (1);
83 			}
84 			(void) printf("%s%u\n", cp, hid);
85 			break;
86 
87 		default:
88 			usage();
89 			return (1);
90 		}
91 		cp = " ";
92 	}
93 
94 	/*
95 	 * Return exit status of one (error) if not booted as a cluster.
96 	 */
97 	return (bootflags & CLUSTER_BOOTED ? 0 : 1);
98 }
99 
100 static void
101 errmsg(char *msg)
102 {
103 	int save_error;
104 
105 	save_error = errno;		/* in case fprintf changes errno */
106 	(void) fprintf(stderr, "%s: ", cmdname);
107 	errno = save_error;
108 	perror(msg);
109 }
110 
111 static void
112 usage()
113 {
114 	(void) fprintf(stderr, "%s: %s -[bnh]\n", gettext("usage"), cmdname);
115 }
116