From: Craig Small Date: Tue, 31 May 2022 11:35:40 +0000 (+1000) Subject: tload: Report on lack of /proc/loadavg X-Git-Tag: v4.0.1rc1~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3111334ddd5b29ef723a06688bd81a5f8eae8322;p=procps-ng tload: Report on lack of /proc/loadavg Now that the library correctly returns an error if loadavg is not available, tload can tell the user the bad news. References: procps-ng/procps#227 commit 8fcd14de18b998647ba47f5b35feb1d85e2d2f08 Signed-off-by: Craig Small --- diff --git a/tload.c b/tload.c index 279b4b53..993c13bc 100644 --- a/tload.c +++ b/tload.c @@ -170,11 +170,20 @@ int main(int argc, char **argv) alrm(0); while (1) { + int rc; if (scale_fact < max_scale) scale_fact *= 2.0; /* help it drift back up. */ - procps_loadavg(&av[0], &av[1], &av[2]); + if ((rc = procps_loadavg(&av[0], &av[1], &av[2])) < 0) + { + if (rc == -ENOENT) + xerrx(EXIT_FAILURE, + _("Load average file /proc/loadavg does not exist")); + else + xerrx(EXIT_FAILURE, + _("Unable to get load average")); + } do { lines = av[0] * scale_fact;