Thread: [srvx-commits] CVS: services/src main.c,1.137,1.138 saxdb.c,1.13,1.14
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-09-08 04:28:40
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv17662/src
Modified Files:
main.c saxdb.c
Log Message:
fix possible crash when writing modcmd database as part of mondo database
Index: main.c
===================================================================
RCS file: /cvsroot/srvx/services/src/main.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -C2 -r1.137 -r1.138
*** main.c 5 Sep 2002 14:54:46 -0000 1.137
--- main.c 8 Sep 2002 04:28:38 -0000 1.138
***************
*** 758,764 ****
reg_exit_func(main_shutdown);
modcmd_init();
saxdb_init();
- timeq_init();
gline_init();
sendmail_init();
--- 758,764 ----
reg_exit_func(main_shutdown);
+ timeq_init();
modcmd_init();
saxdb_init();
gline_init();
sendmail_init();
Index: saxdb.c
===================================================================
RCS file: /cvsroot/srvx/services/src/saxdb.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** saxdb.c 7 Sep 2002 02:32:20 -0000 1.13
--- saxdb.c 8 Sep 2002 04:28:38 -0000 1.14
***************
*** 48,56 ****
static struct saxdb *last_db;
- static struct saxdb *mondo_db;
static struct dict *saxdbs; /* -> struct saxdb */
! static struct dict *mondo_sections; /* -> struct saxdb */
static struct module *saxdb_module;
! static int use_mondo;
static void
--- 48,57 ----
static struct saxdb *last_db;
static struct dict *saxdbs; /* -> struct saxdb */
! static struct dict *mondo_db;
static struct module *saxdb_module;
!
! static SAXDB_WRITER(saxdb_mondo_writer);
! static void saxdb_timed_write(void *data);
static void
***************
*** 62,74 ****
data = parse_database(db->filename);
if (!data) return;
! db->reader(data);
! free_database(data);
}
struct saxdb *
saxdb_register(const char *name, saxdb_reader_func_t *reader, saxdb_writer_func_t *writer) {
- char mondo_path[MAXLEN];
struct saxdb *db;
int ii;
db = calloc(1, sizeof(*db));
--- 63,81 ----
data = parse_database(db->filename);
if (!data) return;
! if (db->writer == saxdb_mondo_writer) {
! mondo_db = data;
! } else {
! db->reader(data);
! free_database(data);
! }
}
struct saxdb *
saxdb_register(const char *name, saxdb_reader_func_t *reader, saxdb_writer_func_t *writer) {
struct saxdb *db;
+ struct dict *conf;
int ii;
+ const char *filename = NULL, *str;
+ char conf_path[MAXLEN];
db = calloc(1, sizeof(*db));
***************
*** 76,85 ****
db->reader = reader;
db->writer = writer;
! db->filename = malloc(strlen(db->name)+4);
! for (ii=0; db->name[ii]; ++ii) db->filename[ii] = tolower(db->name[ii]);
! strcpy(db->filename+ii, ".db");
dict_insert(saxdbs, db->name, db);
- sprintf(mondo_path, "dbs/%s/mondo_section", name);
- if (reader && !conf_get_data(mondo_path, RECDB_QSTRING)) saxdb_read_db(db);
db->prev = last_db;
last_db = db;
--- 83,117 ----
db->reader = reader;
db->writer = writer;
! /* Look up configuration */
! sprintf(conf_path, "dbs/%s", name);
! if ((conf = conf_get_data(conf_path, RECDB_OBJECT))) {
! if ((str = database_get_data(conf, "mondo_section", RECDB_QSTRING))) {
! db->mondo_section = strdup(str);
! }
! str = database_get_data(conf, "frequency", RECDB_QSTRING);
! db->write_interval = str ? ParseInterval(str) : 1800;
! if (db->write_interval && !db->mondo_section) {
! timeq_add(now + db->write_interval, saxdb_timed_write, db);
! }
! filename = database_get_data(conf, "filename", RECDB_QSTRING);
! }
! /* Insert filename */
! if (filename) {
! db->filename = strdup(filename);
! } else {
! db->filename = malloc(strlen(db->name)+4);
! for (ii=0; db->name[ii]; ++ii) db->filename[ii] = tolower(db->name[ii]);
! strcpy(db->filename+ii, ".db");
! }
! /* Read from disk (or mondo DB) */
! if (db->mondo_section) {
! if ((conf = database_get_data(mondo_db, db->mondo_section, RECDB_OBJECT))) {
! db->reader(conf);
! }
! } else {
! saxdb_read_db(db);
! }
! /* Remember the database */
dict_insert(saxdbs, db->name, db);
db->prev = last_db;
last_db = db;
***************
*** 291,295 ****
saxdb_mondo_write(struct saxdb_context *ctx, struct saxdb *saxdb) {
int res;
! if (saxdb->prev && (res = saxdb_mondo_write(ctx, saxdb->prev))) return res;
if (saxdb->mondo_section) {
saxdb_start_record(ctx, saxdb->mondo_section, 1);
--- 323,331 ----
saxdb_mondo_write(struct saxdb_context *ctx, struct saxdb *saxdb) {
int res;
! if (saxdb->prev) {
! if ((res = saxdb_mondo_write(ctx, saxdb->prev))) return res;
! /* cheat a little here to put a newline between mondo sections */
! saxdb_put_char(ctx, '\n');
! }
if (saxdb->mondo_section) {
saxdb_start_record(ctx, saxdb->mondo_section, 1);
***************
*** 299,304 ****
}
saxdb_end_record(ctx);
- /* cheat a little here to put a newline between mondo sections */
- saxdb_put_char(ctx, '\n');
}
return 0;
--- 335,338 ----
***************
*** 309,355 ****
}
- static void
- saxdb_conf_read(void) {
- struct dict *conf;
- struct dict *node;
- struct record_data *rd;
- struct saxdb *db;
- dict_iterator_t it;
- char *str;
-
- conf = conf_get_data("dbs", RECDB_OBJECT);
- if (!conf) return;
- timeq_del(0, saxdb_timed_write, 0, TIMEQ_IGNORE_WHEN|TIMEQ_IGNORE_DATA);
- dict_delete(mondo_sections);
- mondo_sections = dict_new();
- use_mondo = 0;
- for (it = dict_first(conf); it; it = iter_next(it)) {
- rd = iter_data(it);
- if (rd->type != RECDB_OBJECT) continue;
- if (!(db = dict_find(saxdbs, iter_key(it), NULL))) continue;
- node = rd->d.object;
- free(db->mondo_section);
- db->mondo_section = NULL;
- free(db->filename);
- db->filename = NULL;
- if ((str = database_get_data(node, "mondo_section", RECDB_QSTRING))) {
- db->mondo_section = strdup(str);
- dict_insert(mondo_sections, db->mondo_section, db);
- use_mondo = 1;
- }
- if ((str = database_get_data(node, "filename", RECDB_QSTRING))) {
- db->filename = strdup(str);
- } else if (!db->mondo_section) {
- db->filename = malloc(strlen(iter_key(it)) + 4);
- sprintf(db->filename, "%s.db", iter_key(it));
- }
- str = database_get_data(node, "frequency", RECDB_QSTRING);
- db->write_interval = str ? ParseInterval(str) : 1800;
- if (db->write_interval && !db->mondo_section) {
- timeq_add(now + db->write_interval, saxdb_timed_write, db);
- }
- }
- }
-
static MODCMD_FUNC(cmd_write) {
struct timeval start, stop;
--- 343,346 ----
***************
*** 406,410 ****
saxdb_cleanup(void) {
dict_delete(saxdbs);
- dict_delete(mondo_sections);
}
--- 397,400 ----
***************
*** 438,443 ****
saxdbs = dict_new();
dict_set_free_data(saxdbs, saxdb_free);
! mondo_db = saxdb_register("mondo", NULL, saxdb_mondo_writer);
! mondo_db->reader = saxdb_mondo_reader;
saxdb_module = module_register("saxdb", MAIN_LOG, "saxdb.help", saxdb_expand_help);
modcmd_register(saxdb_module, "write", cmd_write, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
--- 428,432 ----
saxdbs = dict_new();
dict_set_free_data(saxdbs, saxdb_free);
! saxdb_register("mondo", saxdb_mondo_reader, saxdb_mondo_writer);
saxdb_module = module_register("saxdb", MAIN_LOG, "saxdb.help", saxdb_expand_help);
modcmd_register(saxdb_module, "write", cmd_write, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
***************
*** 445,451 ****
}
! void saxdb_finalize(void) {
! conf_register_reload(saxdb_conf_read);
! if (use_mondo) saxdb_read_db(mondo_db);
}
--- 434,440 ----
}
! void
! saxdb_finalize(void) {
! free_database(mondo_db);
}
|