Hi
Here is a cleaned up patch.
Changes since the last patch:
-Removed the corosync.conf change.
-Removed unnecessary changes to the corosync/Makefile.
-I have also moved keygen into the apps directory.
-Renamed openais-cfgtool to corosync-cfgtool.
-Renamed objctl to corosync-objctl.
-Install corosync-cfgtool to sbin
-Angus
---
corosync/Makefile | 7 +-
corosync/apps/Makefile | 67 +++++
corosync/apps/corosync-cfgtool.c | 189 ++++++++++++++
corosync/apps/corosync-objctl.c | 499 ++++++++++++++++++++++++++++++++++++++
corosync/apps/keygen.c | 98 ++++++++
corosync/exec/Makefile | 12 +-
corosync/exec/keygen.c | 98 --------
corosync/man/corosync-objctl.8 | 113 +++++++++
corosync/test/Makefile | 5 +-
corosync/test/openais-cfgtool.c | 189 --------------
10 files changed, 975 insertions(+), 302 deletions(-)
create mode 100644 corosync/apps/Makefile
create mode 100644 corosync/apps/corosync-cfgtool.c
create mode 100644 corosync/apps/corosync-objctl.c
create mode 100644 corosync/apps/keygen.c
delete mode 100644 corosync/exec/keygen.c
create mode 100644 corosync/man/corosync-objctl.8
delete mode 100644 corosync/test/openais-cfgtool.c
diff --git a/corosync/Makefile b/corosync/Makefile
index 61772a9..cbd6843 100644
--- a/corosync/Makefile
+++ b/corosync/Makefile
@@ -63,13 +63,14 @@ ifeq (ia64,$(ARCH))
LIBDIR=$(PREFIX)/lib/corosync
endif
-SUBDIRS:=$(builddir)lcr $(builddir)lib $(builddir)exec $(builddir)test
$(builddir)services
+SUBDIRS:=$(builddir)lcr $(builddir)lib $(builddir)apps $(builddir)exec
$(builddir)test $(builddir)services
sub_make = srcdir=$(srcdir) builddir=$(builddir) subdir=$(1)/ $(MAKE)
-I$(srcdir)$(1) -f $(srcdir)$(1)/Makefile $(2)
all: $(SUBDIRS)
@(cd $(builddir)lcr; echo ==== `pwd` ===; $(call sub_make,lcr,all));
@(cd $(builddir)lib; echo ==== `pwd` ===; $(call sub_make,lib,all));
@(cd $(builddir)exec; echo ==== `pwd` ===; $(call sub_make,exec,all));
+ @(cd $(builddir)apps; echo ==== `pwd` ===; $(call sub_make,apps,all));
@(cd $(builddir)services; echo ==== `pwd` ===; $(call
sub_make,services,all));
@(cd $(builddir)test; echo ==== `pwd` ===; $(call sub_make,test,all));
@@ -108,6 +109,7 @@ help:
clean:
(cd $(builddir)lcr; echo ==== `pwd` ===; $(call sub_make,lcr,clean));
(cd $(builddir)lib; echo ==== `pwd` ===; $(call sub_make,lib,clean));
+ (cd $(builddir)apps; echo ==== `pwd` ===; $(call sub_make,apps,clean));
(cd $(builddir)exec; echo ==== `pwd` ===; $(call sub_make,exec,clean));
(cd $(builddir)services; echo ==== `pwd` ===; $(call
sub_make,services,clean));
(cd $(builddir)test; echo ==== `pwd` ===; $(call sub_make,test,clean));
@@ -171,7 +173,8 @@ install: all
install -m 755 $(builddir)exec/*lcrso $(DESTDIR)$(LCRSODIR)
install -m 755 $(builddir)services/*lcrso $(DESTDIR)$(LCRSODIR)
install -m 755 $(builddir)exec/corosync $(DESTDIR)$(SBINDIR)
- install -m 700 $(builddir)exec/keygen $(DESTDIR)$(SBINDIR)/ais-keygen
+ install -m 755 $(builddir)apps/objctl $(DESTDIR)$(SBINDIR)
+ install -m 700 $(builddir)apps/keygen $(DESTDIR)$(SBINDIR)/ais-keygen
if [ ! -f $(DESTDIR)$(ETCDIR)/penais.conf ] ; then \
install -m 644 $(srcdir)conf/corosync.conf $(DESTDIR)$(ETCDIR)
; \
diff --git a/corosync/apps/Makefile b/corosync/apps/Makefile
new file mode 100644
index 0000000..1096f8e
--- /dev/null
+++ b/corosync/apps/Makefile
@@ -0,0 +1,67 @@
+# Copyright (c) 2008 Allied Telesis Labs NZ.
+#
+# Author: Angus Salkeld
+#
+# All rights reserved.
+#
+# This software licensed under BSD license, the text of which follows:
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# - Neither the name of the MontaVista Software, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+# Include configuration
+#
+srcdir ?= $(CURDIR)/../
+subdir ?= apps/
+
+include $(srcdir)Makefile.inc
+
+ifeq (${OPENAIS_COMPAT}, SOLARIS)
+ override LDFLAGS += -lnsl -lsocket -lrt
+endif
+
+LIBS = ../lib/libconfdb.a ../lib/libcfg.a
+BINARIES=corosync-objctl corosync-cfgtool keygen
+APPS_SRC=$(addsuffix .c,$(BINARIES))
+EXTRA_CFLAGS = -I$(srcdir)include
+
+all: $(BINARIES)
+
+corosync-objctl: corosync-objctl.o $(LIBS)
+ $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+
+corosync-cfgtool: corosync-cfgtool.o $(LIBS)
+ $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+
+keygen: keygen.o
+ $(CC) $(LDFLAGS) -o $@ $<
+
+clean:
+ rm -f *.o $(BINARIES)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
+
+depend:
+ makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(APPS_SRC) > /dev/null 2>&1
diff --git a/corosync/apps/corosync-cfgtool.c b/corosync/apps/corosync-cfgtool.c
new file mode 100644
index 0000000..9a7d115
--- /dev/null
+++ b/corosync/apps/corosync-cfgtool.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2006-2007 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Steven Dake <[EMAIL PROTECTED]>
+ *
+ * This software licensed under BSD license, the text of which follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the MontaVista Software, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "saAis.h"
+#include "cfg.h"
+
+static void ringstatusget_do (void)
+{
+ SaAisErrorT result;
+ openais_cfg_handle_t handle;
+ unsigned int interface_count;
+ char **interface_names;
+ char **interface_status;
+ unsigned int i;
+
+ printf ("Printing ring status.\n");
+ result = openais_cfg_initialize (&handle, NULL);
+ if (result != SA_AIS_OK) {
+ printf ("Could not initialize openais configuration API error
%d\n", result);
+ exit (1);
+ }
+
+ openais_cfg_ring_status_get (handle,
+ &interface_names,
+ &interface_status,
+ &interface_count);
+
+ for (i = 0; i < interface_count; i++) {
+ printf ("RING ID %d\n", i);
+ printf ("\tid\t= %s\n", interface_names[i]);
+ printf ("\tstatus\t= %s\n", interface_status[i]);
+ }
+
+ openais_cfg_finalize (handle);
+}
+
+static void ringreenable_do (void)
+{
+ SaAisErrorT result;
+ openais_cfg_handle_t handle;
+
+ printf ("Re-enabling all failed rings.\n");
+ result = openais_cfg_initialize (&handle, NULL);
+ if (result != SA_AIS_OK) {
+ printf ("Could not initialize openais configuration API error
%d\n", result);
+ exit (1);
+ }
+
+ result = openais_cfg_ring_reenable (handle);
+ if (result != SA_AIS_OK) {
+ printf ("Could not reenable ring error %d\n", result);
+ }
+
+ openais_cfg_finalize (handle);
+}
+
+void service_load_do (char *service, unsigned int version)
+{
+ SaAisErrorT result;
+ openais_cfg_handle_t handle;
+
+ printf ("Loading service '%s' version '%d'\n", service, version);
+ result = openais_cfg_initialize (&handle, NULL);
+ if (result != SA_AIS_OK) {
+ printf ("Could not initialize openais configuration API error
%d\n", result);
+ exit (1);
+ }
+ result = openais_cfg_service_load (handle, service, version);
+ if (result != SA_AIS_OK) {
+ printf ("Could not load service (error = %d)\n", result);
+ }
+ openais_cfg_finalize (handle);
+}
+
+void service_unload_do (char *service, unsigned int version)
+{
+ SaAisErrorT result;
+ openais_cfg_handle_t handle;
+
+ printf ("Unloading service '%s' version '%d'\n", service, version);
+ result = openais_cfg_initialize (&handle, NULL);
+ if (result != SA_AIS_OK) {
+ printf ("Could not initialize openais configuration API error
%d\n", result);
+ exit (1);
+ }
+ result = openais_cfg_service_unload (handle, service, version);
+ if (result != SA_AIS_OK) {
+ printf ("Could not unload service (error = %d)\n", result);
+ }
+ openais_cfg_finalize (handle);
+}
+
+void usage_do (void)
+{
+ printf ("openais-cfgtool [-s] [-r] [-l] [-u] [service_name] [-v]
[version]\n\n");
+ printf ("A tool for displaying and configuring active parameters within
openais.\n");
+ printf ("options:\n");
+ printf ("\t-s\tDisplays the status of the current rings on this
node.\n");
+ printf ("\t-r\tReset redundant ring state cluster wide after a fault
to\n");
+ printf ("\t\tre-enable redundant ring operation.\n");
+ printf ("\t-l\tLoad a service identified by name.\n");
+ printf ("\t-u\tUnload a service identified by name.\n");
+}
+
+int main (int argc, char *argv[]) {
+ const char *options = "srl:u:v:";
+ int opt;
+ int service_load = 0;
+ int service_unload = 0;
+ char *service;
+ unsigned int version;
+
+ if (argc == 1) {
+ usage_do ();
+ }
+ while ( (opt = getopt(argc, argv, options)) != -1 ) {
+ switch (opt) {
+ case 's':
+ ringstatusget_do ();
+ break;
+ case 'r':
+ ringreenable_do ();
+ break;
+ case 'l':
+ service_load = 1;
+ service = strdup (optarg);
+ break;
+ case 'u':
+ service_unload = 1;
+ service = strdup (optarg);
+ break;
+ case 'v':
+ version = atoi (optarg);
+ }
+ }
+
+ if (service_load) {
+ service_load_do (service, version);
+ } else
+ if (service_unload) {
+ service_unload_do (service, version);
+ }
+
+ return (0);
+}
diff --git a/corosync/apps/corosync-objctl.c b/corosync/apps/corosync-objctl.c
new file mode 100644
index 0000000..84f356c
--- /dev/null
+++ b/corosync/apps/corosync-objctl.c
@@ -0,0 +1,499 @@
+/*
+ * Copyright (c) 2008 Allied Telesis Labs NZ
+ *
+ * All rights reserved.
+ *
+ * Author: Angus Salkeld <[EMAIL PROTECTED]>
+ *
+ * This software licensed under BSD license, the text of which follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the MontaVista Software, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include "saAis.h"
+#include "confdb.h"
+
+#define SEPERATOR '.'
+#define SEPERATOR_STR "."
+#define OBJ_NAME_SIZE 512
+
+typedef enum {
+ ACTION_READ,
+ ACTION_WRITE,
+ ACTION_CREATE,
+ ACTION_DELETE,
+ ACTION_PRINT_ALL,
+ ACTION_PRINT_DEFAULT,
+} action_types_t;
+
+typedef enum {
+ FIND_OBJECT_ONLY,
+ FIND_OBJECT_OR_KEY,
+ FIND_KEY_ONLY
+} find_object_of_type_t;
+
+confdb_callbacks_t callbacks = {
+ .confdb_change_notify_fn = NULL,
+};
+
+static int action;
+
+/* Recursively dump the object tree */
+static void print_config_tree(confdb_handle_t handle, unsigned int
parent_object_handle, char * parent_name)
+{
+ unsigned int object_handle;
+ char object_name[OBJ_NAME_SIZE];
+ int object_name_len;
+ char key_name[OBJ_NAME_SIZE];
+ int key_name_len;
+ char key_value[OBJ_NAME_SIZE];
+ int key_value_len;
+ confdb_error_t res;
+ int children_printed;
+
+ /* Show the keys */
+ res = confdb_key_iter_start(handle, parent_object_handle);
+ if (res != CONFDB_OK) {
+ fprintf(stderr, "error resetting key iterator for object %d:
%d\n", parent_object_handle, res);
+ exit(EXIT_FAILURE);
+ }
+ children_printed = 0;
+
+ while ( (res = confdb_key_iter(handle,
+
parent_object_handle,
+ key_name,
+
&key_name_len,
+ key_value,
+
&key_value_len)) == CONFDB_OK) {
+ key_name[key_name_len] = '\0';
+ key_value[key_value_len] = '\0';
+ if (parent_name != NULL)
+ printf("%s%c%s=%s\n", parent_name, SEPERATOR,key_name,
key_value);
+ else
+ printf("%s=%s\n", key_name, key_value);
+
+ children_printed++;
+ }
+
+ /* Show sub-objects */
+ res = confdb_object_iter_start(handle, parent_object_handle);
+ if (res != CONFDB_OK) {
+ fprintf(stderr, "error resetting object iterator for object %d:
%d\n", parent_object_handle, res);
+ exit(EXIT_FAILURE);
+ }
+
+ while ( (res = confdb_object_iter(handle,
+
parent_object_handle,
+
&object_handle,
+
object_name,
+
&object_name_len)) == CONFDB_OK) {
+
+ object_name[object_name_len] = '\0';
+ if (parent_name != NULL) {
+ snprintf(key_value, OBJ_NAME_SIZE, "%s%c%s",
parent_name, SEPERATOR, object_name);
+ } else {
+ if ((action == ACTION_PRINT_DEFAULT) &&
strcmp(object_name, "internal_configuration") == 0) continue;
+ snprintf(key_value, OBJ_NAME_SIZE, "%s", object_name);
+ }
+ print_config_tree(handle, object_handle, key_value);
+ children_printed++;
+ }
+ if (children_printed == 0 && parent_name != NULL) {
+ printf("%s\n", parent_name);
+ }
+}
+
+static int print_all(void)
+{
+ confdb_handle_t handle;
+ int result;
+
+ result = confdb_initialize (&handle, &callbacks);
+ if (result != CONFDB_OK) {
+ fprintf (stderr, "Could not initialize objdb library. Error
%d\n", result);
+ return 1;
+ }
+
+ print_config_tree(handle, OBJECT_PARENT_HANDLE, NULL);
+
+ result = confdb_finalize (handle);
+
+ return 0;
+}
+
+
+static int print_help(void)
+{
+ printf("\n");
+ printf ("usage: corosync-objctl object%ckey ...\n", SEPERATOR);
+ printf (" corosync-objctl -c object%cchild_obj ...\n",
SEPERATOR);
+ printf (" corosync-objctl -d object%cchild_obj ...\n",
SEPERATOR);
+ printf (" corosync-objctl -w object%cchild_obj.key=value ...\n",
SEPERATOR);
+ printf (" corosync-objctl -a (print all objects)\n");
+ printf("\n");
+ return 0;
+}
+
+static confdb_error_t validate_name(char * obj_name_pt)
+{
+ if ((strchr (obj_name_pt, SEPERATOR) == NULL) &&
+ (strchr (obj_name_pt, '=') == NULL))
+ return CONFDB_OK;
+ else
+ return CONFDB_ERR_INVALID_PARAM;
+}
+
+void get_child_name(char * name_pt, char * child_name)
+{
+ char * tmp;
+ char str_copy[OBJ_NAME_SIZE];
+
+ strcpy(str_copy, name_pt);
+
+ /* first remove the value (it could be a file path */
+ tmp = strchr(str_copy, '=');
+ if (tmp != NULL) *tmp = '\0';
+
+ /* truncate the */
+ tmp = strrchr(str_copy, SEPERATOR);
+ if (tmp == NULL) tmp = str_copy;
+ strcpy(child_name, tmp+1);
+}
+
+void get_parent_name(char * name_pt, char * parent_name)
+{
+ char * tmp;
+ strcpy(parent_name, name_pt);
+
+ /* first remove the value (it could be a file path */
+ tmp = strchr(parent_name, '=');
+ if (tmp != NULL) *tmp = '\0';
+
+ /* then truncate the child name */
+ tmp = strrchr(parent_name, SEPERATOR);
+ if (tmp != NULL) *tmp = '\0';
+}
+
+void get_key(char * name_pt, char * key_name, char * key_value)
+{
+ char * tmp;
+ char str_copy[OBJ_NAME_SIZE];
+
+ strcpy(str_copy, name_pt);
+
+ /* first remove the value (it could have a SEPERATOR in it */
+ tmp = strchr(str_copy, '=');
+ if (tmp != NULL && strlen(tmp) > 0) {
+ strcpy(key_value, tmp+1);
+ *tmp = '\0';
+ } else {
+ key_value[0] = '\0';
+ }
+ /* then remove the name */
+ tmp = strrchr(str_copy, SEPERATOR);
+ if (tmp == NULL) tmp = str_copy;
+ strcpy(key_name, tmp+1);
+}
+
+static confdb_error_t find_object (confdb_handle_t handle,
+ char * name_pt,
+ find_object_of_type_t type,
+ uint32_t * out_handle)
+{
+ char * obj_name_pt;
+ char * save_pt;
+ uint32_t obj_handle;
+ confdb_handle_t parent_object_handle = OBJECT_PARENT_HANDLE;
+ char tmp_name[OBJ_NAME_SIZE];
+ confdb_error_t res;
+
+ strncpy (tmp_name, name_pt, OBJ_NAME_SIZE);
+ obj_name_pt = strtok_r(tmp_name, SEPERATOR_STR, &save_pt);
+
+ while (obj_name_pt != NULL) {
+ res = confdb_object_find_start(handle, parent_object_handle);
+ if (res != CONFDB_OK) {
+ fprintf (stderr, "Could not start object_find %d\n",
res);
+ exit (EXIT_FAILURE);
+ }
+
+ res = confdb_object_find(handle, parent_object_handle,
+ obj_name_pt, strlen (obj_name_pt), &obj_handle);
+ if (res != CONFDB_OK) {
+ return res;
+ }
+
+ parent_object_handle = obj_handle;
+ obj_name_pt = strtok_r (NULL, SEPERATOR_STR, &save_pt);
+ }
+
+ *out_handle = parent_object_handle;
+ return res;
+}
+
+static void read_object(confdb_handle_t handle, char * name_pt)
+{
+ char parent_name[OBJ_NAME_SIZE];
+ uint32_t obj_handle;
+ confdb_error_t res;
+
+ get_parent_name(name_pt, parent_name);
+ res = find_object (handle, name_pt, FIND_OBJECT_OR_KEY, &obj_handle);
+ if (res == CONFDB_OK) {
+ print_config_tree(handle, obj_handle, parent_name);
+ }
+}
+
+static void write_key(confdb_handle_t handle, char * path_pt)
+{
+ uint32_t obj_handle;
+ char parent_name[OBJ_NAME_SIZE];
+ char key_name[OBJ_NAME_SIZE];
+ char key_value[OBJ_NAME_SIZE];
+ char old_key_value[OBJ_NAME_SIZE];
+ int old_key_value_len;
+ confdb_error_t res;
+
+ /* find the parent object */
+ get_parent_name(path_pt, parent_name);
+ get_key(path_pt, key_name, key_value);
+
+ if (validate_name(key_name) != CONFDB_OK) {
+ fprintf(stderr, "Incorrect key name, can not have \"=\" or
\"%c\"\n", SEPERATOR);
+ exit(EXIT_FAILURE);
+ }
+ res = find_object (handle, parent_name, FIND_OBJECT_ONLY, &obj_handle);
+
+ if (res != CONFDB_OK) {
+ fprintf(stderr, "Can't find parent object of \"%s\"\n",
path_pt);
+ exit(EXIT_FAILURE);
+ }
+
+ /* get the current key */
+ res = confdb_key_get (handle,
+ obj_handle,
+ key_name,
+ strlen(key_name),
+ old_key_value,
+ &old_key_value_len);
+
+ if (res == CONFDB_OK) {
+ /* replace the current value */
+ res = confdb_key_replace (handle,
+ obj_handle,
+ key_name,
+
strlen(key_name),
+ old_key_value,
+
old_key_value_len,
+ key_value,
+
strlen(key_value));
+
+ if (res != CONFDB_OK)
+ fprintf(stderr, "Failed to replace the key %s=%s. Error
%d\n", key_name, key_value, res);
+ } else {
+ /* not there, create a new key */
+ res = confdb_key_create (handle,
+ obj_handle,
+ key_name,
+
strlen(key_name),
+ key_value,
+
strlen(key_value));
+ if (res != CONFDB_OK)
+ fprintf(stderr, "Failed to create the key %s=%s. Error
%d\n", key_name, key_value, res);
+ }
+
+}
+
+static void create_object(confdb_handle_t handle, char * name_pt)
+{
+ char * obj_name_pt;
+ char * save_pt;
+ uint32_t obj_handle;
+ uint32_t parent_object_handle = OBJECT_PARENT_HANDLE;
+ char tmp_name[OBJ_NAME_SIZE];
+ confdb_error_t res;
+
+ strncpy (tmp_name, name_pt, OBJ_NAME_SIZE);
+ obj_name_pt = strtok_r(tmp_name, SEPERATOR_STR, &save_pt);
+
+ while (obj_name_pt != NULL) {
+ res = confdb_object_find_start(handle, parent_object_handle);
+ if (res != CONFDB_OK) {
+ fprintf (stderr, "Could not start object_find %d\n",
res);
+ exit (EXIT_FAILURE);
+ }
+
+ res = confdb_object_find(handle, parent_object_handle,
+ obj_name_pt,
strlen (obj_name_pt), &obj_handle);
+ if (res != CONFDB_OK) {
+
+ if (validate_name(obj_name_pt) != CONFDB_OK) {
+ fprintf(stderr, "Incorrect object name \"%s\",
\"=\" not allowed.\n",
+ obj_name_pt);
+ exit(EXIT_FAILURE);
+ }
+ res = confdb_object_create (handle,
+
parent_object_handle,
+
obj_name_pt,
+
strlen (obj_name_pt),
+
&obj_handle);
+ if (res != CONFDB_OK)
+ fprintf(stderr, "Failed to create object
\"%s\". Error %d.\n",
+ obj_name_pt, res);
+ }
+
+ parent_object_handle = obj_handle;
+ obj_name_pt = strtok_r (NULL, SEPERATOR_STR, &save_pt);
+ }
+}
+
+static void delete_object(confdb_handle_t handle, char * name_pt)
+{
+ confdb_error_t res;
+ uint32_t obj_handle;
+ res = find_object (handle, name_pt, FIND_OBJECT_ONLY, &obj_handle);
+
+ if (res == CONFDB_OK) {
+ res = confdb_object_destroy (handle, obj_handle);
+
+ if (res != CONFDB_OK)
+ fprintf(stderr, "Failed to find object \"%s\" to
delete. Error %d\n", name_pt, res);
+ } else {
+ char parent_name[OBJ_NAME_SIZE];
+ char key_name[OBJ_NAME_SIZE];
+ char key_value[OBJ_NAME_SIZE];
+
+ /* find the parent object */
+ get_parent_name(name_pt, parent_name);
+ get_key(name_pt, key_name, key_value);
+ res = find_object (handle, parent_name, FIND_OBJECT_ONLY,
&obj_handle);
+
+ if (res != CONFDB_OK) {
+ fprintf(stderr, "Failed to find the key's parent object
\"%s\". Error %d\n", parent_name, res);
+ exit (EXIT_FAILURE);
+ }
+
+ res = confdb_key_delete (handle,
+ obj_handle,
+ key_name,
+
strlen(key_name),
+ key_value,
+
strlen(key_value));
+
+ if (res != CONFDB_OK)
+ fprintf(stderr, "Failed to delete key \"%s=%s\" from
object \"%s\". Error %d\n",
+ key_name, key_value, parent_name, res);
+ }
+}
+
+
+int main (int argc, char *argv[]) {
+ confdb_handle_t handle;
+ confdb_error_t result;
+ char c;
+
+ action = ACTION_READ;
+
+ for (;;){
+ c = getopt (argc,argv,"hawcdp:");
+ if (c==-1) {
+ break;
+ }
+ switch (c) {
+ case 'h':
+ return print_help();
+ break;
+ case 'a':
+ action = ACTION_PRINT_ALL;
+ break;
+ case 'p':
+ printf("%s:%d NOT Implemented yet.\n",
__FUNCTION__, __LINE__);
+ return -1;
+ //return read_in_config_file();
+ break;
+ case 'c':
+ action = ACTION_CREATE;
+ break;
+ case 'd':
+ action = ACTION_DELETE;
+ break;
+ case 'w':
+ action = ACTION_WRITE;
+ break;
+ default :
+ action = ACTION_READ;
+ break;
+ }
+ }
+
+ if (argc == 1) {
+ action = ACTION_PRINT_DEFAULT;
+ return print_all();
+ } else if (action == ACTION_PRINT_ALL) {
+ return print_all();
+ } else if (optind >= argc) {
+ fprintf(stderr, "Expected an object path after options\n");
+ exit(EXIT_FAILURE);
+ }
+
+ result = confdb_initialize (&handle, &callbacks);
+ if (result != CONFDB_OK) {
+ fprintf (stderr, "Failed to initialize the objdb API. Error
%d\n", result);
+ exit (EXIT_FAILURE);
+ }
+ while (optind < argc) {
+ switch (action) {
+ case ACTION_READ:
+ read_object(handle, argv[optind++]);
+ break;
+ case ACTION_WRITE:
+ write_key(handle, argv[optind++]);
+ break;
+ case ACTION_CREATE:
+ create_object(handle, argv[optind++]);
+ break;
+ case ACTION_DELETE:
+ delete_object(handle, argv[optind++]);
+ break;
+ }
+ }
+
+ result = confdb_finalize (handle);
+ if (result != CONFDB_OK) {
+ fprintf (stderr, "Error finalizing objdb API. Error %d\n",
result);
+ exit(EXIT_FAILURE);
+ }
+
+ return 0;
+}
+
diff --git a/corosync/apps/keygen.c b/corosync/apps/keygen.c
new file mode 100644
index 0000000..6e41e9f
--- /dev/null
+++ b/corosync/apps/keygen.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2004 MontaVista Software, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Steven Dake ([EMAIL PROTECTED])
+ *
+ * This software licensed under BSD license, the text of which follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the MontaVista Software, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <netinet/in.h>
+
+int main (void) {
+ int authkey_fd;
+ int random_fd;
+ unsigned char key[128];
+ int res;
+
+ printf ("OpenAIS Authentication key generator.\n");
+ if (geteuid() != 0) {
+ printf ("Error: Authorization key must be generated as root
user.\n");
+ exit (1);
+ }
+ mkdir ("/etc/ais", 0700);
+
+ printf ("Gathering %lu bits for key from /dev/random.\n", (unsigned
long)(sizeof (key) * 8));
+ random_fd = open ("/dev/random", O_RDONLY);
+ if (random_fd == -1) {
+ perror ("Is /dev/random present? Opening /dev/random");
+ exit (1);
+ }
+
+ /*
+ * Read random data
+ */
+ res = read (random_fd, key, sizeof (key));
+ if (res == -1) {
+ perror ("Could not read /dev/random");
+ exit (1);
+ }
+
+ /*
+ * Open key
+ */
+ authkey_fd = open ("/etc/ais/authkey", O_CREAT|O_WRONLY, 600);
+ if (authkey_fd == -1) {
+ perror ("Could not create /etc/ais/authkey");
+ exit (1);
+ }
+ /*
+ * Set security of authorization key to uid = 0 uid = 0 mode = 0400
+ */
+ res = fchown (authkey_fd, 0, 0);
+ fchmod (authkey_fd, 0400);
+
+ printf ("Writing openais key to /etc/ais/authkey.\n");
+
+ /*
+ * Write key
+ */
+ res = write (authkey_fd, key, sizeof (key));
+ if (res == -1) {
+ perror ("Could not write /etc/ais/authkey");
+ exit (1);
+ }
+
+ return (0);
+}
diff --git a/corosync/exec/Makefile b/corosync/exec/Makefile
index eba842c..c14ce02 100644
--- a/corosync/exec/Makefile
+++ b/corosync/exec/Makefile
@@ -75,10 +75,10 @@ override CFLAGS += -fPIC
all:libtotem_pg.a libtotem_pg.so.2.0.0 liblogsys.a liblogsys.so.2.0.0 \
../lcr/lcr_ifact.o corosync \
- objdb.lcrso vsf_ykd.lcrso coroparse.lcrso keygen
+ objdb.lcrso vsf_ykd.lcrso coroparse.lcrso
else
EXEC_OBJS = $(MAIN_OBJS) $(LCR_OBJS)
-all: libtotem_pg.a liblogsys.a corosync keygen
+all: libtotem_pg.a liblogsys.a corosync
endif
@@ -131,15 +131,9 @@ liblogsys.so.2.0.0: $(LIBLOGSYS_OBJS)
endif
-keygen: keygen.o
- $(CC) $(LDFLAGS) keygen.o -o keygen
-
-openais-instantiate: openais-instantiate.o
- $(CC) $(LDFLAGS) openais-instantiate.o -o openais-instantiate
-
clean:
rm -f corosync $(OBJS) *.o *.lcrso libtotem_pg.so* libtotem_pg.a
gmon.out
- rm -f keygen keygen.o openais-instantiate *.da *.bb *.bbg liblogsys.so*
liblogsys.a
+ rm -f *.da *.bb *.bbg liblogsys.so* liblogsys.a
depend:
makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(EXEC_SRC) $(TOTEM_SRC)
$(LOGSYS_SRC) $(LCR_SRC) > /dev/null 2>&1
diff --git a/corosync/exec/keygen.c b/corosync/exec/keygen.c
deleted file mode 100644
index 6e41e9f..0000000
--- a/corosync/exec/keygen.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2004 MontaVista Software, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake ([EMAIL PROTECTED])
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <netinet/in.h>
-
-int main (void) {
- int authkey_fd;
- int random_fd;
- unsigned char key[128];
- int res;
-
- printf ("OpenAIS Authentication key generator.\n");
- if (geteuid() != 0) {
- printf ("Error: Authorization key must be generated as root
user.\n");
- exit (1);
- }
- mkdir ("/etc/ais", 0700);
-
- printf ("Gathering %lu bits for key from /dev/random.\n", (unsigned
long)(sizeof (key) * 8));
- random_fd = open ("/dev/random", O_RDONLY);
- if (random_fd == -1) {
- perror ("Is /dev/random present? Opening /dev/random");
- exit (1);
- }
-
- /*
- * Read random data
- */
- res = read (random_fd, key, sizeof (key));
- if (res == -1) {
- perror ("Could not read /dev/random");
- exit (1);
- }
-
- /*
- * Open key
- */
- authkey_fd = open ("/etc/ais/authkey", O_CREAT|O_WRONLY, 600);
- if (authkey_fd == -1) {
- perror ("Could not create /etc/ais/authkey");
- exit (1);
- }
- /*
- * Set security of authorization key to uid = 0 uid = 0 mode = 0400
- */
- res = fchown (authkey_fd, 0, 0);
- fchmod (authkey_fd, 0400);
-
- printf ("Writing openais key to /etc/ais/authkey.\n");
-
- /*
- * Write key
- */
- res = write (authkey_fd, key, sizeof (key));
- if (res == -1) {
- perror ("Could not write /etc/ais/authkey");
- exit (1);
- }
-
- return (0);
-}
diff --git a/corosync/man/corosync-objctl.8 b/corosync/man/corosync-objctl.8
new file mode 100644
index 0000000..f230008
--- /dev/null
+++ b/corosync/man/corosync-objctl.8
@@ -0,0 +1,113 @@
+.\"/*
+.\" * Copyright (c) 2008 Allied Telesis Labs NZ.
+.\" *
+.\" * All rights reserved.
+.\" *
+.\" * Author: Angus Salkeld ([EMAIL PROTECTED])
+.\" *
+.\" * This software licensed under BSD license, the text of which follows:
+.\" *
+.\" * Redistribution and use in source and binary forms, with or without
+.\" * modification, are permitted provided that the following conditions are
met:
+.\" *
+.\" * - Redistributions of source code must retain the above copyright notice,
+.\" * this list of conditions and the following disclaimer.
+.\" * - Redistributions in binary form must reproduce the above copyright
notice,
+.\" * this list of conditions and the following disclaimer in the
documentation
+.\" * and/or other materials provided with the distribution.
+.\" * - Neither the name of the MontaVista Software, Inc. nor the names of its
+.\" * contributors may be used to endorse or promote products derived from
this
+.\" * software without specific prior written permission.
+.\" *
+.\" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS"
+.\" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
+.\" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+.\" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+.\" * THE POSSIBILITY OF SUCH DAMAGE.
+.\" */
+.TH COROSYNC-OBJCTL 8 2008-07-29
+.SH NAME
+corosync-objctl \- Configure objects in the Object Database
+.SH SYNOPSIS
+.B "corosync-objctl [\-c|\-w|\-d|\-a|\-h] <OBJECT-SPEC>..."
+.SH DESCRIPTION
+.B corosync-objctl
+is used to configure objects within the object database at runtime.
+.SH OBJECT-SPEC
+.TP
+There are two types of entities
+.B Objects
+and
+.B Key=Value pairs
+.TP
+.B Objects
+Objects are container like entities that can hold other entities.
+They are specified as "objectA"."objectB".
+An example is logging.logger.
+.TP
+.B Key=Value pairs
+These are the entities that actually hold values (read database "fields").
+They are specified as object.key=value or just object.key if you are reading.
+.SH OPTIONS
+.TP
+.B -c
+Create a new object.
+.TP
+.B -d
+Delete an existing object.
+.TP
+.B "-w"
+Use this option when you want to write a new value to a key.
+.TP
+.B "-a"
+Display all values currently available.
+.TP
+.B -h
+Print basic usage.
+.SH EXAMPLES
+.TP
+Print the objOne object (shouldn't exist yet).
+$ corosync-objctl objOne
+.TP
+Create the objOne object.
+$ corosync-objctl -c objOne
+.TP
+Print the objOne object (empty).
+$ corosync-objctl objOne
+.br
+objOne
+.TP
+Write two new keys to the objOne object.
+$ corosync-objctl -w objOne.max=3000 objOne.min=100
+.TP
+Print the objOne object (with the two new keys).
+$ corosync-objctl objOne
+.br
+objOne.min=100
+.br
+objOne.max=3000
+.TP
+Delete the objOne.min key
+$ corosync-objctl -d objOne.min=100
+.TP
+Prove that is gone.
+$ corosync-objctl objOne
+.br
+objOne.max=3000
+.TP
+Delete the whole objOne object.
+$ corosync-objctl -d objOne
+.TP
+Prove that is gone.
+$ corosync-objctl objOne
+.SH SEE ALSO
+.BR confdb_initialize (3),
+.SH AUTHOR
+Angus Salkeld
+.PP
diff --git a/corosync/test/Makefile b/corosync/test/Makefile
index cc04481..36668f2 100644
--- a/corosync/test/Makefile
+++ b/corosync/test/Makefile
@@ -39,7 +39,7 @@ endif
LIBRARIES= ../lib/libevs.a ../lib/libcpg.a ../lib/libcfg.a ../lib/libconfdb.a
LIBS = $(LIBRARIES)
-BINARIES= testevs evsbench testcpg testcpg2 cpgbench testconfdb openais-cfgtool
+BINARIES= testevs evsbench testcpg testcpg2 cpgbench testconfdb
override CFLAGS += -I../include
override LDFLAGS += -L../lib
@@ -73,9 +73,6 @@ cpgbench: cpgbench.o $(LIBRARIES)
testconfdb: testconfdb.o $(LIBRARIES)
$(CC) $(LDFLAGS) -o testconfdb testconfdb.o $(LIBS) -rdynamic
-openais-cfgtool: openais-cfgtool.o $(LIBRARIES)
- $(CC) $(LDFLAGS) -o openais-cfgtool openais-cfgtool.o $(LIBS)
-
logsys_s: logsys_s.o logsys_s1.o logsys_s2.o ../exec/liblogsys.a
$(CC) -o logsys_s logsys_s.o logsys_s1.o logsys_s2.o
../exec/liblogsys.a $(LDFLAGS)
diff --git a/corosync/test/openais-cfgtool.c b/corosync/test/openais-cfgtool.c
deleted file mode 100644
index 9a7d115..0000000
--- a/corosync/test/openais-cfgtool.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (c) 2006-2007 Red Hat, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake <[EMAIL PROTECTED]>
- *
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "saAis.h"
-#include "cfg.h"
-
-static void ringstatusget_do (void)
-{
- SaAisErrorT result;
- openais_cfg_handle_t handle;
- unsigned int interface_count;
- char **interface_names;
- char **interface_status;
- unsigned int i;
-
- printf ("Printing ring status.\n");
- result = openais_cfg_initialize (&handle, NULL);
- if (result != SA_AIS_OK) {
- printf ("Could not initialize openais configuration API error
%d\n", result);
- exit (1);
- }
-
- openais_cfg_ring_status_get (handle,
- &interface_names,
- &interface_status,
- &interface_count);
-
- for (i = 0; i < interface_count; i++) {
- printf ("RING ID %d\n", i);
- printf ("\tid\t= %s\n", interface_names[i]);
- printf ("\tstatus\t= %s\n", interface_status[i]);
- }
-
- openais_cfg_finalize (handle);
-}
-
-static void ringreenable_do (void)
-{
- SaAisErrorT result;
- openais_cfg_handle_t handle;
-
- printf ("Re-enabling all failed rings.\n");
- result = openais_cfg_initialize (&handle, NULL);
- if (result != SA_AIS_OK) {
- printf ("Could not initialize openais configuration API error
%d\n", result);
- exit (1);
- }
-
- result = openais_cfg_ring_reenable (handle);
- if (result != SA_AIS_OK) {
- printf ("Could not reenable ring error %d\n", result);
- }
-
- openais_cfg_finalize (handle);
-}
-
-void service_load_do (char *service, unsigned int version)
-{
- SaAisErrorT result;
- openais_cfg_handle_t handle;
-
- printf ("Loading service '%s' version '%d'\n", service, version);
- result = openais_cfg_initialize (&handle, NULL);
- if (result != SA_AIS_OK) {
- printf ("Could not initialize openais configuration API error
%d\n", result);
- exit (1);
- }
- result = openais_cfg_service_load (handle, service, version);
- if (result != SA_AIS_OK) {
- printf ("Could not load service (error = %d)\n", result);
- }
- openais_cfg_finalize (handle);
-}
-
-void service_unload_do (char *service, unsigned int version)
-{
- SaAisErrorT result;
- openais_cfg_handle_t handle;
-
- printf ("Unloading service '%s' version '%d'\n", service, version);
- result = openais_cfg_initialize (&handle, NULL);
- if (result != SA_AIS_OK) {
- printf ("Could not initialize openais configuration API error
%d\n", result);
- exit (1);
- }
- result = openais_cfg_service_unload (handle, service, version);
- if (result != SA_AIS_OK) {
- printf ("Could not unload service (error = %d)\n", result);
- }
- openais_cfg_finalize (handle);
-}
-
-void usage_do (void)
-{
- printf ("openais-cfgtool [-s] [-r] [-l] [-u] [service_name] [-v]
[version]\n\n");
- printf ("A tool for displaying and configuring active parameters within
openais.\n");
- printf ("options:\n");
- printf ("\t-s\tDisplays the status of the current rings on this
node.\n");
- printf ("\t-r\tReset redundant ring state cluster wide after a fault
to\n");
- printf ("\t\tre-enable redundant ring operation.\n");
- printf ("\t-l\tLoad a service identified by name.\n");
- printf ("\t-u\tUnload a service identified by name.\n");
-}
-
-int main (int argc, char *argv[]) {
- const char *options = "srl:u:v:";
- int opt;
- int service_load = 0;
- int service_unload = 0;
- char *service;
- unsigned int version;
-
- if (argc == 1) {
- usage_do ();
- }
- while ( (opt = getopt(argc, argv, options)) != -1 ) {
- switch (opt) {
- case 's':
- ringstatusget_do ();
- break;
- case 'r':
- ringreenable_do ();
- break;
- case 'l':
- service_load = 1;
- service = strdup (optarg);
- break;
- case 'u':
- service_unload = 1;
- service = strdup (optarg);
- break;
- case 'v':
- version = atoi (optarg);
- }
- }
-
- if (service_load) {
- service_load_do (service, version);
- } else
- if (service_unload) {
- service_unload_do (service, version);
- }
-
- return (0);
-}
--
1.5.6
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais