summaryrefslogtreecommitdiff
path: root/src/minutils/s6ps_statparse.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-04-12 13:44:02 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-04-12 13:44:02 +0000
commit0b37a8b8e99c0f34bdaf406af2b9aca4e56e1d9d (patch)
treee5f409137f1201840e555c64639346f16a6316cd /src/minutils/s6ps_statparse.c
parent1d3de2e015b24e3c34e678227acb24a490462f8b (diff)
downloads6-linux-utils-0b37a8b8e99c0f34bdaf406af2b9aca4e56e1d9d.tar.xz
Replace fd_writev with buffer_write in s6-uevent-listener
Diffstat (limited to 'src/minutils/s6ps_statparse.c')
-rw-r--r--src/minutils/s6ps_statparse.c125
1 files changed, 65 insertions, 60 deletions
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 ;