forked from altcloud/fence-virt
Make debugging work from modules again
Signed-off-by: Lon Hohberger <lhh@redhat.com>
This commit is contained in:
parent
8c3b59fe53
commit
da7d3f4c9d
@ -21,14 +21,14 @@
|
|||||||
|
|
||||||
static int _debug = 0;
|
static int _debug = 0;
|
||||||
|
|
||||||
inline void
|
void
|
||||||
dset(int threshold)
|
dset(int threshold)
|
||||||
{
|
{
|
||||||
_debug = threshold;
|
_debug = threshold;
|
||||||
dbg_printf(3, "Debugging threshold is now %d\n", threshold);
|
dbg_printf(3, "Debugging threshold is now %d\n", threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int
|
int
|
||||||
dget(void)
|
dget(void)
|
||||||
{
|
{
|
||||||
return _debug;
|
return _debug;
|
||||||
|
@ -29,4 +29,9 @@ extern struct value *val_list;
|
|||||||
extern struct node *node_list;
|
extern struct node *node_list;
|
||||||
extern struct parser_context *context_stack;
|
extern struct parser_context *context_stack;
|
||||||
|
|
||||||
|
int _sc_value_add(char *id, char *val, struct value **list);
|
||||||
|
int _sc_node_add(char *id, struct value *vallist, struct node *nodelist,
|
||||||
|
struct node **list);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,11 +90,15 @@ main(int argc, char *argv[])
|
|||||||
c = sc_init();
|
c = sc_init();
|
||||||
sc_parse(c, NULL);
|
sc_parse(c, NULL);
|
||||||
sc_dump(c, stdout);
|
sc_dump(c, stdout);
|
||||||
if (argc >= 2) {
|
if (argc == 2) {
|
||||||
if (sc_get(c, argv[1], value, sizeof(value)) == 0)
|
if (sc_get(c, argv[1], value, sizeof(value)) == 0)
|
||||||
printf("%s = %s\n", argv[1], value);
|
printf("%s = %s\n", argv[1], value);
|
||||||
else
|
else
|
||||||
printf("Not found\n");
|
printf("Not found\n");
|
||||||
|
} else if (argc == 3) {
|
||||||
|
printf("---------\n");
|
||||||
|
if (sc_set(c, argv[1], argv[2]) == 0)
|
||||||
|
sc_dump(c, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_release(c);
|
sc_release(c);
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
extern int yylex (void);
|
extern int yylex (void);
|
||||||
int yyerror(const char *foo);
|
int yyerror(const char *foo);
|
||||||
|
|
||||||
static int
|
int
|
||||||
value_add(char *id, char *val, struct value **list)
|
_sc_value_add(char *id, char *val, struct value **list)
|
||||||
{
|
{
|
||||||
struct value *v;
|
struct value *v;
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ value_add(char *id, char *val, struct value **list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
int
|
||||||
node_add(char *id, struct value *vallist, struct node *nodelist,
|
_sc_node_add(char *id, struct value *vallist, struct node *nodelist,
|
||||||
struct node **list)
|
struct node **list)
|
||||||
{
|
{
|
||||||
struct node *n;
|
struct node *n;
|
||||||
@ -72,7 +72,7 @@ node:
|
|||||||
struct parser_context *c = NULL;
|
struct parser_context *c = NULL;
|
||||||
|
|
||||||
c = context_stack;
|
c = context_stack;
|
||||||
node_add($1, val_list, node_list, &c->node_list);
|
_sc_node_add($1, val_list, node_list, &c->node_list);
|
||||||
val_list = c->val_list;
|
val_list = c->val_list;
|
||||||
node_list = c->node_list;
|
node_list = c->node_list;
|
||||||
context_stack = c->next;
|
context_stack = c->next;
|
||||||
@ -84,7 +84,7 @@ node:
|
|||||||
struct parser_context *c = NULL;
|
struct parser_context *c = NULL;
|
||||||
|
|
||||||
c = context_stack;
|
c = context_stack;
|
||||||
node_add($1, val_list, node_list, &c->node_list);
|
_sc_node_add($1, val_list, node_list, &c->node_list);
|
||||||
val_list = c->val_list;
|
val_list = c->val_list;
|
||||||
node_list = c->node_list;
|
node_list = c->node_list;
|
||||||
context_stack = c->next;
|
context_stack = c->next;
|
||||||
@ -99,7 +99,7 @@ stuff:
|
|||||||
|
|
||||||
assign:
|
assign:
|
||||||
T_ID T_EQ T_VAL T_SEMI {
|
T_ID T_EQ T_VAL T_SEMI {
|
||||||
value_add($1, $3, &val_list);
|
_sc_value_add($1, $3, &val_list);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
%%
|
%%
|
||||||
|
@ -180,15 +180,16 @@ _sc_get(config_info_t *config, const char *key, char *value, size_t valuesz)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr[0] == '@') {
|
if (ptr[0] != '@')
|
||||||
++ptr;
|
return 1;
|
||||||
found = 0;
|
|
||||||
|
|
||||||
for (v = values; v; v = v->next) {
|
++ptr;
|
||||||
if (!strcasecmp(v->id, ptr)) {
|
found = 0;
|
||||||
snprintf(value, valuesz, "%s", v->val);
|
|
||||||
return 0;
|
for (v = values; v; v = v->next) {
|
||||||
}
|
if (!strcasecmp(v->id, ptr)) {
|
||||||
|
snprintf(value, valuesz, "%s", v->val);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +197,76 @@ _sc_get(config_info_t *config, const char *key, char *value, size_t valuesz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sc_set(config_info_t *config, const char *key, const char *value)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
struct node *n, **nodes = &((struct parser_context *)config)->node_list;
|
||||||
|
struct value *v, **values = &((struct parser_context *)config)->val_list;
|
||||||
|
char *ptr;
|
||||||
|
char *slash;
|
||||||
|
char *id_dup, *val_dup;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
ptr = (char *)key;
|
||||||
|
while ((slash = strchr(ptr, '/'))) {
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
strncpy(buf, ptr, (slash - ptr));
|
||||||
|
ptr = ++slash;
|
||||||
|
found = 0;
|
||||||
|
|
||||||
|
for (n = *nodes; n; n = n->next) {
|
||||||
|
if (strcasecmp(n->id, buf))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
nodes = &n->nodes;
|
||||||
|
values = &n->values;
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
id_dup = strdup(buf);
|
||||||
|
if (!id_dup)
|
||||||
|
return -1;
|
||||||
|
_sc_node_add(id_dup, NULL, NULL, nodes);
|
||||||
|
n = *nodes;
|
||||||
|
nodes = &n->nodes;
|
||||||
|
values = &n->values;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ptr[0] != '@')
|
||||||
|
return 1;
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
for (v = *values; v; v = v->next) {
|
||||||
|
if (strcasecmp(v->id, ptr))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ptr = v->val;
|
||||||
|
v->val = strdup(value);
|
||||||
|
if (!v->val) {
|
||||||
|
v->val = ptr;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(ptr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
id_dup = strdup(ptr);
|
||||||
|
if (!id_dup)
|
||||||
|
return -1;
|
||||||
|
val_dup = strdup(value);
|
||||||
|
if (!val_dup)
|
||||||
|
return -1;
|
||||||
|
_sc_value_add(id_dup, val_dup, values);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_sc_parse(const char *filename, config_info_t **config)
|
_sc_parse(const char *filename, config_info_t **config)
|
||||||
{
|
{
|
||||||
@ -239,6 +310,7 @@ _sc_parse(const char *filename, config_info_t **config)
|
|||||||
|
|
||||||
static const config_object_t sc_object = {
|
static const config_object_t sc_object = {
|
||||||
.get = _sc_get,
|
.get = _sc_get,
|
||||||
|
.set = _sc_set,
|
||||||
.parse = _sc_parse,
|
.parse = _sc_parse,
|
||||||
.free = _sc_free,
|
.free = _sc_free,
|
||||||
.dump = _sc_dump,
|
.dump = _sc_dump,
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
#ifndef _SIMPLECONFIG_H
|
|
||||||
#define _SIMPLECONFIG_H
|
|
||||||
|
|
||||||
typedef void config_info_t;
|
|
||||||
|
|
||||||
typedef int (*config_get_t)(config_info_t *config, const char *key,
|
|
||||||
char *value, size_t valuesz);
|
|
||||||
typedef int (*config_parse_t)(const char *filename, config_info_t **config);
|
|
||||||
typedef int (*config_free_t)(config_info_t *config);
|
|
||||||
typedef void (*config_dump_t)(config_info_t *config, FILE *fp);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We use an abstract object here so we do not have to link loadable
|
|
||||||
* modules against the configuration library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
config_get_t get;
|
|
||||||
config_parse_t parse;
|
|
||||||
config_free_t free;
|
|
||||||
config_dump_t dump;
|
|
||||||
config_info_t *info;
|
|
||||||
} config_object_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These macros may be called from within a loadable module
|
|
||||||
*/
|
|
||||||
#define sc_get(obj, key, value, valuesz) \
|
|
||||||
obj->get(obj->info, key, value, valuesz)
|
|
||||||
#define sc_parse(obj, filename) \
|
|
||||||
obj->parse(filename, &obj->info)
|
|
||||||
#define sc_free(obj) \
|
|
||||||
obj->free(obj->info)
|
|
||||||
#define sc_dump(obj, fp) \
|
|
||||||
obj->dump(obj->info, fp)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Do not call the below functions from loadable modules. Doing so
|
|
||||||
* requires linking the configuration library in to the modules, which
|
|
||||||
* is what we want to avoid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Returns a copy of our simple config object */
|
|
||||||
config_object_t *sc_init(void);
|
|
||||||
|
|
||||||
/* Frees a previously-allocated copy of our simple config object */
|
|
||||||
void sc_release(config_object_t *c);
|
|
||||||
|
|
||||||
#endif
|
|
@ -5,6 +5,8 @@ typedef void config_info_t;
|
|||||||
|
|
||||||
typedef int (*config_get_t)(config_info_t *config, const char *key,
|
typedef int (*config_get_t)(config_info_t *config, const char *key,
|
||||||
char *value, size_t valuesz);
|
char *value, size_t valuesz);
|
||||||
|
typedef int (*config_set_t)(config_info_t *config, const char *key,
|
||||||
|
const char *value);
|
||||||
typedef int (*config_parse_t)(const char *filename, config_info_t **config);
|
typedef int (*config_parse_t)(const char *filename, config_info_t **config);
|
||||||
typedef int (*config_free_t)(config_info_t *config);
|
typedef int (*config_free_t)(config_info_t *config);
|
||||||
typedef void (*config_dump_t)(config_info_t *config, FILE *fp);
|
typedef void (*config_dump_t)(config_info_t *config, FILE *fp);
|
||||||
@ -16,6 +18,7 @@ typedef void (*config_dump_t)(config_info_t *config, FILE *fp);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
config_get_t get;
|
config_get_t get;
|
||||||
|
config_set_t set;
|
||||||
config_parse_t parse;
|
config_parse_t parse;
|
||||||
config_free_t free;
|
config_free_t free;
|
||||||
config_dump_t dump;
|
config_dump_t dump;
|
||||||
@ -27,6 +30,8 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
#define sc_get(obj, key, value, valuesz) \
|
#define sc_get(obj, key, value, valuesz) \
|
||||||
obj->get(obj->info, key, value, valuesz)
|
obj->get(obj->info, key, value, valuesz)
|
||||||
|
#define sc_set(obj, key, value) \
|
||||||
|
obj->set(obj->info, key, value)
|
||||||
#define sc_parse(obj, filename) \
|
#define sc_parse(obj, filename) \
|
||||||
obj->parse(filename, &obj->info)
|
obj->parse(filename, &obj->info)
|
||||||
#define sc_free(obj) \
|
#define sc_free(obj) \
|
||||||
|
@ -346,8 +346,12 @@ libvirt_init(backend_context_t *c, config_object_t *config)
|
|||||||
if (!info)
|
if (!info)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
dbg_printf(5, "[%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
memset(info, 0, sizeof(*info));
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
|
if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0)
|
||||||
|
dset(atoi(value));
|
||||||
|
|
||||||
if (sc_get(config, "backends/libvirt/@uri",
|
if (sc_get(config, "backends/libvirt/@uri",
|
||||||
value, sizeof(value)) == 0) {
|
value, sizeof(value)) == 0) {
|
||||||
uri = strdup(value);
|
uri = strdup(value);
|
||||||
|
@ -41,8 +41,7 @@ main(int argc, char **argv)
|
|||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
dset(atoi(optarg));
|
debug_set = atoi(optarg);
|
||||||
debug_set = 1;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
@ -54,11 +53,16 @@ main(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!debug_set) {
|
if (debug_set) {
|
||||||
if (sc_get(config, "fence_virtd/@debug",
|
snprintf(val, sizeof(val), "%d", debug_set);
|
||||||
val, sizeof(val)) == 0)
|
sc_set(config, "fence_virtd/@debug", val);
|
||||||
dset(atoi(val));
|
} else {
|
||||||
|
if (sc_get(config, "fence_virtd/@debug", val, sizeof(val))==0)
|
||||||
|
debug_set = atoi(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dset(debug_set);
|
||||||
|
|
||||||
if (!foreground) {
|
if (!foreground) {
|
||||||
if (sc_get(config, "fence_virtd/@foreground",
|
if (sc_get(config, "fence_virtd/@foreground",
|
||||||
val, sizeof(val)) == 0)
|
val, sizeof(val)) == 0)
|
||||||
|
@ -343,6 +343,9 @@ mcast_config(config_object_t *config, mcast_options *args)
|
|||||||
char value[1024];
|
char value[1024];
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
||||||
|
if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0)
|
||||||
|
dset(atoi(value));
|
||||||
|
|
||||||
if (sc_get(config, "listeners/multicast/@key_file",
|
if (sc_get(config, "listeners/multicast/@key_file",
|
||||||
value, sizeof(value)-1) == 0) {
|
value, sizeof(value)-1) == 0) {
|
||||||
dbg_printf(1, "Got %s for key_file\n", value);
|
dbg_printf(1, "Got %s for key_file\n", value);
|
||||||
|
@ -26,9 +26,6 @@
|
|||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* Local includes */
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define NAME "null"
|
#define NAME "null"
|
||||||
#define VERSION "0.8"
|
#define VERSION "0.8"
|
||||||
|
Loading…
Reference in New Issue
Block a user