17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22*a38ee582SMarcel Telka
23*a38ee582SMarcel Telka /*
24*a38ee582SMarcel Telka * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
25*a38ee582SMarcel Telka */
26*a38ee582SMarcel Telka
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * Copyright (c) 1998 by Sun Microsystems, Inc.
297c478bd9Sstevel@tonic-gate * All rights reserved.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <locale.h>
387c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
417c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate static char *cmdname;
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate static void errmsg(char *);
477c478bd9Sstevel@tonic-gate static void usage();
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)507c478bd9Sstevel@tonic-gate main(int argc, char **argv)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate int c, bootflags;
537c478bd9Sstevel@tonic-gate nodeid_t nid, hid;
547c478bd9Sstevel@tonic-gate char *cp = "";
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
577c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate cmdname = argv[0]; /* put actual command name in messages */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
627c478bd9Sstevel@tonic-gate errmsg("_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG)");
637c478bd9Sstevel@tonic-gate return (1);
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "bnh")) != EOF) {
677c478bd9Sstevel@tonic-gate switch (c) {
687c478bd9Sstevel@tonic-gate case 'b': /* print boot flags */
697c478bd9Sstevel@tonic-gate (void) printf("%s%u\n", cp, bootflags);
707c478bd9Sstevel@tonic-gate break;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate case 'n': /* print our node number */
737c478bd9Sstevel@tonic-gate if (_cladm(CL_CONFIG, CL_NODEID, &nid) != 0) {
74*a38ee582SMarcel Telka errmsg("node is not configured as part of a "
75*a38ee582SMarcel Telka "cluster");
767c478bd9Sstevel@tonic-gate return (1);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate (void) printf("%s%u\n", cp, nid);
797c478bd9Sstevel@tonic-gate break;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate case 'h': /* print the highest node number */
827c478bd9Sstevel@tonic-gate if (_cladm(CL_CONFIG, CL_HIGHEST_NODEID, &hid) != 0) {
837c478bd9Sstevel@tonic-gate errmsg("node is not booted as part of a "
84*a38ee582SMarcel Telka "cluster");
857c478bd9Sstevel@tonic-gate return (1);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate (void) printf("%s%u\n", cp, hid);
887c478bd9Sstevel@tonic-gate break;
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate default:
917c478bd9Sstevel@tonic-gate usage();
927c478bd9Sstevel@tonic-gate return (1);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate cp = " ";
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * Return exit status of one (error) if not booted as a cluster.
997c478bd9Sstevel@tonic-gate */
1007c478bd9Sstevel@tonic-gate return (bootflags & CLUSTER_BOOTED ? 0 : 1);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate static void
errmsg(char * msg)1047c478bd9Sstevel@tonic-gate errmsg(char *msg)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate int save_error;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate save_error = errno; /* in case fprintf changes errno */
1097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", cmdname);
1107c478bd9Sstevel@tonic-gate errno = save_error;
1117c478bd9Sstevel@tonic-gate perror(msg);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate static void
usage()1157c478bd9Sstevel@tonic-gate usage()
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s -[bnh]\n", gettext("usage"), cmdname);
1187c478bd9Sstevel@tonic-gate }
119