diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-25 17:07:23 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-25 17:07:23 -0700 |
commit | 715c71340d771feb5dc3526af339ed319aeea7ac (patch) | |
tree | d628eb72813fefa76a5d731063a359087bc3f69c /src | |
parent | a3b40ded1276afe8e9e426c39d721a9ccb989eb8 (diff) |
libvmon: wrap X-Macro parser state in a struct
This makes no functional difference, but silences warnings about
unused variables when -Wall is enabled.
Diffstat (limited to 'src')
-rw-r--r-- | src/libvmon/defs/_begin.def | 167 | ||||
-rw-r--r-- | src/libvmon/vmon.c | 14 |
2 files changed, 92 insertions, 89 deletions
diff --git a/src/libvmon/defs/_begin.def b/src/libvmon/defs/_begin.def index c8be434..2ca75b2 100644 --- a/src/libvmon/defs/_begin.def +++ b/src/libvmon/defs/_begin.def @@ -127,16 +127,19 @@ /* most the stuff we need in scope for the parser generated via VMON_IMPLEMENT_PARSER before including the appropriate .def */ #ifdef VMON_PREPARE_PARSER - char input; - int var_isneg = 0; - int var_int = 0; - unsigned int var_uint = 0; - long var_long = 0; - long long var_longlong = 0; - unsigned long var_ulong = 0; - unsigned long long var_ulonglong = 0; - char *var_array = NULL; - int var_array_alloc_len = 0, var_array_len = 0; + struct _parser { + char input; + int var_isneg; + int var_int; + unsigned int var_uint; + long var_long; + long long var_longlong; + unsigned long var_ulong; + unsigned long long var_ulonglong; + char *var_array; + int var_array_alloc_len; + int var_array_len; + } _p = {}; #define vmon_datum_str(_name, _sym, _label, _desc) #define vmon_datum_str_array(_name, _sym, _label, _desc) @@ -174,12 +177,12 @@ * names etc. */ #define vmon_datum_str(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case VMON_PARSER_DELIM:\ /* store accumulated string, reset tmp, and advance */\ if ((*store)->_name) {\ - if ( strncmp((*store)->name, _array, var_array_len) ||\ - (*store)->name[var_array_len] != '\0') {\ + if ( strncmp((*store)->name, _p.var_array, _p.var_array_len) ||\ + (*store)->name[_p.var_array_len] != '\0') {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ }\ @@ -188,13 +191,13 @@ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ }\ - (*store)->_name = strndup(var_array, var_array_len);\ - var_array_len = 0;\ + (*store)->_name = strndup(_p.var_array, _p.var_array_len);\ + _p.var_array_len = 0;\ state++;\ break;\ default:\ /* accumulate string */\ - var_array[var_array_len++] = input;\ + _p.var_array[_p.var_array_len++] = _p.input;\ break;\ }\ break; @@ -204,10 +207,10 @@ break; #define vmon_datum_char(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if ((*store)->_name != input) {\ + if ((*store)->_name != _p.input) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = input;\ + (*store)->_name = _p.input;\ }\ state++;\ break; @@ -218,26 +221,26 @@ break; #define vmon_datum_int(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '-':\ /* TODO: we don't verify the '-' is leading... */\ - var_isneg = 1;\ + _p.var_isneg = 1;\ break;\ case '0' ... '9':\ - var_int *= 10;\ - var_int += input - '0';\ + _p.var_int *= 10;\ + _p.var_int += _p.input - '0';\ break;\ default:\ - if (var_isneg) {\ - var_int = -var_int;\ - var_isneg = 0;\ + if (_p.var_isneg) {\ + _p.var_int = -_p.var_int;\ + _p.var_isneg = 0;\ }\ - if ((*store)->_name != var_int) {\ + if ((*store)->_name != _p.var_int) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_int;\ + (*store)->_name = _p.var_int;\ }\ - var_int = 0;\ + _p.var_int = 0;\ state++;\ break;\ }\ @@ -246,18 +249,18 @@ break; #define vmon_datum_uint(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ - var_uint *= 10;\ - var_uint += input - '0';\ + _p.var_uint *= 10;\ + _p.var_uint += _p.input - '0';\ break;\ default:\ - if ((*store)->_name != var_uint) {\ + if ((*store)->_name != _p.var_uint) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_uint;\ + (*store)->_name = _p.var_uint;\ }\ - var_uint = 0;\ + _p.var_uint = 0;\ state++;\ break;\ }\ @@ -266,18 +269,18 @@ break; #define vmon_datum_ulong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ - var_ulong *= 10;\ - var_ulong += input - '0';\ + _p.var_ulong *= 10;\ + _p.var_ulong += _p.input - '0';\ break;\ default:\ - if ((*store)->_name != var_ulong) {\ + if ((*store)->_name != _p.var_ulong) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_ulong;\ + (*store)->_name = _p.var_ulong;\ }\ - var_ulong = 0;\ + _p.var_ulong = 0;\ state++;\ break;\ }\ @@ -286,18 +289,18 @@ break; #define vmon_datum_ulonglong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ - var_ulonglong *= 10;\ - var_ulonglong += input - '0';\ + _p.var_ulonglong *= 10;\ + _p.var_ulonglong += _p.input - '0';\ break;\ default:\ - if ((*store)->_name != var_ulonglong) {\ + if ((*store)->_name != _p.var_ulonglong) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_ulonglong;\ + (*store)->_name = _p.var_ulonglong;\ }\ - var_ulonglong = 0;\ + _p.var_ulonglong = 0;\ state++;\ break;\ }\ @@ -306,26 +309,26 @@ break; #define vmon_datum_long(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '-':\ /* TODO: we dont verify the '-' is leading... */\ - var_isneg = 1;\ + _p.var_isneg = 1;\ break;\ case '0' ... '9':\ - var_long *= 10;\ - var_long += input - '0';\ + _p.var_long *= 10;\ + _p.var_long += _p.input - '0';\ break;\ default:\ - if (var_isneg) {\ - var_long = -var_long;\ - var_isneg = 0;\ + if (_p.var_isneg) {\ + _p.var_long = -_p.var_long;\ + _p.var_isneg = 0;\ }\ - if ((*store)->_name != var_long) {\ + if ((*store)->_name != _p.var_long) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_long;\ + (*store)->_name = _p.var_long;\ }\ - var_long = 0;\ + _p.var_long = 0;\ state++;\ break;\ }\ @@ -334,26 +337,26 @@ break; #define vmon_datum_longlong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '-':\ /* TODO: we dont verify the '-' is leading... */\ - var_isneg = 1;\ + _p.var_isneg = 1;\ break;\ case '0' ... '9':\ - var_longlong *= 10;\ - var_longlong += input - '0';\ + _p.var_longlong *= 10;\ + _p.var_longlong += _p.input - '0';\ break;\ default:\ - if (var_isneg) {\ - var_longlong = -var_longlong;\ - var_isneg = 0;\ + if (_p.var_isneg) {\ + _p.var_longlong = -_p.var_longlong;\ + _p.var_isneg = 0;\ }\ - if ((*store)->_name != var_longlong) {\ + if ((*store)->_name != _p.var_longlong) {\ BITSET((*store)->changed, VMON_ ## _sym);\ changes++;\ - (*store)->_name = var_longlong;\ + (*store)->_name = _p.var_longlong;\ }\ - var_longlong = 0;\ + _p.var_longlong = 0;\ state++;\ break;\ }\ @@ -363,24 +366,24 @@ /* parse but simply skip omitted fields, advance on the delimiter */ #define vmon_omit_n(_n, _sym, _desc) case VMON_PARSER_STATE_ ## _sym:\ - var_int++;\ - if (var_int >= _n) {\ - var_int = 0;\ + _p.var_int++;\ + if (_p.var_int >= _n) {\ + _p.var_int = 0;\ state++;\ }\ break; #define vmon_omit_literal(_lit, _sym) case VMON_PARSER_STATE_ ## _sym:\ /* TODO make this actually match the literal, for now we skip the length. */ \ - var_int++;\ - if (var_int >= (sizeof(_lit) - 1)) {\ - var_int = 0;\ + _p.var_int++;\ + if (_p.var_int >= (sizeof(_lit) - 1)) {\ + _p.var_int = 0;\ state++;\ }\ break; #define vmon_omit_run(_char, _sym) case VMON_PARSER_STATE_ ## _sym:\ - if (input != _char) {\ + if (_p.input != _char) {\ state++;\ /* XXX: we fall-through to the next case because this byte belongs to the next state */\ } else {\ @@ -389,14 +392,14 @@ #define vmon_omit_str(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if (input == VMON_PARSER_DELIM) {\ + if (_p.input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ } #define vmon_omit_str_array(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if (input == VMON_PARSER_DELIM) {\ + if (_p.input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ @@ -407,14 +410,14 @@ break; #define vmon_omit_char_array(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - if (input == VMON_PARSER_DELIM) {\ + if (_p.input == VMON_PARSER_DELIM) {\ state++;\ } else {\ break;\ } #define vmon_omit_int(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ case '-':\ break;\ @@ -427,7 +430,7 @@ break;\ #define vmon_omit_uint(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ break;\ default:\ @@ -439,7 +442,7 @@ break; #define vmon_omit_ulong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ break;\ default:\ @@ -451,7 +454,7 @@ break; #define vmon_omit_ulonglong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ break;\ default:\ @@ -463,7 +466,7 @@ break; #define vmon_omit_long(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ case '-':\ break;\ @@ -476,7 +479,7 @@ break; #define vmon_omit_longlong(_name, _sym, _label, _desc) case VMON_PARSER_STATE_ ## _sym:\ - switch (input) {\ + switch (_p.input) {\ case '0' ... '9':\ case '-':\ break;\ diff --git a/src/libvmon/vmon.c b/src/libvmon/vmon.c index fead0a8..6ba4c6e 100644 --- a/src/libvmon/vmon.c +++ b/src/libvmon/vmon.c @@ -270,7 +270,7 @@ static sample_ret_t proc_sample_stat(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_ return DTOR_FREE; } -_retry: +/* _retry: */ if (!(*store)) { /* ctor */ *store = calloc(1, sizeof(vmon_proc_stat_t)); @@ -328,7 +328,7 @@ _retry: readlinkf(vmon, &(*store)->exe, vmon->proc_dir, "%i/exe", proc->pid); /* XXX TODO: there's a race between discovering comm_len from /proc/$pid/comm and applying it in the parsing of /proc/$pid/stat, detect the race - * scenario and retry the sample when detected by goto _retry */ + * scenario and retry the sample when detected by goto _retry (see commented _retry label above) */ /* read in stat and parse it assigning the stat members accordingly */ while ((len = try_pread((*store)->stat_fd, vmon->buf, sizeof(vmon->buf), total)) > 0) { @@ -336,7 +336,7 @@ _retry: for (i = 0; i < len; i++) { /* parse the fields from the file, stepping through... */ - input = vmon->buf[i]; + _p.input = vmon->buf[i]; switch (state) { #define VMON_PARSER_DELIM ' ' /* TODO XXX eliminate the need for this, I want the .def's to include all the data format knowledge */ #define VMON_IMPLEMENT_PARSER @@ -811,7 +811,7 @@ static sample_ret_t proc_sample_vm(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_vm for (i = 0; i < len; i++) { /* parse the fields from the file, stepping through... */ - input = vmon->buf[i]; + _p.input = vmon->buf[i]; switch (state) { #define VMON_IMPLEMENT_PARSER #include "defs/proc_vm.def" @@ -868,7 +868,7 @@ static sample_ret_t proc_sample_io(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_io for (i = 0; i < len; i++) { /* parse the fields from the file, stepping through... */ - input = vmon->buf[i]; + _p.input = vmon->buf[i]; switch (state) { #define VMON_IMPLEMENT_PARSER #include "defs/proc_io.def" @@ -914,7 +914,7 @@ static sample_ret_t sys_sample_stat(vmon_t *vmon, vmon_sys_stat_t **store) total += len; for (i = 0; i < len; i++) { - input = vmon->buf[i]; + _p.input = vmon->buf[i]; switch (state) { #define VMON_PARSER_DELIM ' ' /* TODO XXX eliminate the need for this, I want the .def's to include all the data format knowledge */ #define VMON_IMPLEMENT_PARSER @@ -964,7 +964,7 @@ static sample_ret_t sys_sample_vm(vmon_t *vmon, vmon_sys_vm_t **store) total += len; for (i = 0; i < len; i++) { - input = vmon->buf[i]; + _p.input = vmon->buf[i]; switch (state) { #define VMON_PARSER_DELIM ' ' /* TODO XXX eliminate the need for this, I want the .def's to include all the data format knowledge */ #define VMON_IMPLEMENT_PARSER |