summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-04-13 07:21:15 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-04-13 07:21:15 +0000
commit30bb26f896777144eb20a620440a97fa5c2be50f (patch)
treee96ee59231187e62e494caf2bea4baffe2a31bb9
parent0b37a8b8e99c0f34bdaf406af2b9aca4e56e1d9d (diff)
downloads6-linux-utils-30bb26f896777144eb20a620440a97fa5c2be50f.tar.gz
s6-linux-utils-30bb26f896777144eb20a620440a97fa5c2be50f.tar.xz
s6-linux-utils-30bb26f896777144eb20a620440a97fa5c2be50f.zip
Fix s6-ps types parsing
 The documented type lengths for /proc/$pid/stat in "man 5 proc" are for
*kernel* types. Those lengths may not apply to userland types (think
32-bit userspace on 64-bit kernels). So we need to parse everything as
64-bit, and do the conversion to userspace types later.
 Thanks to mixi for the report and the analysis.
-rw-r--r--src/minutils/s6ps_statparse.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/minutils/s6ps_statparse.c b/src/minutils/s6ps_statparse.c
index 0b1b261..56e00f9 100644
--- a/src/minutils/s6ps_statparse.c
+++ b/src/minutils/s6ps_statparse.c
@@ -9,6 +9,7 @@
 #include <skalibs/tai.h>
 #include "s6-ps.h"
 
+
  /*
     going to great lengths to avoid scanf(), but all this code
     is still smaller than scanf (no floating point parsing etc.)
@@ -25,7 +26,7 @@ static size_t f64 (char const *s, void *u64)
   return uint64_scan(s, u) ;
 }
 
-#define DEFUN(name, type) \
+#define DEFUNU(name, type) \
 static size_t name (char const *s, void *p) \
 { \
   uint64_t u ; \
@@ -34,9 +35,18 @@ static size_t name (char const *s, void *p) \
   return len ; \
 } \
 
-DEFUN(fint, int)
-DEFUN(fpid, pid_t)
-DEFUN(fdev, dev_t)
+#define DEFUNS(name, type) \
+static size_t name (char const *s, void *p) \
+{ \
+  int64_t d ; \
+  size_t len = int64_scan(s, &d) ; \
+  *(type *)p = d ; \
+  return len ; \
+} \
+
+DEFUNS(fint, int)
+DEFUNS(fpid, pid_t)
+DEFUNU(fdev, dev_t)
 
 static scanfunc_t_ref scanfuncs[STATVARS] =
 {