~aperezdc/dmon

357e8e710fe9ac4c42ebcee5001355c2bddd42b8 — Matt Schulte 4 years ago 8c5e4be
Compile under gcc 4.7 and with uclibc

Validated compilation under -std=gnu99 and -std=gnu11 using gcc 4.7.2
and gcc 9.3.0.
4 files changed, 21 insertions(+), 4 deletions(-)

M deps/cflag/cflag.h
M deps/dbuf/dbuf.c
M deps/dbuf/dbuf.h
M dmon.c
M deps/cflag/cflag.h => deps/cflag/cflag.h +2 -2
@@ 40,13 40,13 @@ struct cflag {


#define CFLAG(_t, _name, _letter, _data, _help) \
    ((struct cflag) {                           \
    {                                           \
        .func = cflag_ ## _t,                   \
        .name = (_name),                        \
        .letter = (_letter),                    \
        .data = (_data),                        \
        .help = (_help),                        \
    })
    }
#define CFLAG_HELP \
    CFLAG(help, "help", 'h', NULL, "Prints command line usage help.")
#define CFLAG_END \

M deps/dbuf/dbuf.c => deps/dbuf/dbuf.c +1 -1
@@ 57,7 57,7 @@ struct dbuf*
dbuf_new(size_t prealloc)
{
    struct dbuf *b = mrealloc(NULL, sizeof(struct dbuf));
    *b = DBUF_INIT;
    *b = (struct dbuf)DBUF_INIT;
    bresize(b, prealloc);
    return b;
}

M deps/dbuf/dbuf.h => deps/dbuf/dbuf.h +1 -1
@@ 24,7 24,7 @@ struct dbuf {
    size_t   alloc;
};

#define DBUF_INIT  ((struct dbuf) { .data = NULL, .size = 0, .alloc = 0 })
#define DBUF_INIT  { .data = NULL, .size = 0, .alloc = 0 }

struct dbuf* dbuf_new(size_t prealloc)
    __attribute__((warn_unused_result));

M dmon.c => dmon.c +17 -0
@@ 13,6 13,7 @@
#include "task.h"
#include "util.h"
#include <assert.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdarg.h>


@@ 138,6 139,22 @@ signal_to_name (int signum)
    return unknown;
}

#if defined(__UCLIBC__)
static int getloadavg(double *a, int n)
{
    struct sysinfo si;
    if (n <= 0) return n ? -1 : 0;
    if (n > 3) n = 3;

    if (sysinfo(&si) != 0) return -1;

    int i = 0;
    for (i=0; i<n; i++)
        a[i] = 1.0/(1<<SI_LOAD_SHIFT) * si.loads[i];

    return n;
}
#endif

static int
reap_and_check (void)