From: Timo Sirainen Date: Thu, 5 May 2016 18:26:37 +0000 (+0300) Subject: stats: Handle getrusage() errors better X-Git-Tag: 2.3.0.rc1~3828 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a16057fc5283ab54128edd73408c332217dffb5e;p=thirdparty%2Fdovecot%2Fcore.git stats: Handle getrusage() errors better I'm not aware of these errors actually happening anywhere, but its error handling wouldn't have been correct if previous getrusage() calls had succeeded. Now if it fails, log an error once and just keep on using the last working rusage. --- diff --git a/src/plugins/stats/mail-stats-fill.c b/src/plugins/stats/mail-stats-fill.c index 95e4445f6c..3c8ff360e4 100644 --- a/src/plugins/stats/mail-stats-fill.c +++ b/src/plugins/stats/mail-stats-fill.c @@ -111,14 +111,19 @@ user_trans_stats_get(struct stats_user *suser, struct mail_stats *dest_r) void mail_stats_fill(struct stats_user *suser, struct mail_stats *stats_r) { + static bool getrusage_broken = FALSE; static struct rusage prev_usage; struct rusage usage; memset(stats_r, 0, sizeof(*stats_r)); /* cputime */ - if (getrusage(RUSAGE_SELF, &usage) < 0) - memset(&usage, 0, sizeof(usage)); - if (timeval_diff_usecs(&usage.ru_stime, &prev_usage.ru_stime) < 0) { + if (getrusage(RUSAGE_SELF, &usage) < 0) { + if (!getrusage_broken) { + i_error("getrusage() failed: %m"); + getrusage_broken = TRUE; + } + usage = prev_usage; + } else if (timeval_diff_usecs(&usage.ru_stime, &prev_usage.ru_stime) < 0) { /* This seems to be a Linux bug. */ usage.ru_stime = prev_usage.ru_stime; }