]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Handle getrusage() errors better
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 5 May 2016 18:26:37 +0000 (21:26 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 6 May 2016 18:06:24 +0000 (21:06 +0300)
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.

src/plugins/stats/mail-stats-fill.c

index 95e4445f6cb7b5358932088660179e81c80b9715..3c8ff360e4f8fa2dedbe2a11af38af5a919f2732 100644 (file)
@@ -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;
        }