diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-07-22 14:53:37 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-07-22 14:53:37 +0300 |
commit | b369ed6ad26c07d3aec65a1bf0910c0d828c400f (patch) | |
tree | 525b13a5bbda244cbec3fe10c25c47aa2975e2a5 /src | |
parent | 0917d1276103d9cc893e8ac091e9e63c5e6182f8 (diff) | |
download | wydawca-b369ed6ad26c07d3aec65a1bf0910c0d828c400f.tar.gz wydawca-b369ed6ad26c07d3aec65a1bf0910c0d828c400f.tar.bz2 |
Finish mod_logstat implementation. Document it.
* doc/wydawca.texi: Document mod_logstat.
* include/wydawca/wydawca.h (wy_ev_statistics): Rename to
wy_ev_finish. All uses changed.
(wydawca_stat): New enum (from src/wydawca.h)
(WY_STAT_MASK,WY_STAT_MASK_NONE)
(WY_STAT_MASK_ALL): New macros.
All uses changed.
* modules/logstat/mod_logstat.c (stat_mask): Default to WY_STAT_MASK_ALL.
(wy_notify): Provide default output.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 34 | ||||
-rw-r--r-- | src/directive.c | 6 | ||||
-rw-r--r-- | src/diskio.c | 14 | ||||
-rw-r--r-- | src/event.c | 4 | ||||
-rw-r--r-- | src/gpg.c | 16 | ||||
-rw-r--r-- | src/null.c | 8 | ||||
-rw-r--r-- | src/triplet.c | 6 | ||||
-rw-r--r-- | src/wydawca.c | 24 | ||||
-rw-r--r-- | src/wydawca.h | 29 |
9 files changed, 58 insertions, 83 deletions
diff --git a/src/config.c b/src/config.c index f6305c5..0d7da22 100644 --- a/src/config.c +++ b/src/config.c @@ -217,7 +217,7 @@ static struct keyword event_tab[] = { { "bad-directive-signature", wy_ev_bad_directive_signature }, { "bad-detached-signature", wy_ev_bad_detached_signature }, { "check-failure", wy_ev_check_fail }, - { "statistics", wy_ev_statistics }, + { "finish", wy_ev_finish }, {NULL} }; @@ -351,19 +351,19 @@ cb_set_umask(enum grecs_callback_command cmd, } static struct keyword stat_tab[] = { - { "errors", STAT_ERRORS }, - { "warnings", STAT_WARNINGS }, - { "bad-signatures", STAT_BAD_SIGNATURE }, - { "access-violations", STAT_ACCESS_VIOLATIONS }, - { "complete-triplets", STAT_COMPLETE_TRIPLETS }, - { "incomplete-triplets", STAT_INCOMPLETE_TRIPLETS }, - { "bad-triplets", STAT_BAD_TRIPLETS }, - { "expired-triplets", STAT_EXPIRED_TRIPLETS }, - { "triplet-success", STAT_TRIPLET_SUCCESS }, - { "uploads", STAT_UPLOADS }, - { "archives", STAT_ARCHIVES }, - { "symlinks", STAT_SYMLINKS }, - { "rmsymlinks", STAT_RMSYMLINKS }, + { "errors", WY_STAT_ERRORS }, + { "warnings", WY_STAT_WARNINGS }, + { "bad-signatures", WY_STAT_BAD_SIGNATURE }, + { "access-violations", WY_STAT_ACCESS_VIOLATIONS }, + { "complete-triplets", WY_STAT_COMPLETE_TRIPLETS }, + { "incomplete-triplets", WY_STAT_INCOMPLETE_TRIPLETS }, + { "bad-triplets", WY_STAT_BAD_TRIPLETS }, + { "expired-triplets", WY_STAT_EXPIRED_TRIPLETS }, + { "triplet-success", WY_STAT_TRIPLET_SUCCESS }, + { "uploads", WY_STAT_UPLOADS }, + { "archives", WY_STAT_ARCHIVES }, + { "symlinks", WY_STAT_SYMLINKS }, + { "rmsymlinks", WY_STAT_RMSYMLINKS }, { NULL }, }; @@ -383,11 +383,11 @@ parse_single_statmask(grecs_locus_t *locus, const grecs_value_t *val, arg = val->v.string; if (strcmp(arg, "all") == 0) { - *pmask = STAT_MASK_ALL; + *pmask = WY_STAT_MASK_ALL; *invert = 1; return 0; } else if (strcmp(arg, "none") == 0) { - *pmask = STAT_MASK_NONE; + *pmask = WY_STAT_MASK_NONE; *invert = 0; return 0; } @@ -397,7 +397,7 @@ parse_single_statmask(grecs_locus_t *locus, const grecs_value_t *val, arg); return 1; } - *pmask = STAT_MASK(x); + *pmask = WY_STAT_MASK(x); return 0; } diff --git a/src/directive.c b/src/directive.c index 5dd1724..8ce1ca2 100644 --- a/src/directive.c +++ b/src/directive.c @@ -559,7 +559,7 @@ external_check(struct wy_triplet *trp) free(file); if (rc) { - UPDATE_STATS(STAT_CHECK_FAIL); + UPDATE_STATS(WY_STAT_CHECK_FAIL); notify(spool->notification, trp, wy_ev_check_fail); } @@ -599,7 +599,7 @@ process_directives(struct wy_triplet *trp) const struct spool *spool; ASGN_SPOOL(spool, trp, return 1); - UPDATE_STATS(STAT_COMPLETE_TRIPLETS); + UPDATE_STATS(WY_STAT_COMPLETE_TRIPLETS); timer_start("triplet"); report_init(); for (n = directive_first(trp, &key, &val); n; @@ -671,7 +671,7 @@ process_directives(struct wy_triplet *trp) trp->file[file_directive].name, strerror(errno)); } - UPDATE_STATS(STAT_TRIPLET_SUCCESS); + UPDATE_STATS(WY_STAT_TRIPLET_SUCCESS); report_finish(); timer_stop("triplet"); notify(spool->notification, trp, wy_ev_success); diff --git a/src/diskio.c b/src/diskio.c index 7916b3f..a86997e 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -237,7 +237,7 @@ tar_append_file(const char *archive, const char *file) wy_debug(1, (_("tarring %s to %s"), file, archive)); if (wy_dry_run) { - UPDATE_STATS(STAT_ARCHIVES); + UPDATE_STATS(WY_STAT_ARCHIVES); return 0; } @@ -250,7 +250,7 @@ tar_append_file(const char *archive, const char *file) switch (wydawca_exec(6, argv, NULL)) { case exec_success: - UPDATE_STATS(STAT_ARCHIVES); + UPDATE_STATS(WY_STAT_ARCHIVES); return 0; case exec_fail: @@ -351,13 +351,13 @@ do_archive_file(const char *dst_file, const char *dst_dir, const char *file, case archive_directory: if (backup_file(dst_file, dst_dir, file, archive, reldir)) return 1; - UPDATE_STATS(STAT_ARCHIVES); + UPDATE_STATS(WY_STAT_ARCHIVES); break; case archive_tar: if (tar_append_file(archive->name, dst_file)) return 1; - UPDATE_STATS(STAT_ARCHIVES); + UPDATE_STATS(WY_STAT_ARCHIVES); break; } @@ -431,7 +431,7 @@ dir_move_file(struct wy_triplet *trp, enum file_type file_id) free(dst_file); free(dst_dir); if (rc == 0) - UPDATE_STATS(STAT_UPLOADS); + UPDATE_STATS(WY_STAT_UPLOADS); return rc; } @@ -616,7 +616,7 @@ dir_symlink_file(struct wy_triplet *trp, free(dst); free(dst_dir); if (rc == 0) - UPDATE_STATS(STAT_SYMLINKS); + UPDATE_STATS(WY_STAT_SYMLINKS); return rc; } @@ -648,7 +648,7 @@ do_rmsymlink_file(const char *dst_file, int noentok) strerror(errno)); return 1; } - UPDATE_STATS(STAT_RMSYMLINKS); + UPDATE_STATS(WY_STAT_RMSYMLINKS); return 0; } diff --git a/src/event.c b/src/event.c index 11e902a..d359814 100644 --- a/src/event.c +++ b/src/event.c @@ -28,9 +28,9 @@ notify(struct notification *n, struct wy_triplet *t, } void -notify_stats() +notify_finish() { - notify(default_notification, NULL, wy_ev_statistics); + notify(default_notification, NULL, wy_ev_finish); } void @@ -152,27 +152,27 @@ checksig(gpgme_signature_t sig, const char *uid, struct wy_triplet *trp) break; case GPG_ERR_BAD_SIGNATURE: - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("BAD signature from %s"), uid); return 0; case GPG_ERR_NO_PUBKEY: - UPDATE_STATS(STAT_ACCESS_VIOLATIONS); + UPDATE_STATS(WY_STAT_ACCESS_VIOLATIONS); wy_log(LOG_ERR, _("No public key")); return 0; case GPG_ERR_NO_DATA: - UPDATE_STATS(STAT_BAD_TRIPLETS); + UPDATE_STATS(WY_STAT_BAD_TRIPLETS); wy_log(LOG_ERR, _("No signature")); return 0; case GPG_ERR_SIG_EXPIRED: - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("Expired signature from %s"), uid); return 0; case GPG_ERR_KEY_EXPIRED: - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("Key expired (%s)"), uid); return 0; @@ -245,7 +245,7 @@ verify_directive_signature(struct wy_triplet *trp) result = gpgme_op_verify_result(ctx); if (!gpg_verify_signature(ctx, result->signatures, trp)) { - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); notify(trp->spool->notification, trp, wy_ev_bad_directive_signature); rc = 1; @@ -253,7 +253,7 @@ verify_directive_signature(struct wy_triplet *trp) rc = 0; } else { rc = 1; - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("%s: directive verification failed: %s"), trp->name, gpgme_strerror(ec)); } @@ -301,7 +301,7 @@ verify_detached_signature(struct wy_triplet *trp) return 0; case exec_fail: - UPDATE_STATS(STAT_BAD_SIGNATURE); + UPDATE_STATS(WY_STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("BAD detached signature for %s"), trp->name); notify(spool->notification, trp, wy_ev_bad_detached_signature); break; @@ -24,7 +24,7 @@ null_move_file(struct wy_triplet *trp, enum file_type file_id) const char *file_name = trp->file[file_id].name; wy_debug(1, (_("spool %s: installing file `%s/%s'"), spool->tag, trp->relative_dir, file_name)); - UPDATE_STATS(STAT_UPLOADS); + UPDATE_STATS(WY_STAT_UPLOADS); if (!wy_dry_run && unlink(file_name)) { wy_log(LOG_ERR, _("cannot unlink %s: %s"), file_name, strerror(errno)); @@ -38,7 +38,7 @@ null_archive_file(struct wy_triplet *trp, const char *file_name) { wy_debug(1, (_("spool %s: archiving `%s'"), trp->spool->tag, file_name)); - UPDATE_STATS(STAT_ARCHIVES); + UPDATE_STATS(WY_STAT_ARCHIVES); return 0; } @@ -48,7 +48,7 @@ null_symlink_file(struct wy_triplet *trp, { wy_debug(1, (_("spool %s: symlinking `%s' to `%s'"), trp->spool->tag, wanted_src, wanted_dst)); - UPDATE_STATS(STAT_SYMLINKS); + UPDATE_STATS(WY_STAT_SYMLINKS); return 0; } @@ -57,6 +57,6 @@ null_rmsymlink_file(struct wy_triplet *trp, const char *file_name) { wy_debug(1, (_("spool %s: removing symlink `%s/%s'"), trp->spool->tag, trp->relative_dir, file_name)); - UPDATE_STATS(STAT_RMSYMLINKS); + UPDATE_STATS(WY_STAT_RMSYMLINKS); return 0; } diff --git a/src/triplet.c b/src/triplet.c index 067bc01..7c79af0 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -373,17 +373,17 @@ triplet_processor(void *data, void *proc_data) case triplet_incomplete: wy_debug(1, (_("%s: incomplete triplet"), trp->name)); /* ignore unless expired (see below); */ - UPDATE_STATS(STAT_INCOMPLETE_TRIPLETS); + UPDATE_STATS(WY_STAT_INCOMPLETE_TRIPLETS); break; case triplet_bad: - UPDATE_STATS(STAT_BAD_TRIPLETS); + UPDATE_STATS(WY_STAT_BAD_TRIPLETS); remove_triplet(trp, 0); return 0; } if (triplet_expired_p(trp)) { - UPDATE_STATS(STAT_EXPIRED_TRIPLETS); + UPDATE_STATS(WY_STAT_EXPIRED_TRIPLETS); remove_triplet(trp, 0); } diff --git a/src/wydawca.c b/src/wydawca.c index 4bd3620..00d779c 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -52,7 +52,7 @@ char *wy_gpg_homedir; char *default_check_script; struct grecs_sockaddr listen_sockaddr; -unsigned wydawca_stat[MAX_STAT]; +unsigned wydawca_stat[WY_MAX_STAT]; unsigned min_directive_version = MIN_DIRECTIVE_VERSION; unsigned max_directive_version = MAX_DIRECTIVE_VERSION; @@ -117,11 +117,11 @@ wy_log(int prio, char *fmt, ...) case LOG_ALERT: case LOG_CRIT: case LOG_ERR: - UPDATE_STATS(STAT_ERRORS); + UPDATE_STATS(WY_STAT_ERRORS); break; case LOG_WARNING: - UPDATE_STATS(STAT_WARNINGS); + UPDATE_STATS(WY_STAT_WARNINGS); } va_start(ap, fmt); @@ -140,7 +140,7 @@ wy_dbg(char *fmt, ...) } -static char *stat_name[MAX_STAT] = { +static char *stat_name[WY_MAX_STAT] = { N_("errors"), N_("warnings"), N_("bad signatures"), @@ -157,7 +157,7 @@ static char *stat_name[MAX_STAT] = { N_("check failures"), }; -static char *stat_kwname[MAX_STAT] = { +static char *stat_kwname[WY_MAX_STAT] = { "stat:errors", "stat:warnings", "stat:bad_signatures", @@ -179,8 +179,8 @@ wy_stat_mask_p(unsigned long mask) { int i; - for (i = 0; i < MAX_STAT; i++) - if (wydawca_stat[i] != 0 && (mask && STAT_MASK(i))) + for (i = 0; i < WY_MAX_STAT; i++) + if (wydawca_stat[i] != 0 && (mask && WY_STAT_MASK(i))) return 1; return 0; } @@ -202,9 +202,9 @@ make_stat_expansion(size_t count) { int i; struct wy_metadef *def, *p; - def = grecs_calloc(MAX_STAT + count + 1, sizeof(def[0])); + def = grecs_calloc(WY_MAX_STAT + count + 1, sizeof(def[0])); p = def + count; - for (i = 0; i < MAX_STAT; i++, p++) { + for (i = 0; i < WY_MAX_STAT; i++, p++) { p->kw = stat_kwname[i]; p->value = NULL; p->storage = NULL; @@ -221,13 +221,13 @@ logstats() int i; if (wy_stat_mask_p(print_stats)) { - for (i = 0; i < MAX_STAT; i++) - if (print_stats & STAT_MASK(i)) + for (i = 0; i < WY_MAX_STAT; i++) + if (print_stats & WY_STAT_MASK(i)) wy_log(LOG_INFO, "%s: %u", gettext(stat_name[i]), wydawca_stat[i]); } - notify_stats(); + notify_finish(); } void diff --git a/src/wydawca.h b/src/wydawca.h index 0dd99e1..580d0be 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -263,31 +263,6 @@ struct spool { } \ } while (0) -enum wydawca_stat { - STAT_ERRORS, - STAT_WARNINGS, - STAT_BAD_SIGNATURE, - STAT_ACCESS_VIOLATIONS, - STAT_COMPLETE_TRIPLETS, - STAT_INCOMPLETE_TRIPLETS, - STAT_BAD_TRIPLETS, - STAT_EXPIRED_TRIPLETS, - STAT_TRIPLET_SUCCESS, - STAT_UPLOADS, - STAT_ARCHIVES, - STAT_SYMLINKS, - STAT_RMSYMLINKS, - STAT_CHECK_FAIL, - MAX_STAT -}; - -#define STAT_MASK(c) (1<<(c)) -#define STAT_MASK_NONE 0 -#define STAT_MASK_ALL (STAT_MASK(MAX_STAT) - 1) - -int wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node, - void *varptr, void *cb_data); - struct notification { struct notification *next; enum wy_event ev; @@ -351,7 +326,7 @@ extern int syslog_include_prio; /* Syslog priority indication */ extern time_t file_sweep_time; /* Unlink stale file after this amount of time */ extern char *tar_command_name; /* Name of the tar command */ -extern unsigned wydawca_stat[MAX_STAT]; +extern unsigned wydawca_stat[WY_MAX_STAT]; extern unsigned long print_stats; extern int archive_signatures; @@ -385,7 +360,7 @@ extern int inotify_enable; extern struct notification *default_notification; #define UPDATE_STATS(what) do { \ - if (what >= MAX_STAT) abort(); \ + if (what >= WY_MAX_STAT) abort(); \ wydawca_stat[what]++; \ } while (0) |