diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-23 00:54:27 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-23 00:54:27 +0200 |
commit | 0077bc419d34a0341f978fc0e2d5cba8d35d4b28 (patch) | |
tree | f5cb831a306e99dce9a8c5af1b4be55cf7dbb658 | |
parent | 67a64a6a7809c183516740696e15ab88f82d7ef0 (diff) | |
download | wydawca-0077bc419d34a0341f978fc0e2d5cba8d35d4b28.tar.gz wydawca-0077bc419d34a0341f978fc0e2d5cba8d35d4b28.tar.bz2 |
Fix memory leaks, provide config statements for disabling inotify.
* src/config.c: New statement "inotify" (global and
spool-specific).
* src/gpg.c (gpg_verify_signature): Free key when
no longer needed.
(verify_directive_signature): Fix memory leak.
* src/job.c (job_queue_runner): Free the unlinked job.
* src/triplet.c (triplet_lookup): Free key.name.
* src/verify.c (fill_project_name): Return immediately if
trp->blurb is not null.
* src/watcher.c (create_watcher): Ignore spool if its
inotify_enable is false.
(watcher_init): Return immediately if inotify_enable is
false.
* src/wydawca.c (inotify_enable): New global.
* src/wydawca.h: Likewise.
-rw-r--r-- | src/config.c | 8 | ||||
-rw-r--r-- | src/gpg.c | 43 | ||||
-rw-r--r-- | src/job.c | 5 | ||||
-rw-r--r-- | src/triplet.c | 3 | ||||
-rw-r--r-- | src/verify.c | 3 | ||||
-rw-r--r-- | src/watcher.c | 16 | ||||
-rw-r--r-- | src/wydawca.c | 2 | ||||
-rw-r--r-- | src/wydawca.h | 3 |
8 files changed, 65 insertions, 18 deletions
diff --git a/src/config.c b/src/config.c index 66d5fb7..509b0d5 100644 --- a/src/config.c +++ b/src/config.c @@ -1158,6 +1158,10 @@ static struct grecs_keyword spool_kw[] = { grecs_type_string, GRECS_DFLT, NULL, offsetof(struct spool, file_sweep_time), cb_interval }, + { "inotify", NULL, N_("Enable or disable inotify for this spool"), + grecs_type_bool, GRECS_DFLT, + NULL, offsetof(struct spool, inotify_enable), }, + { "dictionary", N_("ident"), N_("Define data dictionary"), grecs_type_section, GRECS_DFLT, NULL, offsetof(struct spool, dictionary), @@ -1200,6 +1204,7 @@ cb_spool (enum grecs_callback_command cmd, spool = grecs_zalloc (sizeof (*spool)); spool->tag = grecs_strdup (value->v.string); spool->file_sweep_time = file_sweep_time; + spool->inotify_enable = 1; for (i = 0; i < NITEMS (spool->dictionary); i++) spool->dictionary[i] = default_dictionary[i]; spool->archive = default_archive_descr; @@ -1419,6 +1424,9 @@ static struct grecs_keyword wydawca_kw[] = { { "pidfile", N_("file"), N_("Set pid file name"), grecs_type_string, GRECS_DFLT, &pidfile }, + { "inotify", NULL, N_("Enable or disable inotify support"), + grecs_type_bool, GRECS_DFLT, &inotify_enable }, + { "user", N_("name"), N_("Run with UID and GID of this user"), grecs_type_string, GRECS_DFLT, NULL, 0, cb_user }, { "group", NULL, N_("Retain these supplementary groups"), @@ -147,22 +147,8 @@ create_gpg_homedir () } static int -gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, - struct file_triplet *trp) +checksig (gpgme_signature_t sig, const char *uid, struct file_triplet *trp) { - if (!sig) - return 0; - - for (; sig; sig = sig->next) - { - const char *uid; - gpgme_key_t key; - - if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR) - uid = key->uids->uid; - else - uid = sig->fpr; - switch (gpg_err_code (sig->status)) { case GPG_ERR_NO_ERROR: @@ -208,6 +194,30 @@ gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, logmsg (LOG_ERR, _("Unknown signature error")); return 0; } + return -1; +} + +static int +gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, + struct file_triplet *trp) +{ + if (!sig) + return 0; + + for (; sig; sig = sig->next) + { + const char *uid; + gpgme_key_t key; + int rc; + + if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR) + uid = key->uids->uid; + else + uid = sig->fpr; + rc = checksig (sig, uid, trp); + gpgme_key_unref (key); + if (rc != -1) + return rc; } return 1; } @@ -217,7 +227,7 @@ int verify_directive_signature (struct file_triplet *trp) { gpgme_ctx_t ctx; - gpgme_data_t key_data, directive_data, plain; + gpgme_data_t key_data, directive_data, plain = NULL; gpgme_error_t ec; int rc; struct uploader_info *uptr; @@ -269,6 +279,7 @@ verify_directive_signature (struct file_triplet *trp) trp->name, gpgme_strerror (ec)); } + gpgme_data_release (plain); gpgme_data_release (directive_data); gpgme_data_release (key_data); gpgme_release (ctx); @@ -338,7 +338,12 @@ job_queue_runner () job->timestamp = now + interval; } else + { job_remove (job); + free (job); + job = next; + continue; + } } } diff --git a/src/triplet.c b/src/triplet.c index 05b7536..aa74de0 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -127,9 +127,10 @@ triplet_lookup (struct spool *spool, const char *name) memcpy (key.name, finfo.name, finfo.root_len); key.name[finfo.root_len] = 0; key.spool = spool; + file_info_cleanup (&finfo); ret = grecs_symtab_lookup_or_install (triplet_table, &key, NULL); - file_info_cleanup (&finfo); + free (key.name); return ret; } diff --git a/src/verify.c b/src/verify.c index 4a108bc..dee160f 100644 --- a/src/verify.c +++ b/src/verify.c @@ -97,6 +97,9 @@ fill_project_name (struct file_triplet *trp) const char *directory; int rc; + if (trp->blurb) + return 0; + size = trp->file[file_directive].sb.st_size; if (size <= MSG_BEGIN_MARKER_LEN) { diff --git a/src/watcher.c b/src/watcher.c index f8761ee..c52e3e6 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -84,8 +84,15 @@ create_watcher (struct spool *sp, void *data) if (!sp) return 0; + if (!sp->inotify_enable) + { + if (debug_level > 1) + logmsg (LOG_DEBUG, "disabling inotify support for spool %s", sp->tag); + return 0; + } + if (debug_level > 1) - logmsg (LOG_DEBUG, "creating watcher %s", path); + logmsg (LOG_DEBUG, "spool %s: creating watcher %s", sp->tag, path); dwp = malloc (sizeof(*dwp)); if (!dwp) { @@ -114,6 +121,13 @@ watcher_init () { int ifd, rc; + if (!inotify_enable) + { + if (debug_level > 1) + logmsg (LOG_DEBUG, "disabling inotify support"); + return -1; + } + if (debug_level > 1) logmsg (LOG_DEBUG, "setting up inotify"); ifd = inotify_init (); diff --git a/src/wydawca.c b/src/wydawca.c index 521d796..45a5cff 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -53,6 +53,8 @@ unsigned wydawca_stat[MAX_STAT]; unsigned min_directive_version = MIN_DIRECTIVE_VERSION; unsigned max_directive_version = MAX_DIRECTIVE_VERSION; +int inotify_enable = 1; + void initstats () { diff --git a/src/wydawca.h b/src/wydawca.h index 722fc9b..323d403 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -226,6 +226,7 @@ struct spool mu_url_t dest_url; /* Destination URL */ const char *dest_dir; /* Directory part of the above */ struct virt_tab vtab; /* Virtual method table */ + int inotify_enable; time_t file_sweep_time; /* Remove invalid/unprocessed files after this amount of time */ @@ -377,6 +378,8 @@ extern unsigned max_directive_version; extern struct spool fake_spool; extern struct spool inotify_spool; +extern int inotify_enable; + #define UPDATE_STATS(what) \ do \ { \ |