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;
|
||||
|
||||
inline void
|
||||
void
|
||||
dset(int threshold)
|
||||
{
|
||||
_debug = threshold;
|
||||
dbg_printf(3, "Debugging threshold is now %d\n", threshold);
|
||||
}
|
||||
|
||||
inline int
|
||||
int
|
||||
dget(void)
|
||||
{
|
||||
return _debug;
|
||||
|
@ -29,4 +29,9 @@ extern struct value *val_list;
|
||||
extern struct node *node_list;
|
||||
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
|
||||
|
@ -90,11 +90,15 @@ main(int argc, char *argv[])
|
||||
c = sc_init();
|
||||
sc_parse(c, NULL);
|
||||
sc_dump(c, stdout);
|
||||
if (argc >= 2) {
|
||||
if (argc == 2) {
|
||||
if (sc_get(c, argv[1], value, sizeof(value)) == 0)
|
||||
printf("%s = %s\n", argv[1], value);
|
||||
else
|
||||
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);
|
||||
|
@ -8,8 +8,8 @@
|
||||
extern int yylex (void);
|
||||
int yyerror(const char *foo);
|
||||
|
||||
static int
|
||||
value_add(char *id, char *val, struct value **list)
|
||||
int
|
||||
_sc_value_add(char *id, char *val, struct value **list)
|
||||
{
|
||||
struct value *v;
|
||||
|
||||
@ -31,8 +31,8 @@ value_add(char *id, char *val, struct value **list)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
node_add(char *id, struct value *vallist, struct node *nodelist,
|
||||
int
|
||||
_sc_node_add(char *id, struct value *vallist, struct node *nodelist,
|
||||
struct node **list)
|
||||
{
|
||||
struct node *n;
|
||||
@ -72,7 +72,7 @@ node:
|
||||
struct parser_context *c = NULL;
|
||||
|
||||
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;
|
||||
node_list = c->node_list;
|
||||
context_stack = c->next;
|
||||
@ -84,7 +84,7 @@ node:
|
||||
struct parser_context *c = NULL;
|
||||
|
||||
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;
|
||||
node_list = c->node_list;
|
||||
context_stack = c->next;
|
||||
@ -99,7 +99,7 @@ stuff:
|
||||
|
||||
assign:
|
||||
T_ID T_EQ T_VAL T_SEMI {
|
||||
value_add($1, $3, &val_list);
|
||||
_sc_value_add($1, $3, &val_list);
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
@ -180,7 +180,9 @@ _sc_get(config_info_t *config, const char *key, char *value, size_t valuesz)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ptr[0] == '@') {
|
||||
if (ptr[0] != '@')
|
||||
return 1;
|
||||
|
||||
++ptr;
|
||||
found = 0;
|
||||
|
||||
@ -190,12 +192,81 @@ _sc_get(config_info_t *config, const char *key, char *value, size_t valuesz)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
_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 = {
|
||||
.get = _sc_get,
|
||||
.set = _sc_set,
|
||||
.parse = _sc_parse,
|
||||
.free = _sc_free,
|
||||
.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,
|
||||
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_free_t)(config_info_t *config);
|
||||
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 {
|
||||
config_get_t get;
|
||||
config_set_t set;
|
||||
config_parse_t parse;
|
||||
config_free_t free;
|
||||
config_dump_t dump;
|
||||
@ -27,6 +30,8 @@ typedef struct {
|
||||
*/
|
||||
#define sc_get(obj, 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) \
|
||||
obj->parse(filename, &obj->info)
|
||||
#define sc_free(obj) \
|
||||
|
@ -346,8 +346,12 @@ libvirt_init(backend_context_t *c, config_object_t *config)
|
||||
if (!info)
|
||||
return -1;
|
||||
|
||||
dbg_printf(5, "[%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__);
|
||||
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",
|
||||
value, sizeof(value)) == 0) {
|
||||
uri = strdup(value);
|
||||
|
@ -41,8 +41,7 @@ main(int argc, char **argv)
|
||||
config_file = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
dset(atoi(optarg));
|
||||
debug_set = 1;
|
||||
debug_set = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
@ -54,11 +53,16 @@ main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!debug_set) {
|
||||
if (sc_get(config, "fence_virtd/@debug",
|
||||
val, sizeof(val)) == 0)
|
||||
dset(atoi(val));
|
||||
if (debug_set) {
|
||||
snprintf(val, sizeof(val), "%d", debug_set);
|
||||
sc_set(config, "fence_virtd/@debug", val);
|
||||
} else {
|
||||
if (sc_get(config, "fence_virtd/@debug", val, sizeof(val))==0)
|
||||
debug_set = atoi(val);
|
||||
}
|
||||
|
||||
dset(debug_set);
|
||||
|
||||
if (!foreground) {
|
||||
if (sc_get(config, "fence_virtd/@foreground",
|
||||
val, sizeof(val)) == 0)
|
||||
|
@ -343,6 +343,9 @@ mcast_config(config_object_t *config, mcast_options *args)
|
||||
char value[1024];
|
||||
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",
|
||||
value, sizeof(value)-1) == 0) {
|
||||
dbg_printf(1, "Got %s for key_file\n", value);
|
||||
|
@ -26,9 +26,6 @@
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Local includes */
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
#define NAME "null"
|
||||
#define VERSION "0.8"
|
||||
|
Loading…
Reference in New Issue
Block a user