Fixes #2518 -- weird behaviour of lookup_or_init (#2520)
* Allow lookup_or_init to return NULL (rather than just returning from the current function)
* Fixed a couple of bad edits found when running tests. Also fixed a bug in the
test runner. Also fixed a bug in libbcc where the python signature did not match
the actual implementation.
diff --git a/tools/syscount.py b/tools/syscount.py
index 6cbea11..21e788d 100755
--- a/tools/syscount.py
+++ b/tools/syscount.py
@@ -133,12 +133,16 @@
return 0;
val = data.lookup_or_init(&key, &zero);
- val->count++;
- val->total_ns += bpf_ktime_get_ns() - *start_ns;
+ if (val) {
+ val->count++;
+ val->total_ns += bpf_ktime_get_ns() - *start_ns;
+ }
#else
u64 *val, zero = 0;
val = data.lookup_or_init(&key, &zero);
- ++(*val);
+ if (val) {
+ ++(*val);
+ }
#endif
return 0;
}