Fix build error.
[openais.git] / test / openais-cfgtool.c
blob9a7d11531d0fa35ab17a37f4d1664fbb32afad23
1 /*
2 * Copyright (c) 2006-2007 Red Hat, Inc.
4 * All rights reserved.
6 * Author: Steven Dake <sdake@redhat.com>
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <errno.h>
38 #include <signal.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <sys/select.h>
44 #include <sys/un.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
48 #include "saAis.h"
49 #include "cfg.h"
51 static void ringstatusget_do (void)
53 SaAisErrorT result;
54 openais_cfg_handle_t handle;
55 unsigned int interface_count;
56 char **interface_names;
57 char **interface_status;
58 unsigned int i;
60 printf ("Printing ring status.\n");
61 result = openais_cfg_initialize (&handle, NULL);
62 if (result != SA_AIS_OK) {
63 printf ("Could not initialize openais configuration API error %d\n", result);
64 exit (1);
67 openais_cfg_ring_status_get (handle,
68 &interface_names,
69 &interface_status,
70 &interface_count);
72 for (i = 0; i < interface_count; i++) {
73 printf ("RING ID %d\n", i);
74 printf ("\tid\t= %s\n", interface_names[i]);
75 printf ("\tstatus\t= %s\n", interface_status[i]);
78 openais_cfg_finalize (handle);
81 static void ringreenable_do (void)
83 SaAisErrorT result;
84 openais_cfg_handle_t handle;
86 printf ("Re-enabling all failed rings.\n");
87 result = openais_cfg_initialize (&handle, NULL);
88 if (result != SA_AIS_OK) {
89 printf ("Could not initialize openais configuration API error %d\n", result);
90 exit (1);
93 result = openais_cfg_ring_reenable (handle);
94 if (result != SA_AIS_OK) {
95 printf ("Could not reenable ring error %d\n", result);
98 openais_cfg_finalize (handle);
101 void service_load_do (char *service, unsigned int version)
103 SaAisErrorT result;
104 openais_cfg_handle_t handle;
106 printf ("Loading service '%s' version '%d'\n", service, version);
107 result = openais_cfg_initialize (&handle, NULL);
108 if (result != SA_AIS_OK) {
109 printf ("Could not initialize openais configuration API error %d\n", result);
110 exit (1);
112 result = openais_cfg_service_load (handle, service, version);
113 if (result != SA_AIS_OK) {
114 printf ("Could not load service (error = %d)\n", result);
116 openais_cfg_finalize (handle);
119 void service_unload_do (char *service, unsigned int version)
121 SaAisErrorT result;
122 openais_cfg_handle_t handle;
124 printf ("Unloading service '%s' version '%d'\n", service, version);
125 result = openais_cfg_initialize (&handle, NULL);
126 if (result != SA_AIS_OK) {
127 printf ("Could not initialize openais configuration API error %d\n", result);
128 exit (1);
130 result = openais_cfg_service_unload (handle, service, version);
131 if (result != SA_AIS_OK) {
132 printf ("Could not unload service (error = %d)\n", result);
134 openais_cfg_finalize (handle);
137 void usage_do (void)
139 printf ("openais-cfgtool [-s] [-r] [-l] [-u] [service_name] [-v] [version]\n\n");
140 printf ("A tool for displaying and configuring active parameters within openais.\n");
141 printf ("options:\n");
142 printf ("\t-s\tDisplays the status of the current rings on this node.\n");
143 printf ("\t-r\tReset redundant ring state cluster wide after a fault to\n");
144 printf ("\t\tre-enable redundant ring operation.\n");
145 printf ("\t-l\tLoad a service identified by name.\n");
146 printf ("\t-u\tUnload a service identified by name.\n");
149 int main (int argc, char *argv[]) {
150 const char *options = "srl:u:v:";
151 int opt;
152 int service_load = 0;
153 int service_unload = 0;
154 char *service;
155 unsigned int version;
157 if (argc == 1) {
158 usage_do ();
160 while ( (opt = getopt(argc, argv, options)) != -1 ) {
161 switch (opt) {
162 case 's':
163 ringstatusget_do ();
164 break;
165 case 'r':
166 ringreenable_do ();
167 break;
168 case 'l':
169 service_load = 1;
170 service = strdup (optarg);
171 break;
172 case 'u':
173 service_unload = 1;
174 service = strdup (optarg);
175 break;
176 case 'v':
177 version = atoi (optarg);
181 if (service_load) {
182 service_load_do (service, version);
183 } else
184 if (service_unload) {
185 service_unload_do (service, version);
188 return (0);