summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-22 22:54:27 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-12-22 22:54:27 (GMT)
commit0077bc419d34a0341f978fc0e2d5cba8d35d4b28 (patch) (unidiff)
treef5cb831a306e99dce9a8c5af1b4be55cf7dbb658
parent67a64a6a7809c183516740696e15ab88f82d7ef0 (diff)
downloadwydawca-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.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--src/config.c8
-rw-r--r--src/gpg.c43
-rw-r--r--src/job.c5
-rw-r--r--src/triplet.c3
-rw-r--r--src/verify.c3
-rw-r--r--src/watcher.c16
-rw-r--r--src/wydawca.c2
-rw-r--r--src/wydawca.h3
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[] = {
1158 grecs_type_string, GRECS_DFLT, 1158 grecs_type_string, GRECS_DFLT,
1159 NULL, offsetof(struct spool, file_sweep_time), 1159 NULL, offsetof(struct spool, file_sweep_time),
1160 cb_interval }, 1160 cb_interval },
1161 { "inotify", NULL, N_("Enable or disable inotify for this spool"),
1162 grecs_type_bool, GRECS_DFLT,
1163 NULL, offsetof(struct spool, inotify_enable), },
1164
1161 { "dictionary", N_("ident"), N_("Define data dictionary"), 1165 { "dictionary", N_("ident"), N_("Define data dictionary"),
1162 grecs_type_section, GRECS_DFLT, 1166 grecs_type_section, GRECS_DFLT,
1163 NULL, offsetof(struct spool, dictionary), 1167 NULL, offsetof(struct spool, dictionary),
@@ -1200,6 +1204,7 @@ cb_spool (enum grecs_callback_command cmd,
1200 spool = grecs_zalloc (sizeof (*spool)); 1204 spool = grecs_zalloc (sizeof (*spool));
1201 spool->tag = grecs_strdup (value->v.string); 1205 spool->tag = grecs_strdup (value->v.string);
1202 spool->file_sweep_time = file_sweep_time; 1206 spool->file_sweep_time = file_sweep_time;
1207 spool->inotify_enable = 1;
1203 for (i = 0; i < NITEMS (spool->dictionary); i++) 1208 for (i = 0; i < NITEMS (spool->dictionary); i++)
1204 spool->dictionary[i] = default_dictionary[i]; 1209 spool->dictionary[i] = default_dictionary[i];
1205 spool->archive = default_archive_descr; 1210 spool->archive = default_archive_descr;
@@ -1419,6 +1424,9 @@ static struct grecs_keyword wydawca_kw[] = {
1419 { "pidfile", N_("file"), N_("Set pid file name"), 1424 { "pidfile", N_("file"), N_("Set pid file name"),
1420 grecs_type_string, GRECS_DFLT, &pidfile }, 1425 grecs_type_string, GRECS_DFLT, &pidfile },
1421 1426
1427 { "inotify", NULL, N_("Enable or disable inotify support"),
1428 grecs_type_bool, GRECS_DFLT, &inotify_enable },
1429
1422 { "user", N_("name"), N_("Run with UID and GID of this user"), 1430 { "user", N_("name"), N_("Run with UID and GID of this user"),
1423 grecs_type_string, GRECS_DFLT, NULL, 0, cb_user }, 1431 grecs_type_string, GRECS_DFLT, NULL, 0, cb_user },
1424 { "group", NULL, N_("Retain these supplementary groups"), 1432 { "group", NULL, N_("Retain these supplementary groups"),
diff --git a/src/gpg.c b/src/gpg.c
index 8979e9c..814be6f 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -147,22 +147,8 @@ create_gpg_homedir ()
147} 147}
148 148
149static int 149static int
150gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig, 150checksig (gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
151 struct file_triplet *trp)
152{ 151{
153 if (!sig)
154 return 0;
155
156 for (; sig; sig = sig->next)
157 {
158 const char *uid;
159 gpgme_key_t key;
160
161 if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR)
162 uid = key->uids->uid;
163 else
164 uid = sig->fpr;
165
166 switch (gpg_err_code (sig->status)) 152 switch (gpg_err_code (sig->status))
167 { 153 {
168 case GPG_ERR_NO_ERROR: 154 case GPG_ERR_NO_ERROR:
@@ -208,6 +194,30 @@ gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig,
208 logmsg (LOG_ERR, _("Unknown signature error")); 194 logmsg (LOG_ERR, _("Unknown signature error"));
209 return 0; 195 return 0;
210 } 196 }
197 return -1;
198}
199
200static int
201gpg_verify_signature (gpgme_ctx_t ctx, gpgme_signature_t sig,
202 struct file_triplet *trp)
203{
204 if (!sig)
205 return 0;
206
207 for (; sig; sig = sig->next)
208 {
209 const char *uid;
210 gpgme_key_t key;
211 int rc;
212
213 if (gpgme_get_key (ctx, sig->fpr, &key, 0) == GPG_ERR_NO_ERROR)
214 uid = key->uids->uid;
215 else
216 uid = sig->fpr;
217 rc = checksig (sig, uid, trp);
218 gpgme_key_unref (key);
219 if (rc != -1)
220 return rc;
211 } 221 }
212 return 1; 222 return 1;
213} 223}
@@ -217,7 +227,7 @@ int
217verify_directive_signature (struct file_triplet *trp) 227verify_directive_signature (struct file_triplet *trp)
218{ 228{
219 gpgme_ctx_t ctx; 229 gpgme_ctx_t ctx;
220 gpgme_data_t key_data, directive_data, plain; 230 gpgme_data_t key_data, directive_data, plain = NULL;
221 gpgme_error_t ec; 231 gpgme_error_t ec;
222 int rc; 232 int rc;
223 struct uploader_info *uptr; 233 struct uploader_info *uptr;
@@ -269,6 +279,7 @@ verify_directive_signature (struct file_triplet *trp)
269 trp->name, gpgme_strerror (ec)); 279 trp->name, gpgme_strerror (ec));
270 } 280 }
271 281
282 gpgme_data_release (plain);
272 gpgme_data_release (directive_data); 283 gpgme_data_release (directive_data);
273 gpgme_data_release (key_data); 284 gpgme_data_release (key_data);
274 gpgme_release (ctx); 285 gpgme_release (ctx);
diff --git a/src/job.c b/src/job.c
index 3fae432..315303f 100644
--- a/src/job.c
+++ b/src/job.c
@@ -338,7 +338,12 @@ job_queue_runner ()
338 job->timestamp = now + interval; 338 job->timestamp = now + interval;
339 } 339 }
340 else 340 else
341 {
341 job_remove (job); 342 job_remove (job);
343 free (job);
344 job = next;
345 continue;
346 }
342 } 347 }
343 } 348 }
344 349
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)
127 memcpy (key.name, finfo.name, finfo.root_len); 127 memcpy (key.name, finfo.name, finfo.root_len);
128 key.name[finfo.root_len] = 0; 128 key.name[finfo.root_len] = 0;
129 key.spool = spool; 129 key.spool = spool;
130 file_info_cleanup (&finfo);
130 131
131 ret = grecs_symtab_lookup_or_install (triplet_table, &key, NULL); 132 ret = grecs_symtab_lookup_or_install (triplet_table, &key, NULL);
132 file_info_cleanup (&finfo); 133 free (key.name);
133 134
134 return ret; 135 return ret;
135} 136}
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)
97 const char *directory; 97 const char *directory;
98 int rc; 98 int rc;
99 99
100 if (trp->blurb)
101 return 0;
102
100 size = trp->file[file_directive].sb.st_size; 103 size = trp->file[file_directive].sb.st_size;
101 if (size <= MSG_BEGIN_MARKER_LEN) 104 if (size <= MSG_BEGIN_MARKER_LEN)
102 { 105 {
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)
84 if (!sp) 84 if (!sp)
85 return 0; 85 return 0;
86 86
87 if (!sp->inotify_enable)
88 {
89 if (debug_level > 1)
90 logmsg (LOG_DEBUG, "disabling inotify support for spool %s", sp->tag);
91 return 0;
92 }
93
87 if (debug_level > 1) 94 if (debug_level > 1)
88 logmsg (LOG_DEBUG, "creating watcher %s", path); 95 logmsg (LOG_DEBUG, "spool %s: creating watcher %s", sp->tag, path);
89 dwp = malloc (sizeof(*dwp)); 96 dwp = malloc (sizeof(*dwp));
90 if (!dwp) 97 if (!dwp)
91 { 98 {
@@ -114,6 +121,13 @@ watcher_init ()
114{ 121{
115 int ifd, rc; 122 int ifd, rc;
116 123
124 if (!inotify_enable)
125 {
126 if (debug_level > 1)
127 logmsg (LOG_DEBUG, "disabling inotify support");
128 return -1;
129 }
130
117 if (debug_level > 1) 131 if (debug_level > 1)
118 logmsg (LOG_DEBUG, "setting up inotify"); 132 logmsg (LOG_DEBUG, "setting up inotify");
119 ifd = inotify_init (); 133 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];
53unsigned min_directive_version = MIN_DIRECTIVE_VERSION; 53unsigned min_directive_version = MIN_DIRECTIVE_VERSION;
54unsigned max_directive_version = MAX_DIRECTIVE_VERSION; 54unsigned max_directive_version = MAX_DIRECTIVE_VERSION;
55 55
56int inotify_enable = 1;
57
56void 58void
57initstats () 59initstats ()
58{ 60{
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
226 mu_url_t dest_url; /* Destination URL */ 226 mu_url_t dest_url; /* Destination URL */
227 const char *dest_dir; /* Directory part of the above */ 227 const char *dest_dir; /* Directory part of the above */
228 struct virt_tab vtab; /* Virtual method table */ 228 struct virt_tab vtab; /* Virtual method table */
229 int inotify_enable;
229 230
230 time_t file_sweep_time; /* Remove invalid/unprocessed files 231 time_t file_sweep_time; /* Remove invalid/unprocessed files
231 after this amount of time */ 232 after this amount of time */
@@ -377,6 +378,8 @@ extern unsigned max_directive_version;
377extern struct spool fake_spool; 378extern struct spool fake_spool;
378extern struct spool inotify_spool; 379extern struct spool inotify_spool;
379 380
381extern int inotify_enable;
382
380 #define UPDATE_STATS(what) \ 383 #define UPDATE_STATS(what) \
381 do \ 384 do \
382 { \ 385 { \

Return to:

Send suggestions and report system problems to the System administrator.