8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / clinfo / clinfo.c
blobc806ad99f7ad74ab37d470f39fa4b101fd2bdb61
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
24 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 1998 by Sun Microsystems, Inc.
29 * All rights reserved.
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <locale.h>
38 #include <sys/cladm.h>
40 #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
41 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
42 #endif
44 static char *cmdname;
46 static void errmsg(char *);
47 static void usage();
49 int
50 main(int argc, char **argv)
52 int c, bootflags;
53 nodeid_t nid, hid;
54 char *cp = "";
56 (void) setlocale(LC_ALL, "");
57 (void) textdomain(TEXT_DOMAIN);
59 cmdname = argv[0]; /* put actual command name in messages */
61 if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
62 errmsg("_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG)");
63 return (1);
66 while ((c = getopt(argc, argv, "bnh")) != EOF) {
67 switch (c) {
68 case 'b': /* print boot flags */
69 (void) printf("%s%u\n", cp, bootflags);
70 break;
72 case 'n': /* print our node number */
73 if (_cladm(CL_CONFIG, CL_NODEID, &nid) != 0) {
74 errmsg("node is not configured as part of a "
75 "cluster");
76 return (1);
78 (void) printf("%s%u\n", cp, nid);
79 break;
81 case 'h': /* print the highest node number */
82 if (_cladm(CL_CONFIG, CL_HIGHEST_NODEID, &hid) != 0) {
83 errmsg("node is not booted as part of a "
84 "cluster");
85 return (1);
87 (void) printf("%s%u\n", cp, hid);
88 break;
90 default:
91 usage();
92 return (1);
94 cp = " ";
98 * Return exit status of one (error) if not booted as a cluster.
100 return (bootflags & CLUSTER_BOOTED ? 0 : 1);
103 static void
104 errmsg(char *msg)
106 int save_error;
108 save_error = errno; /* in case fprintf changes errno */
109 (void) fprintf(stderr, "%s: ", cmdname);
110 errno = save_error;
111 perror(msg);
114 static void
115 usage()
117 (void) fprintf(stderr, "%s: %s -[bnh]\n", gettext("usage"), cmdname);