fenced: munge config option code
authorDavid Teigland <teigland@redhat.com>
Fri, 18 Jul 2008 15:34:00 +0000 (10:34 -0500)
committerDavid Teigland <teigland@redhat.com>
Fri, 18 Jul 2008 15:35:17 +0000 (10:35 -0500)
to match the code in other daemons.

Signed-off-by: David Teigland <teigland@redhat.com>
fence/fenced/config.c
fence/fenced/config.h [new file with mode: 0644]
fence/fenced/fd.h
fence/fenced/main.c
fence/fenced/recover.c

index 3468459b72ee037b2c362ac0e1d5d13fb7007377..046112fbe7201950bcb632d976a62920fc302d9b 100644 (file)
@@ -1,8 +1,27 @@
 #include "fd.h"
+#include "config.h"
 #include "ccs.h"
 
 static int ccs_handle;
 
+/* was a config value set on command line?, 0 or 1. */
+
+int optd_groupd_compat;
+int optd_clean_start;
+int optd_post_join_delay;
+int optd_post_fail_delay;
+int optd_override_time;
+int optd_override_path;
+
+/* actual config value from command line, cluster.conf, or default. */
+
+int cfgd_groupd_compat   = DEFAULT_GROUPD_COMPAT;
+int cfgd_clean_start     = DEFAULT_CLEAN_START;
+int cfgd_post_join_delay = DEFAULT_POST_JOIN_DELAY;
+int cfgd_post_fail_delay = DEFAULT_POST_FAIL_DELAY;
+int cfgd_override_time   = DEFAULT_OVERRIDE_TIME;
+char *cfgd_override_path = DEFAULT_OVERRIDE_PATH;
+
 int setup_ccs(void)
 {
        int i = 0, cd;
@@ -90,7 +109,7 @@ void read_ccs_int(char *path, int *config_val)
 
 int read_ccs(struct fd *fd)
 {
-       char path[256];
+       char path[PATH_MAX];
        char *str;
        int error, i = 0, count = 0;
 
@@ -99,8 +118,8 @@ int read_ccs(struct fd *fd)
           fence us. */
 
        str = NULL;
-       memset(path, 0, 256);
-       snprintf(path, 256, OUR_NAME_PATH, our_name);
+       memset(path, 0, sizeof(path));
+       snprintf(path, sizeof(path), OUR_NAME_PATH, our_name);
 
        error = ccs_get(ccs_handle, path, &str);
        if (error || !str) {
@@ -111,44 +130,37 @@ int read_ccs(struct fd *fd)
        if (str)
                free(str);
 
-       /* The comline config options are initially set to the defaults,
-          then options are read from the command line to override the
-          defaults, for options not set on command line, we look for
-          values set in cluster.conf. */
-
-       if (!comline.groupd_compat_opt)
-               read_ccs_int(GROUPD_COMPAT_PATH, &comline.groupd_compat);
-       if (!comline.clean_start_opt)
-               read_ccs_int(CLEAN_START_PATH, &comline.clean_start);
-       if (!comline.post_join_delay_opt)
-               read_ccs_int(POST_JOIN_DELAY_PATH, &comline.post_join_delay);
-       if (!comline.post_fail_delay_opt)
-               read_ccs_int(POST_FAIL_DELAY_PATH, &comline.post_fail_delay);
-       if (!comline.override_time_opt)
-               read_ccs_int(OVERRIDE_TIME_PATH, &comline.override_time);
-
-       if (!comline.override_path_opt) {
+       if (!optd_groupd_compat)
+               read_ccs_int(GROUPD_COMPAT_PATH, &cfgd_groupd_compat);
+       if (!optd_clean_start)
+               read_ccs_int(CLEAN_START_PATH, &cfgd_clean_start);
+       if (!optd_post_join_delay)
+               read_ccs_int(POST_JOIN_DELAY_PATH, &cfgd_post_join_delay);
+       if (!optd_post_fail_delay)
+               read_ccs_int(POST_FAIL_DELAY_PATH, &cfgd_post_fail_delay);
+       if (!optd_override_time)
+               read_ccs_int(OVERRIDE_TIME_PATH, &cfgd_override_time);
+
+       if (!optd_override_path) {
                str = NULL;
-               memset(path, 0, 256);
+               memset(path, 0, sizeof(path));
                sprintf(path, OVERRIDE_PATH_PATH);
 
                error = ccs_get(ccs_handle, path, &str);
-               if (!error && str) {
-                       free(comline.override_path);
-                       comline.override_path = strdup(str);
-               }
+               if (!error && str)
+                       cfgd_override_path = strdup(str);
                if (str)
                        free(str);
        }
 
-       if (comline.clean_start) {
+       if (cfgd_clean_start) {
                log_debug("clean start, skipping initial nodes");
                goto out;
        }
 
        for (i = 1; ; i++) {
                str = NULL;
-               memset(path, 0, 256);
+               memset(path, 0, sizeof(path));
                sprintf(path, "/cluster/clusternodes/clusternode[%d]/@nodeid", i);
 
                error = ccs_get(ccs_handle, path, &str);
diff --git a/fence/fenced/config.h b/fence/fenced/config.h
new file mode 100644 (file)
index 0000000..3d919ac
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __CONFIG_DOT_H__
+#define __CONFIG_DOT_H__
+
+#define DEFAULT_GROUPD_COMPAT 1
+#define DEFAULT_CLEAN_START 0
+#define DEFAULT_POST_JOIN_DELAY 6
+#define DEFAULT_POST_FAIL_DELAY 0
+#define DEFAULT_OVERRIDE_TIME 3
+#define DEFAULT_OVERRIDE_PATH "/var/run/cluster/fenced_override"
+
+extern int optd_groupd_compat;
+extern int optd_clean_start;
+extern int optd_post_join_delay;
+extern int optd_post_fail_delay;
+extern int optd_override_time;
+extern int optd_override_path;
+
+extern int cfgd_groupd_compat;
+extern int cfgd_clean_start;
+extern int cfgd_post_join_delay;
+extern int cfgd_post_fail_delay;
+extern int cfgd_override_time;
+extern char *cfgd_override_path;
+
+#endif
+
index 1e91894de6aa2d72122d2f49e776b26151a36377..e16da90f1b83b46b0b9c168fec3ff8e82caecfb1 100644 (file)
@@ -95,34 +95,6 @@ do { \
        log_printf(lvl, fmt, ##args); \
 } while (0)
 
-/* config option defaults */
-
-#define DEFAULT_GROUPD_COMPAT  1
-#define DEFAULT_CLEAN_START    0
-#define DEFAULT_POST_JOIN_DELAY        6
-#define DEFAULT_POST_FAIL_DELAY        0
-#define DEFAULT_OVERRIDE_TIME   3
-#define DEFAULT_OVERRIDE_PATH  "/var/run/cluster/fenced_override"
-
-struct commandline
-{
-       int groupd_compat;
-       int clean_start;
-       int post_join_delay;
-       int post_fail_delay;
-       int override_time;
-       char *override_path;
-
-       int8_t groupd_compat_opt;
-       int8_t clean_start_opt;
-       int8_t post_join_delay_opt;
-       int8_t post_fail_delay_opt;
-       int8_t override_time_opt;
-       int8_t override_path_opt;
-};
-
-extern struct commandline comline;
-
 #define FD_MSG_START           1
 #define FD_MSG_VICTIM_DONE     2
 #define FD_MSG_COMPLETE                3
index bc7fb4082cdf24c3f0f3d8bd2946eed1b15f3873..decae4637b070861dd44a1f7e00900948bd482a9 100644 (file)
@@ -1,5 +1,6 @@
 #include "fd.h"
-#include "pthread.h"
+#include "config.h"
+#include <pthread.h>
 #include "copyright.cf"
 
 #define LOCKFILE_NAME          "/var/run/fenced.pid"
@@ -627,7 +628,7 @@ static void loop(void)
 
        group_mode = GROUP_LIBCPG;
 
-       if (comline.groupd_compat) {
+       if (cfgd_groupd_compat) {
                rv = setup_groupd();
                if (rv < 0)
                        goto out;
@@ -635,7 +636,7 @@ static void loop(void)
 
                group_mode = GROUP_LIBGROUP;
 
-               if (comline.groupd_compat == 2) {
+               if (cfgd_groupd_compat == 2) {
                        /* set_group_mode(); */
                        group_mode = GROUP_LIBGROUP;
                }
@@ -683,7 +684,7 @@ static void loop(void)
                        break;
        }
  out:
-       if (comline.groupd_compat)
+       if (cfgd_groupd_compat)
                close_groupd();
        close_logging();
        close_ccs();
@@ -779,37 +780,35 @@ static void read_arguments(int argc, char **argv)
                        break;
 
                case 'g':
-                       comline.groupd_compat = atoi(optarg);
-                       comline.groupd_compat_opt = 1;
+                       optd_groupd_compat = 1;
+                       cfgd_groupd_compat = atoi(optarg);
                        break;
 
                case 'c':
-                       comline.clean_start = 1;
-                       comline.clean_start_opt = 1;
+                       optd_clean_start = 1;
+                       cfgd_clean_start = 1;
                        break;
 
                case 'j':
-                       comline.post_join_delay = atoi(optarg);
-                       comline.post_join_delay_opt = 1;
+                       optd_post_join_delay = 1;
+                       cfgd_post_join_delay = atoi(optarg);
                        break;
 
                case 'f':
-                       comline.post_fail_delay = atoi(optarg);
-                       comline.post_fail_delay_opt = 1;
+                       optd_post_fail_delay = 1;
+                       cfgd_post_fail_delay = atoi(optarg);
                        break;
 
                case 'R':
-                       comline.override_time = atoi(optarg);
-                       if (comline.override_time < 3)
-                               comline.override_time = 3;
-                       comline.override_time_opt = 1;
+                       optd_override_time = 1;
+                       cfgd_override_time = atoi(optarg);
+                       if (cfgd_override_time < 3)
+                               cfgd_override_time = 3;
                        break;
 
                case 'O':
-                       if (comline.override_path)
-                               free(comline.override_path);
-                       comline.override_path = strdup(optarg);
-                       comline.override_path_opt = 1;
+                       optd_override_path = 1;
+                       cfgd_override_path = strdup(optarg);
                        break;
 
                case 'h':
@@ -857,14 +856,6 @@ int main(int argc, char **argv)
 {
        INIT_LIST_HEAD(&domains);
 
-       memset(&comline, 0, sizeof(comline));
-       comline.groupd_compat = DEFAULT_GROUPD_COMPAT;
-       comline.clean_start = DEFAULT_CLEAN_START;
-       comline.post_join_delay = DEFAULT_POST_JOIN_DELAY;
-       comline.post_fail_delay = DEFAULT_POST_FAIL_DELAY;
-       comline.override_time = DEFAULT_OVERRIDE_TIME;
-       comline.override_path = strdup(DEFAULT_OVERRIDE_PATH);
-
        init_logging();
 
        read_arguments(argc, argv);
@@ -915,5 +906,4 @@ char dump_buf[FENCED_DUMP_SIZE];
 int dump_point;
 int dump_wrap;
 int group_mode;
-struct commandline comline;
 
index be82190f20c5040fdc825cc8ebb079523d1b7e3a..5b46f368a94402ed4bf64b0d7063737a17138504 100644 (file)
@@ -1,4 +1,5 @@
 #include "fd.h"
+#include "config.h"
 
 void free_node_list(struct list_head *head)
 {
@@ -164,10 +165,10 @@ void delay_fencing(struct fd *fd, int node_join)
                return;
 
        if (node_join) {
-               delay = comline.post_join_delay;
+               delay = cfgd_post_join_delay;
                delay_type = "post_join_delay";
        } else {
-               delay = comline.post_fail_delay;
+               delay = cfgd_post_fail_delay;
                delay_type = "post_fail_delay";
        }
 
@@ -188,8 +189,8 @@ void delay_fencing(struct fd *fd, int node_join)
 
                if (victim_count < last_count) {
                        gettimeofday(&start, NULL);
-                       if (delay > 0 && comline.post_join_delay > delay) {
-                               delay = comline.post_join_delay;
+                       if (delay > 0 && cfgd_post_join_delay > delay) {
+                               delay = cfgd_post_join_delay;
                                delay_type = "post_join_delay (modified)";
                        }
                }
@@ -272,7 +273,7 @@ void fence_victims(struct fd *fd)
                        continue;
                }
 
-               if (!comline.override_path) {
+               if (!cfgd_override_path) {
                        query_unlock();
                        sleep(5);
                        query_lock();
@@ -281,16 +282,16 @@ void fence_victims(struct fd *fd)
 
                query_unlock();
                /* Check for manual intervention */
-               override = open_override(comline.override_path);
+               override = open_override(cfgd_override_path);
                if (check_override(override, node->name,
-                                  comline.override_time) > 0) {
+                                  cfgd_override_time) > 0) {
                        log_level(LOG_WARNING, "fence \"%s\" overridden by "
                                  "administrator intervention", node->name);
                        victim_done(fd, node->nodeid, VIC_DONE_OVERRIDE);
                        list_del(&node->list);
                        free(node);
                }
-               close_override(&override, comline.override_path);
+               close_override(&override, cfgd_override_path);
                query_lock();
        }
 }
This page took 0.085616 seconds and 5 git commands to generate.