source: subversion/applications/utils/mod_tile/sys_utils.c @ 29283

Last change on this file since 29283 was 28923, checked in by apmon, 7 years ago

[mod_tile] Fix get_load_avg calculation

mod_tile.c was missing an include file resulting in a wrong return type

File size: 695 bytes
Line 
1#include "config.h"
2#include <stdio.h>
3#include <stdlib.h>
4
5#ifdef HAVE_SYS_LOADAVG_H
6#include <sys/loadavg.h>
7#endif
8
9double get_load_avg(void)
10{
11#ifdef HAVE_GETLOADAVG
12    double loadavg[1];
13    int n = getloadavg(loadavg, 1);
14
15    if (n < 1)
16        return 1000.0;
17    else
18        return loadavg[0];
19#else
20    FILE *loadavg = fopen("/proc/loadavg", "r");
21    double avg = 1000.0;
22
23    if (!loadavg) {
24        fprintf(stderr, "failed to read /proc/loadavg");
25        return 1000.0;
26    }
27    if (fscanf(loadavg, "%lf", &avg) != 1) {
28        fprintf(stderr, "failed to parse /proc/loadavg");
29        fclose(loadavg);
30        return 1000.0;
31    }
32    fclose(loadavg);
33
34    return avg;
35#endif
36}
Note: See TracBrowser for help on using the repository browser.