summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-04-25 18:52:09 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-04-25 19:00:26 (GMT)
commitfbb142ae5a57ab227e46ff6ffeb4b29db000034f (patch) (side-by-side diff)
treecc237b384f298a892a64848a2631c96432cceab7
parent68d0e67d55882d1298bb0bf89c954c0ff2b1b823 (diff)
downloadwydawca-fbb142ae5a57ab227e46ff6ffeb4b29db000034f.tar.gz
wydawca-fbb142ae5a57ab227e46ff6ffeb4b29db000034f.tar.bz2
Keep statistic items in global array. Use special thread for periodic reporting
* src/config.c: New configuration statement stat-report-interval * src/directive.c * src/timer.c: Rewrite statistic counters and functions (wydawca_stat_log,wydawca_stat_init,wydawca_stat_update) (wydawca_stat_notify,wydawca_stat_add): New functions. (wy_thr_stat): New thread (statistics reporter. * src/triplet.c: Remove per-thread statistic counters. * src/wydawca.c (wy_main): Use new statistic calls. Force statistic logging at the end of the run. * src/wydawca.h (DEFAULT_STAT_REPORT_INTERVAL): New constant. (stat_report_interval): New extern. (wy_get_stat_array, wy_get_stat_slot) (wy_get_stat_counter): Remove. (wydawca_stat_log,wydawca_stat_init,wydawca_stat_update) (wydawca_stat_notify,wydawca_stat_add) (wydawca_stat_incr): New protos. (stat_mask_p,logstats,wydawca_stats_export) (wydawca_stats_update): Remove protos.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/config.c18
-rw-r--r--src/directive.c6
-rw-r--r--src/diskio.c14
-rw-r--r--src/gpg.c16
-rw-r--r--src/null.c8
-rw-r--r--src/timer.c168
-rw-r--r--src/triplet.c36
-rw-r--r--src/wydawca.c100
-rw-r--r--src/wydawca.h29
-rw-r--r--tests/inotify-ok.at2
-rw-r--r--tests/inotify-rmsymlink.at2
-rw-r--r--tests/inotify-symlink.at2
-rw-r--r--tests/inotify-unatt00.at2
-rw-r--r--tests/inotify-unatt01.at2
-rw-r--r--tests/unp00.at2
15 files changed, 217 insertions, 190 deletions
diff --git a/src/config.c b/src/config.c
index 6b99801..a7ceb92 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1465,10 +1465,14 @@ static struct grecs_keyword wydawca_kw[] = {
N_("Control implicit signature archivation"),
grecs_type_bool, GRECS_DFLT, &archive_signatures },
+ { "stat-report-interval", N_("interval"),
+ N_("Interval for periodic statistics reports"),
+ grecs_type_string, GRECS_DFLT,
+ &stat_report_interval, 0, cb_interval },
{ "statistics", N_("items"),
- N_("Print these stats at the end of run"),
+ N_("Print these statistic items periodically"),
grecs_type_string, GRECS_CONST, &print_stats, 0, wy_cb_statistics },
-
+
{ "sql", N_("id: string"),
N_("Define SQL database"),
grecs_type_section, GRECS_DFLT, NULL, 0, cb_sql, NULL, sql_kw },
@@ -1724,7 +1728,13 @@ config_finish(struct grecs_node *tree)
if (file_sweep_time <= 0) {
file_sweep_time = DEFAULT_FILE_SWEEP_TIME;
wy_log(LOG_NOTICE,
- _("file-sweep-time too low; reverting to the default %lus"),
- (unsigned long)file_sweep_time);
+ _("%s too low; reverting to the default %lus"),
+ "file-sweep-time", (unsigned long)file_sweep_time);
+ }
+ if (stat_report_interval <= 0) {
+ stat_report_interval = DEFAULT_STAT_REPORT_INTERVAL;
+ wy_log(LOG_NOTICE,
+ _("%s too low; reverting to the default %lus"),
+ "stat-report-interval", (unsigned long)stat_report_interval);
}
}
diff --git a/src/directive.c b/src/directive.c
index cdbb513..cdf0bd6 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -558,7 +558,7 @@ external_check(struct wy_triplet *trp)
free(file);
if (rc) {
- increase_stat_counter(WY_STAT_CHECK_FAIL);
+ wydawca_stat_incr(WY_STAT_CHECK_FAIL);
notify(spool->notification, trp, wy_ev_check_fail);
}
@@ -596,7 +596,7 @@ process_directives(struct wy_triplet *trp)
const char *key, *val;
struct spool *spool = trp->spool;
- increase_stat_counter(WY_STAT_COMPLETE_TRIPLETS);
+ wydawca_stat_incr(WY_STAT_COMPLETE_TRIPLETS);
timer_start(WY_TIMER_TRIPLET);
for (n = directive_first(trp, &key, &val); n;
n = directive_next(trp, n, &key, &val)) {
@@ -666,7 +666,7 @@ process_directives(struct wy_triplet *trp)
trp->file[file_directive].name, strerror(errno));
}
- increase_stat_counter(WY_STAT_TRIPLET_SUCCESS);
+ wydawca_stat_incr(WY_STAT_TRIPLET_SUCCESS);
triplet_report_finish(trp);
timer_stop(WY_TIMER_TRIPLET);
notify(spool->notification, trp, wy_ev_success);
diff --git a/src/diskio.c b/src/diskio.c
index b57b5c3..73ce352 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -409,13 +409,13 @@ do_archive_file(int pkg_dir_fd, struct wy_triplet *trp, char const *file_name)
case archive_directory:
if (backup_copy(pkg_dir_fd, trp, file_name))
return -1;
- increase_stat_counter(WY_STAT_ARCHIVES);
+ wydawca_stat_incr(WY_STAT_ARCHIVES);
break;
case archive_tar:
if (tar_append_file(archive->name, trp, file_name))
return 1;
- increase_stat_counter(WY_STAT_ARCHIVES);
+ wydawca_stat_incr(WY_STAT_ARCHIVES);
break;
}
@@ -491,7 +491,7 @@ dir_move_file(struct wy_triplet *trp, enum file_type file_id)
}
if (rc == 0)
- increase_stat_counter(WY_STAT_UPLOADS);
+ wydawca_stat_incr(WY_STAT_UPLOADS);
return rc;
}
@@ -541,7 +541,7 @@ dir_archive_file(struct wy_triplet *trp, const char *file_name)
if (fstatat(pkg_dir_fd, rname, &st, 0) == 0) {
rc = do_archive_file(pkg_dir_fd, trp, rname);
if (rc == 0)
- increase_stat_counter(WY_STAT_ARCHIVES);
+ wydawca_stat_incr(WY_STAT_ARCHIVES);
} else {
wy_log(LOG_ERR, _("cannot stat file %s/%s/%s: %s"),
trp->spool->dest_dir, trp->relative_dir, rname,
@@ -554,7 +554,7 @@ dir_archive_file(struct wy_triplet *trp, const char *file_name)
if (fstatat(pkg_dir_fd, signame, &st, 0) == 0) {
rc = backup_copy(pkg_dir_fd, trp, signame);
if (rc == 0)
- increase_stat_counter(WY_STAT_ARCHIVES);
+ wydawca_stat_incr(WY_STAT_ARCHIVES);
} else if (errno != ENOENT) {
wy_log(LOG_ERR, _("cannot stat file %s/%s/%s: %s"),
trp->spool->dest_dir, trp->relative_dir, signame,
@@ -612,7 +612,7 @@ symlink_triplet_file(int dirfd, struct wy_triplet *trp, const char *src,
src, dst, trp->spool->dest_dir, trp->relative_dir,
strerror(errno));
else
- increase_stat_counter(WY_STAT_SYMLINKS);
+ wydawca_stat_incr(WY_STAT_SYMLINKS);
return rc;
}
@@ -710,7 +710,7 @@ rmsymlink_triplet_file(int dirfd, struct wy_triplet *trp, const char *file)
strerror(errno));
return -1;
}
- increase_stat_counter(WY_STAT_RMSYMLINKS);
+ wydawca_stat_incr(WY_STAT_RMSYMLINKS);
return 0;
}
diff --git a/src/gpg.c b/src/gpg.c
index 0d90f55..41ac723 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -220,27 +220,27 @@ checksig(gpgme_signature_t sig, const char *uid, struct wy_triplet *trp)
break;
case GPG_ERR_BAD_SIGNATURE:
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
wy_log(LOG_ERR, _("BAD signature from %s"), uid);
return 0;
case GPG_ERR_NO_PUBKEY:
- increase_stat_counter(WY_STAT_ACCESS_VIOLATIONS);
+ wydawca_stat_incr(WY_STAT_ACCESS_VIOLATIONS);
wy_log(LOG_ERR, _("No public key"));
return 0;
case GPG_ERR_NO_DATA:
- increase_stat_counter(WY_STAT_BAD_TRIPLETS);
+ wydawca_stat_incr(WY_STAT_BAD_TRIPLETS);
wy_log(LOG_ERR, _("No signature"));
return 0;
case GPG_ERR_SIG_EXPIRED:
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
wy_log(LOG_ERR, _("Expired signature from %s"), uid);
return 0;
case GPG_ERR_KEY_EXPIRED:
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
wy_log(LOG_ERR, _("Key expired (%s)"), uid);
return 0;
@@ -327,7 +327,7 @@ verify_directive_signature(struct wy_triplet *trp)
result = gpgme_op_verify_result(ctx);
if (!gpg_verify_signature(ctx, result->signatures, trp)) {
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
notify(trp->spool->notification, trp,
wy_ev_bad_directive_signature);
rc = 1;
@@ -335,7 +335,7 @@ verify_directive_signature(struct wy_triplet *trp)
rc = 0;
} else {
rc = 1;
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
wy_log(LOG_ERR, _("%s: directive verification failed: %s"),
trp->name, gpgme_strerror(ec));
}
@@ -374,7 +374,7 @@ verify_detached_signature(struct wy_triplet *trp)
wy_debug(1, (_("good detached signature for %s"), trp->name));
rc = 0;
} else {
- increase_stat_counter(WY_STAT_BAD_SIGNATURE);
+ wydawca_stat_incr(WY_STAT_BAD_SIGNATURE);
wy_log(LOG_ERR, _("BAD detached signature for %s"), trp->name);
notify(trp->spool->notification, trp, wy_ev_bad_detached_signature);
rc = 1;
diff --git a/src/null.c b/src/null.c
index ada5dba..ba42c44 100644
--- a/src/null.c
+++ b/src/null.c
@@ -23,7 +23,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));
- increase_stat_counter(WY_STAT_UPLOADS);
+ wydawca_stat_incr(WY_STAT_UPLOADS);
if (!wy_dry_run && unlink(file_name)) {
wy_log(LOG_ERR, _("cannot unlink %s: %s"),
file_name, strerror(errno));
@@ -37,7 +37,7 @@ null_archive_file(struct wy_triplet *trp, const char *file_name)
{
wy_debug(1, (_("spool %s: archiving `%s'"),
trp->spool->tag, file_name));
- increase_stat_counter(WY_STAT_ARCHIVES);
+ wydawca_stat_incr(WY_STAT_ARCHIVES);
return 0;
}
@@ -47,7 +47,7 @@ null_symlink_file(struct wy_triplet *trp,
{
wy_debug(1, (_("spool %s: symlinking `%s' to `%s'"),
trp->spool->tag, wanted_src, wanted_dst));
- increase_stat_counter(WY_STAT_SYMLINKS);
+ wydawca_stat_incr(WY_STAT_SYMLINKS);
return 0;
}
@@ -56,6 +56,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));
- increase_stat_counter(WY_STAT_RMSYMLINKS);
+ wydawca_stat_incr(WY_STAT_RMSYMLINKS);
return 0;
}
diff --git a/src/timer.c b/src/timer.c
index 10fd9a5..ae026d9 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -108,6 +108,16 @@ _timer_compute(wydawca_timer_t t)
DIFFTIME(rusage.ru_stime, t->children_mark.ru_stime);
}
+static inline void
+_timer_reset(wydawca_timer_t t)
+{
+ t->real = 0.0;
+ t->self_user = 0.0;
+ t->self_system = 0.0;
+ t->children_user = 0.0;
+ t->children_system = 0.0;
+}
+
wydawca_timer_t
timer_get(int idx)
{
@@ -130,11 +140,7 @@ wydawca_timer_t
timer_reset(int idx)
{
wydawca_timer_t t = get_thread_timer(idx);
- t->real = 0.0;
- t->self_user = 0.0;
- t->self_system = 0.0;
- t->children_user = 0.0;
- t->children_system = 0.0;
+ _timer_reset(t);
return t;
}
@@ -188,18 +194,20 @@ timer_format_time(double t)
}
/* Cumulative statistic counters and timers */
-WY_STAT_COUNTER *wydawca_global_stats;
+WY_STAT_COUNTER wydawca_global_stats[WY_MAX_STAT];
WY_TIMER *wydawca_global_timer_table;
pthread_mutex_t global_stats_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t global_stats_cond = PTHREAD_COND_INITIALIZER;
+static int stat_stop;
+pthread_t stat_tid;
-/* wydawca_stats_export must be called from the main thread in order to
- export the thread's specific stats and timer pointers to
- wydawca_global_stats and wydawca_global_stats. */
void
-wydawca_stats_export(void)
+wydawca_stat_add(int what, size_t n)
{
- wydawca_global_stats = wy_get_stat_array();
- wydawca_global_timer_table = get_thread_timer_table();
+ if (what >= WY_MAX_STAT) abort();
+ pthread_mutex_lock(&global_stats_mutex);
+ wydawca_global_stats[what] += n;
+ pthread_mutex_unlock(&global_stats_mutex);
}
/* When running in cron mode, this function is called by the triplet
@@ -207,14 +215,12 @@ wydawca_stats_export(void)
incorporates the thread-specific statistics into the cumulative
counters. */
void
-wydawca_stats_update(void)
+wydawca_stat_update(void)
{
int i;
- WY_STAT_COUNTER *ctr = wy_get_stat_array();
WY_TIMER *thread_timers = get_thread_timer_table();
pthread_mutex_lock(&global_stats_mutex);
- for (i = 0; i < WY_MAX_STAT; i++)
- wydawca_global_stats[i] += ctr[i];
+// _timer_compute(&wydawca_global_timer_table[WY_TIMER_WYDAWCA]);
for (i = 0; i < MAX_TIMERS; i++) {
wydawca_global_timer_table[i].real
+= thread_timers[i].real;
@@ -229,3 +235,133 @@ wydawca_stats_update(void)
}
pthread_mutex_unlock(&global_stats_mutex);
}
+
+void
+wydawca_stat_notify(int final)
+{
+ void *ret;
+ pthread_mutex_lock(&global_stats_mutex);
+ stat_stop = final;
+ pthread_cond_broadcast(&global_stats_cond);
+ pthread_mutex_unlock(&global_stats_mutex);
+ if (final)
+ pthread_join(stat_tid, &ret);
+}
+
+void
+wydawca_stat_reset(void)
+{
+ int i;
+
+ for (i = 0; i < WY_MAX_STAT; i++)
+ wydawca_global_stats[i] = 0;
+ for (i = 0; i < MAX_TIMERS; i++)
+ _timer_reset(&wydawca_global_timer_table[i]);
+}
+
+time_t stat_report_interval = DEFAULT_STAT_REPORT_INTERVAL;
+
+void *
+wy_thr_stat(void *ptr)
+{
+ wy_set_cur_thread_name("statcol");
+ pthread_mutex_lock(&global_stats_mutex);
+ /* export the thread's specific stats and timer pointers to
+ wydawca_global_stats and wydawca_global_stats. */
+ wydawca_global_timer_table = get_thread_timer_table();
+ while (!stat_stop) {
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += stat_report_interval;
+ pthread_cond_timedwait(&global_stats_cond, &global_stats_mutex, &ts);
+ wydawca_stat_log();
+ notify_finish();
+ wydawca_stat_reset();
+ }
+ pthread_mutex_unlock(&global_stats_mutex);
+ return NULL;
+}
+
+void
+wydawca_stat_init(void)
+{
+ pthread_create(&stat_tid, NULL, wy_thr_stat, NULL);
+}
+
+static char *stat_name[WY_MAX_STAT] = {
+ N_("errors"),
+ N_("warnings"),
+ N_("bad signatures"),
+ N_("access violation attempts"),
+ N_("complete triplets"),
+ N_("incomplete triplets"),
+ N_("bad triplets"),
+ N_("expired triplets"),
+ N_("triplet successes"),
+ N_("files uploaded"),
+ N_("files archived"),
+ N_("symlinks created"),
+ N_("symlinks removed"),
+ N_("check failures"),
+};
+
+static char *stat_kwname[WY_MAX_STAT] = {
+ "stat:errors",
+ "stat:warnings",
+ "stat:bad_signatures",
+ "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_failures"
+};
+
+int
+wy_stat_mask_p(unsigned long mask)
+{
+ int i;
+
+ for (i = 0; i < WY_MAX_STAT; i++)
+ if (wydawca_global_stats[i] != 0 && (mask && WY_STAT_MASK(i)))
+ return 1;
+ return 0;
+}
+
+int
+wy_stat_expansion(char **ret, char const *name, size_t len)
+{
+ int i;
+
+ for (i = 0; i < WY_MAX_STAT; i++) {
+ if (strlen(stat_kwname[i]) == len
+ && memcmp(stat_kwname[i], name, len) == 0) {
+ size_t size = 0;
+ *ret = NULL;
+ if (grecs_asprintf(ret, &size, "%u", wydawca_global_stats[i]))
+ return WRDSE_NOSPACE;
+ else
+ return WRDSE_OK;
+ }
+ }
+ return WRDSE_UNDEF;
+}
+
+void
+wydawca_stat_log(void)
+{
+ int i;
+
+ if (wy_stat_mask_p(print_stats)) {
+ 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_global_stats[i]);
+ }
+}
+
diff --git a/src/triplet.c b/src/triplet.c
index 47be116..3bdc2d4 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -524,49 +524,19 @@ wy_triplet_wait(void)
triplet_list_unlock(&triplet_running_list);
pthread_mutex_lock(&triplet_table_mutex);
- n = grecs_symtab_count(triplet_table);
+ n = triplet_table ? grecs_symtab_count(triplet_table) : 0;
pthread_mutex_unlock(&triplet_table_mutex);
- *wy_get_stat_slot(WY_STAT_INCOMPLETE_TRIPLETS) += n;
+ wydawca_stat_add(WY_STAT_INCOMPLETE_TRIPLETS, n);
}
-static pthread_key_t key;
-static pthread_once_t key_once = PTHREAD_ONCE_INIT;
-
-static void
-stat_free(void *f)
-{
- free(f);
-}
-
-static void
-make_key(void)
-{
- pthread_key_create(&key, stat_free);
-}
-
-WY_STAT_COUNTER *
-wy_get_stat_array(void)
-{
- WY_STAT_COUNTER *stat;
- pthread_once(&key_once, make_key);
- if ((stat = pthread_getspecific(key)) == NULL) {
- stat = grecs_calloc(WY_MAX_STAT, sizeof(stat[0]));
- pthread_setspecific(key, stat);
- }
- return stat;
-}
-
void *
wy_thr_triplet(void *ptr)
{
struct wy_triplet *trp = ptr;
wy_set_cur_thread_name("triplet");
triplet_commit(trp);
+ wydawca_stat_update();
remove_triplet(trp);
- if (wy_mode == WY_MODE_DAEMON)
- logstats();
- else
- wydawca_stats_update();
return NULL;
}
diff --git a/src/wydawca.c b/src/wydawca.c
index b7ccc7d..2e9c952 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -110,11 +110,11 @@ wy_vlog(int prio, char const *fmt, va_list ap)
case LOG_ALERT:
case LOG_CRIT:
case LOG_ERR:
- increase_stat_counter(WY_STAT_ERRORS);
+ wydawca_stat_incr(WY_STAT_ERRORS);
break;
case LOG_WARNING:
- increase_stat_counter(WY_STAT_WARNINGS);
+ wydawca_stat_incr(WY_STAT_WARNINGS);
}
log_printer(prio, fmt, ap);
@@ -139,87 +139,6 @@ wy_dbg(char const *fmt, ...)
va_end(ap);
}
-
-static char *stat_name[WY_MAX_STAT] = {
- N_("errors"),
- N_("warnings"),
- N_("bad signatures"),
- N_("access violation attempts"),
- N_("complete triplets"),
- N_("incomplete triplets"),
- N_("bad triplets"),
- N_("expired triplets"),
- N_("triplet successes"),
- N_("files uploaded"),
- N_("files archived"),
- N_("symlinks created"),
- N_("symlinks removed"),
- N_("check failures"),
-};
-
-static char *stat_kwname[WY_MAX_STAT] = {
- "stat:errors",
- "stat:warnings",
- "stat:bad_signatures",
- "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_failures"
-};
-
-int
-wy_stat_mask_p(unsigned long mask)
-{
- int i;
- WY_STAT_COUNTER *stat = wy_get_stat_array();
-
- for (i = 0; i < WY_MAX_STAT; i++)
- if (stat[i] != 0 && (mask && WY_STAT_MASK(i)))
- return 1;
- return 0;
-}
-
-int
-wy_stat_expansion(char **ret, char const *name, size_t len)
-{
- int i;
-
- for (i = 0; i < WY_MAX_STAT; i++) {
- if (strlen(stat_kwname[i]) == len
- && memcmp(stat_kwname[i], name, len) == 0) {
- size_t size = 0;
- *ret = NULL;
- if (grecs_asprintf(ret, &size, "%u", wy_get_stat_counter(i)))
- return WRDSE_NOSPACE;
- else
- return WRDSE_OK;
- }
- }
- return WRDSE_UNDEF;
-}
-
-void
-logstats(void)
-{
- int i;
-
- if (wy_stat_mask_p(print_stats)) {
- 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]), wy_get_stat_counter(i));
- }
-
- notify_finish();
-}
-
void
grecs_print_diag(grecs_locus_t * locus, int err, int errcode,
const char *msg)
@@ -320,9 +239,6 @@ wy_main(void)
sigaddset(&sigs, SIGCHLD);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
- wydawca_stats_export();
- scan_all_spools();
-
if (wy_mode == WY_MODE_DAEMON) {
if (!foreground) {
if (daemon(0, 0)) {
@@ -331,12 +247,16 @@ wy_main(void)
}
wy_log(LOG_NOTICE, _("daemon launched"));
}
+
+ wydawca_stat_init();
+ scan_all_spools();
+
pidfile_update();
- // Start cleaner thread
+ /* Start cleaner thread */
pthread_create(&tid, NULL, wy_thr_cleaner, NULL);
- // Start listener thread
+ /* Start listener thread */
pthread_create(&tid, NULL, wy_thr_listen, NULL);
/* Unblock only the fatal signals */
@@ -350,6 +270,8 @@ wy_main(void)
sigwait(&sigs, &i);
wy_log(LOG_NOTICE, "shutting down on signal \"%s\"", strsignal(i));
} else {
+ wydawca_stat_init();
+ scan_all_spools();
/* Unblock only the fatal signals */
sigemptyset(&sigs);
for (i = 0; fatal_signals[i]; i++) {
@@ -357,8 +279,8 @@ wy_main(void)
}
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
wy_triplet_wait();
- logstats();
}
+ wydawca_stat_notify(1);
}
int
diff --git a/src/wydawca.h b/src/wydawca.h
index 825f30b..0a926e6 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -63,6 +63,7 @@ void wy_set_cur_thread_name(char const *name);
#define SP(s) ((s) ? (s) : "NONE")
#define DEFAULT_FILE_SWEEP_TIME 300
+#define DEFAULT_STAT_REPORT_INTERVAL 3600
/* The range of directive versions we accept (major * 100 + minor) */
#define MIN_DIRECTIVE_VERSION 101
@@ -319,6 +320,7 @@ extern char *conffile; /* Configuration file name */
extern int syslog_include_prio; /* Syslog priority indication */
extern time_t file_sweep_time; /* Unlink stale file after this amount of time
*/
+extern time_t stat_report_interval;
extern char *tar_command_name; /* Name of the tar command */
extern unsigned long print_stats;
extern int archive_signatures;
@@ -353,31 +355,18 @@ extern struct notification *default_notification;
extern size_t spool_count;
typedef unsigned WY_STAT_COUNTER;
-WY_STAT_COUNTER *wy_get_stat_array(void);
-
-static inline WY_STAT_COUNTER *
-wy_get_stat_slot(int what)
-{
- return wy_get_stat_array() + what;
-}
-
-static inline WY_STAT_COUNTER
-wy_get_stat_counter(int what)
-{
- return *wy_get_stat_slot(what);
-}
+void wydawca_stat_log(void);
+void wydawca_stat_init(void);
+void wydawca_stat_update(void);
+void wydawca_stat_notify(int final);
+void wydawca_stat_add(int what, size_t n);
static inline void
-increase_stat_counter(int what)
+wydawca_stat_incr(int what)
{
- if (what >= WY_MAX_STAT) abort();
- ++*wy_get_stat_slot(what);
+ wydawca_stat_add(what, 1);
}
-int stat_mask_p(unsigned long mask);
-void logstats(void);
-void wydawca_stats_export(void);
-void wydawca_stats_update(void);
/* Utility functions */
char *safe_file_name(char *file_name);
diff --git a/tests/inotify-ok.at b/tests/inotify-ok.at
index b9ea8e1..9058aca 100644
--- a/tests/inotify-ok.at
+++ b/tests/inotify-ok.at
@@ -41,6 +41,7 @@ cmp orig/conversion-1.1.tar.sig dest/conversion/conversion-1.1.tar.sig
[],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] conversion-1.1.tar.directive.asc: VERSION: 1.2
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -55,7 +56,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 0
wydawca: [[INFO]] symlinks removed: 0
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
diff --git a/tests/inotify-rmsymlink.at b/tests/inotify-rmsymlink.at
index 5af136d..e1addad 100644
--- a/tests/inotify-rmsymlink.at
+++ b/tests/inotify-rmsymlink.at
@@ -49,6 +49,7 @@ done
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] rmsymlink.directive.asc.directive.asc: VERSION: 1.2
wydawca: [[NOTICE]] rmsymlink.directive.asc.directive.asc: COMMENT: remove symlink
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -63,7 +64,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 0
wydawca: [[INFO]] symlinks removed: 2
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
AT_CLEANUP
diff --git a/tests/inotify-symlink.at b/tests/inotify-symlink.at
index 0877552..c46176a 100644
--- a/tests/inotify-symlink.at
+++ b/tests/inotify-symlink.at
@@ -50,6 +50,7 @@ dogana-0.file.sig
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] symlink.directive.asc.directive.asc: VERSION: 1.2
wydawca: [[NOTICE]] symlink.directive.asc.directive.asc: COMMENT: create a symlink
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -64,7 +65,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 2
wydawca: [[INFO]] symlinks removed: 0
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
diff --git a/tests/inotify-unatt00.at b/tests/inotify-unatt00.at
index d33ea27..18375c9 100644
--- a/tests/inotify-unatt00.at
+++ b/tests/inotify-unatt00.at
@@ -40,6 +40,7 @@ cmp orig/conversion-1.1.tar.sig dest/conversion/conversion-1.1.tar.sig
[],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] conversion-1.1.tar.directive.asc: VERSION: 1.2
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -54,7 +55,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 0
wydawca: [[INFO]] symlinks removed: 0
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
AT_CLEANUP
diff --git a/tests/inotify-unatt01.at b/tests/inotify-unatt01.at
index 70d516c..2fff5f5 100644
--- a/tests/inotify-unatt01.at
+++ b/tests/inotify-unatt01.at
@@ -42,6 +42,7 @@ cmp orig/conversion-1.1.tar.sig dest/conversion/conversion-1.1.tar.sig
[],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] conversion-1.1.tar.directive.asc: VERSION: 1.2
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -56,7 +57,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 0
wydawca: [[INFO]] symlinks removed: 0
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
diff --git a/tests/unp00.at b/tests/unp00.at
index 3835245..b3c16ab 100644
--- a/tests/unp00.at
+++ b/tests/unp00.at
@@ -47,6 +47,7 @@ cmp orig/conversion-1.1.tar.sig dest/conversion/conversion-1.1.tar.sig
[],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] conversion-1.1.tar.directive.asc: VERSION: 1.2
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -61,7 +62,6 @@ wydawca: [[INFO]] files archived: 0
wydawca: [[INFO]] symlinks created: 0
wydawca: [[INFO]] symlinks removed: 0
wydawca: [[INFO]] check failures: 0
-wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])

Return to:

Send suggestions and report system problems to the System administrator.