aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-13 08:44:30 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-13 08:52:46 +0200
commit7fede76c95d658dc745e2fcce51e4d7f9091f0ba (patch)
treeba36dafbe5d506f38fb02cbb479e601ff65cd845 /src
parent78df8f9042140b2c0ecf9d81822d1545841df746 (diff)
downloadwydawca-7fede76c95d658dc745e2fcce51e4d7f9091f0ba.tar.gz
wydawca-7fede76c95d658dc745e2fcce51e4d7f9091f0ba.tar.bz2
Bugfixes. Add a stub for new module.
* include/wydawca/wydawca.h (WY_EXPORT): Add an internal prefix. That's a stupid lossage: having not found the composed name (modname_LTX_sym), libtool tries to look up sym itself, which makes it impossible to use names like "open", etc. * src/module.c (resolve_sym): Reflect the above. Take an extra argument specifying whether the symbol is mandatory. (modules_load): Configure modules used in default_notification list. * src/config (cb_load_path): New callback to ensure that multiple module-path* statements accumulate. * modules/logstat/mod_logstat.c: New file. * modules/logstat/Makefile: New file. * configure.ac: Build modules/logstat/Makefile. * modules/Makefile.am (SUBDIRS): Add logstat.
Diffstat (limited to 'src')
-rw-r--r--src/config.c57
-rw-r--r--src/module.c40
2 files changed, 70 insertions, 27 deletions
diff --git a/src/config.c b/src/config.c
index eef4ee1..f5860d4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1001,13 +1001,13 @@ static struct grecs_keyword spool_kw[] = {
cb_dictionary, NULL, dictionary_kw },
{ "archive", N_("type: string"), N_("Set up archivation"),
grecs_type_section, GRECS_DFLT,
NULL, offsetof(struct spool, archive),
cb_archive, NULL, archive_kw },
{ "notify-event", NULL, N_("Configure notification"),
- grecs_type_section, GRECS_DFLT,
+ grecs_type_section, GRECS_MULT,
NULL, offsetof(struct spool, notification),
cb_notify_event, NULL, notify_event_kw },
{ "check-script", NULL, N_("A /bin/sh script to verify the tarball"),
grecs_type_string, GRECS_DFLT,
NULL, offsetof(struct spool, check_script) },
{ NULL }
@@ -1194,12 +1194,54 @@ cb_locking(enum grecs_callback_command cmd, grecs_node_t *node,
value->v.string, locus);
}
return 0;
}
static int
+cb_load_path(enum grecs_callback_command cmd, grecs_node_t *node,
+ void *varptr, void *cb_data)
+{
+ struct grecs_list **lpp = varptr, *lp;
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+
+ if (*lpp)
+ lp = *lpp;
+ else {
+ lp = _grecs_simple_list_create(1);
+ *lpp = lp;
+ }
+ switch (value->type) {
+ case GRECS_TYPE_STRING:
+ grecs_list_append(lp, grecs_strdup(value->v.string));
+ break;
+
+ case GRECS_TYPE_LIST: {
+ struct grecs_list_entry *ep;
+
+ for (ep = value->v.list->head; ep; ep = ep->next) {
+ const grecs_value_t *vp = ep->data;
+
+ if (vp->type != GRECS_TYPE_STRING) {
+ grecs_error(&vp->locus, 0,
+ _("list element must be a string"));
+ return 1;
+ }
+ grecs_list_append(lp, grecs_strdup(vp->v.string));
+ }
+ break;
+ }
+
+ case GRECS_TYPE_ARRAY:
+ grecs_error(locus, 0, _("too many arguments"));
+ return 1;
+ }
+ return 0;
+}
+
+static int
cb_upload_version(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
unsigned *pversion = varptr, n;
grecs_locus_t *locus = &node->locus;
grecs_value_t *value = node->v.value;
@@ -1237,25 +1279,22 @@ static struct grecs_keyword wydawca_kw[] = {
{ "pidfile", N_("file"), N_("Set pid file name"),
grecs_type_string, GRECS_DFLT, &pidfile },
{ "module-prepend-load-path", N_("path"),
N_("List of directories searched for modules prior to "
"the default module directory"),
- grecs_type_string, GRECS_LIST,
- &module_prepend_load_path },
+ grecs_type_string, GRECS_LIST|GRECS_AGGR,
+ &module_prepend_load_path, 0, cb_load_path },
{ "module-load-path", N_("path"),
N_("List of directories searched for database modules."),
- grecs_type_string, GRECS_LIST,
- &module_load_path },
+ grecs_type_string, GRECS_LIST|GRECS_AGGR,
+ &module_load_path, 0, cb_load_path },
{ "module", N_("name: string> <path: string"),
N_("Load the specified module"),
grecs_type_string, GRECS_MULT, NULL, 0, cb_module },
- { "module", N_("name: string> <path: string"),
- N_("Load the specified module"),
- grecs_type_string, GRECS_MULT, NULL, 0, cb_module },
{ "module-init", N_("modname"),
N_("Module-specific initialization data"),
grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL },
{ "inotify", NULL, N_("Enable or disable inotify support"),
grecs_type_bool, GRECS_DFLT, &inotify_enable },
@@ -1369,13 +1408,13 @@ config_init()
}
void
config_finish(struct grecs_node *tree)
{
struct grecs_node *p;
-
+
if (grecs_tree_process(tree, wydawca_kw))
exit(EX_CONFIG);
for (p = tree->down; p; p = p->next) {
if (strcmp(p->ident, "module-init") == 0) {
if (wy_assert_string_arg(&p->v.value->locus,
grecs_callback_set_value,
diff --git a/src/module.c b/src/module.c
index c009971..33946ee 100644
--- a/src/module.c
+++ b/src/module.c
@@ -84,16 +84,16 @@ cb_module(enum grecs_callback_command cmd, grecs_node_t *node,
modinstall(name->v.string, path->v.string, locus);
return 0;
};
static void *
-resolve_sym(struct module *mod, const char *name)
+resolve_sym(struct module *mod, const char *name, int mustbe)
{
void *sym = lt_dlsym(mod->handle, name);
- if (!sym) {
+ if (!sym && mustbe) {
grecs_error(&mod->locus, 0,
_("module \"%s\" does not define symbol \"%s\""),
mod->name, name);
}
return sym;
}
@@ -114,18 +114,18 @@ modload(struct module *mod, lt_dladvise advise)
grecs_error(&mod->locus, 0,
_("cannot load module %s: %s"), mod->path,
lt_dlerror());
return 1;
}
mod->handle = handle;
- mod->open = resolve_sym(mod, "open");
- mod->close = resolve_sym(mod, "close");
+ mod->open = resolve_sym(mod, "wy_open", 0);
+ mod->close = resolve_sym(mod, "wy_close", 0);
- mod->config = resolve_sym(mod, "config");
- mod->notify = resolve_sym(mod, "notify");
- mod->flush = resolve_sym(mod, "flush");
+ mod->config = resolve_sym(mod, "wy_config", 1);
+ mod->notify = resolve_sym(mod, "wy_notify", 1);
+ mod->flush = resolve_sym(mod, "wy_flush", 0);
if (mod->open) {
if (mod->open(mod->modinit)) {
grecs_error(mod->modinit ? &mod->modinit->locus : NULL,
0,
_("failed to initialize module %s"),
@@ -134,39 +134,42 @@ modload(struct module *mod, lt_dladvise advise)
}
}
return 0;
}
static int
-spoolmodcfg(struct spool *spool, void *unused)
+conf_notification_modules(struct notification *np)
{
- struct notification *np;
-
- for (np = spool->notification; np; np = np->next) {
+ for (; np; np = np->next) {
if (np->modname) {
struct module *mod = modlookup(np->modname);
if (!mod) {
- wy_log(LOG_ERR, "spool %s: no such module: %s",
- spool->tag, np->modname);
+ wy_log(LOG_ERR, "%s: no such module",
+ np->modname);
return 1;
}
- if (mod->config) {
+ if (!np->modcfg && mod->config) {
np->modcfg = mod->config(np->modnode);
if (!np->modcfg) {
wy_log(LOG_ERR,
- "spool %s: failed to configure "
- "module \"%s\"",
- spool->tag, np->modname);
+ "%s: failed to configure",
+ np->modname);
return 1;
}
}
}
}
return 0;
}
+static int
+spoolmodcfg(struct spool *spool, void *unused)
+{
+ return conf_notification_modules(spool->notification);
+}
+
void
modules_load()
{
lt_dladvise advise = NULL;
struct grecs_list_entry *ep;
struct module *mod;
@@ -204,12 +207,13 @@ modules_load()
if (for_each_spool(spoolmodcfg, NULL)) {
wy_log(LOG_CRIT,
_("some modules failed to configure, exiting"));
exit(EX_UNAVAILABLE);
}
+ conf_notification_modules(default_notification);
}
void
modules_close()
{
struct module *mod;
@@ -287,13 +291,13 @@ module_help(const char *modname)
if (modload(&mod, advise))
exit(EX_UNAVAILABLE);
lt_dladvise_destroy(&advise);
- help = resolve_sym(&mod, "help");
+ help = resolve_sym(&mod, "wy_help", 0);
if (!help)
wy_log(LOG_NOTICE, "no help for %s", modname);
else
help();
lt_dlclose(mod.handle);

Return to:

Send suggestions and report system problems to the System administrator.