From 0b37a8b8e99c0f34bdaf406af2b9aca4e56e1d9d Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 12 Apr 2017 13:44:02 +0000 Subject: Replace fd_writev with buffer_write in s6-uevent-listener --- src/minutils/s6-ps.h | 8 +-- src/minutils/s6-uevent-listener.c | 2 +- src/minutils/s6ps_pfield.c | 23 +++---- src/minutils/s6ps_statparse.c | 125 ++++++++++++++++++++------------------ 4 files changed, 77 insertions(+), 81 deletions(-) diff --git a/src/minutils/s6-ps.h b/src/minutils/s6-ps.h index f92488d..b0aadcc 100644 --- a/src/minutils/s6-ps.h +++ b/src/minutils/s6-ps.h @@ -90,15 +90,15 @@ struct pscan_s uint64_t cstime ; int prio ; int nice ; - uint32_t threads ; + uint64_t threads ; uint64_t start ; uint64_t vsize ; uint64_t rss ; uint64_t rsslim ; uint64_t wchan ; - uint32_t cpuno ; - uint32_t rtprio ; - uint32_t policy ; + uint64_t cpuno ; + uint64_t rtprio ; + uint64_t policy ; } ; #define PSCAN_ZERO \ diff --git a/src/minutils/s6-uevent-listener.c b/src/minutils/s6-uevent-listener.c index e93cb3a..29fbc38 100644 --- a/src/minutils/s6-uevent-listener.c +++ b/src/minutils/s6-uevent-listener.c @@ -30,7 +30,7 @@ #define BUFSIZE 8191 static char buf1[BUFSIZE + 1] ; -static buffer b1 = BUFFER_INIT(&fd_writev, 1, buf1, BUFSIZE + 1) ; +static buffer b1 = BUFFER_INIT(&buffer_write, 1, buf1, BUFSIZE + 1) ; static unsigned int cont = 1, verbosity = 1 ; static pid_t pid ; diff --git a/src/minutils/s6ps_pfield.c b/src/minutils/s6ps_pfield.c index 6072eb9..f2e3f7f 100644 --- a/src/minutils/s6ps_pfield.c +++ b/src/minutils/s6ps_pfield.c @@ -93,15 +93,6 @@ char const *const *s6ps_opttable = opttable ; static tain_t boottime = TAIN_EPOCH ; -static int fmt_32 (pscan_t *p, size_t *pos, size_t *len, uint32_t u) -{ - if (!stralloc_readyplus(&p->data, UINT32_FMT)) return 0 ; - *pos = p->data.len ; - *len = uint32_fmt(p->data.s + *pos, u) ; - p->data.len += *len ; - return 1 ; -} - static int fmt_64 (pscan_t *p, size_t *pos, size_t *len, uint64_t u) { if (!stralloc_readyplus(&p->data, UINT64_FMT)) return 0 ; @@ -292,7 +283,7 @@ static int fmt_nice (pscan_t *p, size_t *pos, size_t *len) static int fmt_threads (pscan_t *p, size_t *pos, size_t *len) { - return fmt_32(p, pos, len, p->threads) ; + return fmt_64(p, pos, len, p->threads) ; } static int fmt_timedate (pscan_t *p, size_t *pos, size_t *len, struct tm const *tm) @@ -359,12 +350,12 @@ static int fmt_rsslim (pscan_t *p, size_t *pos, size_t *len) static int fmt_cpuno (pscan_t *p, size_t *pos, size_t *len) { - return fmt_32(p, pos, len, p->cpuno) ; + return fmt_64(p, pos, len, p->cpuno) ; } static int fmt_rtprio (pscan_t *p, size_t *pos, size_t *len) { - return fmt_32(p, pos, len, p->rtprio) ; + return fmt_64(p, pos, len, p->rtprio) ; } static int fmt_policy (pscan_t *p, size_t *pos, size_t *len) @@ -397,9 +388,9 @@ static int fmt_group (pscan_t *p, size_t *pos, size_t *len) static struct sysinfo si = { .totalram = 0, .loads = { 0, 0, 0 } } ; -static uint64 gettotalmem (void) +static uint64_t gettotalmem (void) { - uint64 totalmem = 0 ; + uint64_t totalmem = 0 ; if (!si.totalram && (sysinfo(&si) < 0)) return 0 ; totalmem = si.totalram ; totalmem *= si.mem_unit ; @@ -410,9 +401,9 @@ static int percent (stralloc *sa, unsigned int n, size_t *pos, size_t *len) { if (!stralloc_readyplus(sa, UINT64_FMT+1)) return 0 ; *pos = sa->len ; - sa->len += uint64_fmt(sa->s + sa->len, n / 100) ; + sa->len += uint_fmt(sa->s + sa->len, n / 100) ; sa->s[sa->len++] = '.' ; - uint320_fmt(sa->s + sa->len, (uint32)(n % 100), 2) ; + uint0_fmt(sa->s + sa->len, n % 100, 2) ; sa->len += 2 ; *len = sa->len - *pos ; return 1 ; diff --git a/src/minutils/s6ps_statparse.c b/src/minutils/s6ps_statparse.c index 229ed11..0b1b261 100644 --- a/src/minutils/s6ps_statparse.c +++ b/src/minutils/s6ps_statparse.c @@ -14,40 +14,29 @@ is still smaller than scanf (no floating point parsing etc.) */ -#define STATVARS 41 +#define STATVARS 49 typedef size_t scanfunc_t (char const *, void *) ; typedef scanfunc_t *scanfunc_t_ref ; -static size_t f32 (char const *s, void *u32) -{ - uint32_t *u = u32 ; - return uint32_scan(s, u) ; -} - static size_t f64 (char const *s, void *u64) { uint64_t *u = u64 ; return uint64_scan(s, u) ; } -static size_t fint (char const *s, void *i) -{ - int *d = i ; - return int_scan(s, d) ; -} - -static size_t fpid (char const *s, void *p) -{ - pid_t *pid = p ; - return pid_scan(s, pid) ; -} +#define DEFUN(name, type) \ +static size_t name (char const *s, void *p) \ +{ \ + uint64_t u ; \ + size_t len = uint64_scan(s, &u) ; \ + *(type *)p = u ; \ + return len ; \ +} \ -static size_t fdev (char const *s, void *p) -{ - dev_t *d = p ; - return dev_scan(s, d) ; -} +DEFUN(fint, int) +DEFUN(fpid, pid_t) +DEFUN(fdev, dev_t) static scanfunc_t_ref scanfuncs[STATVARS] = { @@ -56,19 +45,19 @@ static scanfunc_t_ref scanfuncs[STATVARS] = &fpid, /* session */ &fdev, /* tty_nr */ &fpid, /* tpgid */ - &f32, /* flags */ - &f32, /* minflt */ - &f32, /* cminflt */ - &f32, /* majflt */ - &f32, /* cmajflt */ + &f64, /* flags */ + &f64, /* minflt */ + &f64, /* cminflt */ + &f64, /* majflt */ + &f64, /* cmajflt */ &f64, /* utime */ &f64, /* stime */ &f64, /* cutime */ &f64, /* cstime */ &fint, /* priority */ &fint, /* nice */ - &f32, /* num_threads */ - &f32, /* itrealvalue */ + &f64, /* num_threads */ + &f64, /* itrealvalue */ &f64, /* starttime */ &f64, /* vsize */ &f64, /* rss */ @@ -78,26 +67,34 @@ static scanfunc_t_ref scanfuncs[STATVARS] = &f64, /* startstack */ &f64, /* kstkesp */ &f64, /* kstkeip */ - &f32, /* signal */ - &f32, /* blocked */ - &f32, /* sigignore */ - &f32, /* sigcatch */ + &f64, /* signal */ + &f64, /* blocked */ + &f64, /* sigignore */ + &f64, /* sigcatch */ &f64, /* wchan */ - &f32, /* nswap */ - &f32, /* cnswap */ - &f32, /* exit_signal */ - &f32, /* processor */ - &f32, /* rt_priority */ - &f32, /* policy */ + &f64, /* nswap */ + &f64, /* cnswap */ + &fint, /* exit_signal */ + &f64, /* processor */ + &f64, /* rt_priority */ + &f64, /* policy */ &f64, /* delayacct_blkio_ticks */ - &f32, /* guest_time */ - &f32 /* cguest_time */ + &f64, /* guest_time */ + &f64, /* cguest_time */ + &f64, /* start_data */ + &f64, /* end_data */ + &f64, /* start_brk */ + &f64, /* arg_start */ + &f64, /* arg_end */ + &f64, /* env_start */ + &f64, /* env_end */ + &fint /* exit_code */ } ; int s6ps_statparse (pscan_t *p) { uint64_t dummy64 ; - uint32_t dummy32 ; + int dummyint ; size_t pos = 0 ; void *scanresults[STATVARS] = { @@ -106,11 +103,11 @@ int s6ps_statparse (pscan_t *p) &p->session, &p->ttynr, &p->tpgid, - &dummy32, - &dummy32, - &dummy32, - &dummy32, - &dummy32, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, &p->utime, &p->stime, &p->cutime, @@ -118,7 +115,7 @@ int s6ps_statparse (pscan_t *p) &p->prio, &p->nice, &p->threads, - &dummy32, + &dummy64, &p->start, &p->vsize, &p->rss, @@ -128,27 +125,35 @@ int s6ps_statparse (pscan_t *p) &dummy64, &dummy64, &dummy64, - &dummy32, - &dummy32, - &dummy32, - &dummy32, + &dummy64, + &dummy64, + &dummy64, + &dummy64, &p->wchan, - &dummy32, - &dummy32, - &dummy32, + &dummy64, + &dummy64, + &dummy64, &p->cpuno, &p->rtprio, &p->policy, &dummy64, - &dummy32, - &dummy32 + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummy64, + &dummyint } ; unsigned int i = 0 ; if (!p->statlen) return 0 ; - pos = uint32_scan(p->data.s, &dummy32) ; + pos = uint64_scan(p->data.s, &dummy64) ; if (!pos) return 0 ; - if (dummy32 != p->pid) return 0 ; + if (dummy64 != p->pid) return 0 ; if (pos + 5 + p->commlen > p->statlen) return 0 ; if (p->data.s[pos++] != ' ') return 0 ; if (p->data.s[pos++] != '(') return 0 ; -- cgit v1.2.3