Skip to content

eBPF-based security platform

util: follow the kernel coding style in the remaining helpers

Daniel Borkmann8842744b435e
diff --git a/util/config.c b/util/config.c
index 124d91ca..79650b34 100644
--- a/util/config.c
+++ b/util/config.c
@@ -181,7 +181,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
map_export_bad(cfg, key, val, "value too long");
else if (val[0] && val[0] != '/')
map_export_bad(cfg, key, val,
- "path must be absolute");
+ "path must be absolute");
} else if (strcmp(key, "map_export.otel_endpoint") == 0) {
if (!set_string(cfg->map_export_otel_endpoint,
sizeof(cfg->map_export_otel_endpoint), val))
@@ -189,8 +189,8 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
} else if (strcmp(key, "map_export.tenant_id") == 0) {
if (val[0] && !shirudo_tenant_id_valid(val))
map_export_bad(cfg, key, val,
- "expected 1..128 characters from "
- "A-Z, a-z, 0-9, '.', '_', '-'");
+ "expected 1..128 characters from "
+ "A-Z, a-z, 0-9, '.', '_', '-'");
else
(void)set_string(cfg->map_export_tenant_id,
sizeof(cfg->map_export_tenant_id),
@@ -199,7 +199,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
if (!parse_bool(val,
&cfg->map_export_otel_insecure))
map_export_bad(cfg, key, val,
- "expected true or false");
+ "expected true or false");
} else if (strcmp(key, "map_export.otel_retries") == 0) {
unsigned long v;
char *end;
@@ -208,7 +208,7 @@ int shirudo_config_load_path(struct shirudo_config *cfg, const char *path)
v = strtoul(val, &end, 10);
if (errno || *end || v > 10)
map_export_bad(cfg, key, val,
- "expected 0..10");
+ "expected 0..10");
else
cfg->map_export_otel_retries =
(unsigned int)v;
diff --git a/util/help.c b/util/help.c
index 508a7f89..1f719eea 100644
--- a/util/help.c
+++ b/util/help.c
@@ -107,7 +107,7 @@ void shirudo_print_help(const struct shirudo_help *h)
fprintf(stderr, "\n%s\n", s->header);
for (j = 0; j < s->n_items; j++) {
size_t indent = 2 + w;
- size_t avail = SHIRUDO_HELP_WIDTH > indent ?
+ size_t avail = indent < SHIRUDO_HELP_WIDTH ?
SHIRUDO_HELP_WIDTH - indent : 1;
fprintf(stderr, " %-*s", (int)w, s->items[j].name);
diff --git a/util/kernel_build_id.c b/util/kernel_build_id.c
index ff43a70f..e9388701 100644
--- a/util/kernel_build_id.c
+++ b/util/kernel_build_id.c
@@ -27,7 +27,7 @@ static int read_u32(const unsigned char *p, size_t remaining, uint32_t *out)
}
int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
+ char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
{
const unsigned char *p = notes;
@@ -64,8 +64,7 @@ int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
return -ENOENT;
}
-int shirudo_kernel_build_id_read(
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
+int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX])
{
unsigned char notes[KERNEL_NOTES_MAX];
size_t len = 0;
diff --git a/util/kernel_build_id.h b/util/kernel_build_id.h
index 7c433399..7c066878 100644
--- a/util/kernel_build_id.h
+++ b/util/kernel_build_id.h
@@ -11,9 +11,8 @@
(SHIRUDO_KERNEL_BUILD_ID_MAX * 2u + 1u)
int shirudo_kernel_build_id_from_notes(const void *notes, size_t notes_len,
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
+ char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
-int shirudo_kernel_build_id_read(
- char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
+int shirudo_kernel_build_id_read(char out[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX]);
#endif /* SHIRUDO_KERNEL_BUILD_ID_H */
diff --git a/util/kernel_release.c b/util/kernel_release.c
index 502a2cbc..fe316e3f 100644
--- a/util/kernel_release.c
+++ b/util/kernel_release.c
@@ -6,7 +6,7 @@
#include "kernel_release.h"
bool shirudo_kernel_release_prefix_matches(const char *release,
- const char *prefix)
+ const char *prefix)
{
size_t len;
diff --git a/util/kernel_release.h b/util/kernel_release.h
index 038f6e67..88676f6d 100644
--- a/util/kernel_release.h
+++ b/util/kernel_release.h
@@ -7,6 +7,6 @@
#include <stdbool.h>
bool shirudo_kernel_release_prefix_matches(const char *release,
- const char *prefix);
+ const char *prefix);
#endif /* SHIRUDO_KERNEL_RELEASE_H */
diff --git a/util/kmodules.c b/util/kmodules.c
index 3352df4a..10c23325 100644
--- a/util/kmodules.c
+++ b/util/kmodules.c
@@ -105,9 +105,10 @@ int shirudo_kmodules_read(struct shirudo_kmod_set *set)
if (rc)
return rc;
end = buf + strlen(buf);
- for (line = buf; line < end; line++)
+ for (line = buf; line < end; line++) {
if (*line == '\n')
*line = '\0';
+ }
set->mods = xmalloc(mod_cap * sizeof(*set->mods));
set->deps = xmalloc(deps_cap * sizeof(*set->deps));
@@ -303,7 +304,7 @@ static void print_subtree(const struct shirudo_kmod_set *set, size_t i,
seen[i >> 3] |= (uint8_t)(1U << (i & 7));
printf("%s%s%s (%s, refs=%u)\n", prefix, branch, m->name,
- size_s, (unsigned)m->refcount);
+ size_s, (unsigned int)m->refcount);
snprintf(child_prefix, sizeof(child_prefix), "%s%s", prefix,
is_last ? " " : "│ ");
@@ -354,9 +355,10 @@ void shirudo_kmodules_print_tree(const struct shirudo_kmod_set *set)
used_by[d >> 3] |= (uint8_t)(1U << (d & 7));
}
}
- for (size_t i = 0; i < set->n; i++)
+ for (size_t i = 0; i < set->n; i++) {
if (((used_by[i >> 3] >> (i & 7)) & 1) == 0)
roots[n_roots++] = i;
+ }
for (size_t r = 0; r < n_roots; r++) {
int is_last = (r == n_roots - 1);
@@ -427,14 +429,13 @@ void shirudo_kmodules_print_recent(const struct shirudo_kmod_set *set,
snprintf(ts, sizeof(ts), "?");
shirudo_human_size(m->size, size_s, sizeof(size_s));
if (boot_sec > 0 && m->loaded_at_sec >= boot_sec)
- shirudo_format_duration(
- (long)(m->loaded_at_sec - boot_sec),
- age, sizeof(age));
+ shirudo_format_duration((long)(m->loaded_at_sec - boot_sec),
+ age, sizeof(age));
else
snprintf(age, sizeof(age), "?");
printf(" [%s] %s (%s, refs=%u, %s since boot)\n",
- ts, m->name, size_s, (unsigned)m->refcount, age);
+ ts, m->name, size_s, (unsigned int)m->refcount, age);
}
xfree(all, set->n * sizeof(*all));
}
diff --git a/util/paths.h b/util/paths.h
index 315646b1..4509d407 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -151,7 +151,7 @@ static inline int shirudo_upatch_bpffs_name(char *out, size_t out_sz,
}
static inline int shirudo_upatch_name_from_bpffs(char *out, size_t out_sz,
- const char *name)
+ const char *name)
{
size_t i, j;
diff --git a/util/preflight.c b/util/preflight.c
index ea269f7f..fa271955 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -38,9 +38,9 @@
#define PREFLIGHT_CERT_MAX (1u * 1024u * 1024u)
-static struct shirudo_preflight_check *next_slot(
- struct shirudo_preflight_result *r,
- enum shirudo_preflight_id id, const char *name)
+static struct shirudo_preflight_check *
+next_slot(struct shirudo_preflight_result *r, enum shirudo_preflight_id id,
+ const char *name)
{
struct shirudo_preflight_check *c = &r->checks[r->n++];
@@ -77,7 +77,7 @@ static void check_root(struct shirudo_preflight_result *r)
pass(c);
else
fail(r, c, "must run as root (EUID=%u)",
- (unsigned)geteuid());
+ (unsigned int)geteuid());
}
static bool lsm_lists_bpf(void)
@@ -95,9 +95,10 @@ static bool lsm_lists_bpf(void)
return false;
buf[n] = '\0';
- for (char *p = strtok(buf, ",\n"); p; p = strtok(NULL, ",\n"))
+ for (char *p = strtok(buf, ",\n"); p; p = strtok(NULL, ",\n")) {
if (strcmp(p, "bpf") == 0)
return true;
+ }
return false;
}
diff --git a/util/sysinfo.c b/util/sysinfo.c
index 9f82e01c..22cd4561 100644
--- a/util/sysinfo.c
+++ b/util/sysinfo.c
@@ -155,7 +155,7 @@ static int kernel_config_entry_cmp(const void *a, const void *b)
}
static void kernel_config_entries_free(struct kernel_config_entry *entries,
- size_t n)
+ size_t n)
{
size_t i;
@@ -167,8 +167,8 @@ static void kernel_config_entries_free(struct kernel_config_entry *entries,
}
int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
- shirudo_kernel_config_cb cb,
- void *ctx)
+ shirudo_kernel_config_cb cb,
+ void *ctx)
{
char path[PATH_MAX];
char line[8192];
@@ -223,7 +223,7 @@ int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
struct kernel_config_entry *next;
next = xreallocarray(entries, n, n + 1,
- sizeof(*entries));
+ sizeof(*entries));
if (!next) {
fclose(f);
kernel_config_entries_free(entries, n);
@@ -255,17 +255,17 @@ int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
}
static void emit_kernel_config_entry(void *ctx, const char *key,
- const char *value)
+ const char *value)
{
shirudo_json_kv_string(ctx, key, value);
}
static void emit_kernel_config(struct shirudo_json_emit *e,
- const char *kernel_release)
+ const char *kernel_release)
{
shirudo_json_obj_open_key(e, "kernel_config");
shirudo_sysinfo_kernel_config_foreach(kernel_release,
- emit_kernel_config_entry, e);
+ emit_kernel_config_entry, e);
shirudo_json_obj_close(e);
}
diff --git a/util/sysinfo.h b/util/sysinfo.h
index 90afba01..f85b8173 100644
--- a/util/sysinfo.h
+++ b/util/sysinfo.h
@@ -37,8 +37,8 @@ typedef void (*shirudo_kernel_config_cb)(void *ctx, const char *key,
const char *value);
int shirudo_sysinfo_kernel_config_foreach(const char *kernel_release,
- shirudo_kernel_config_cb cb,
- void *ctx);
+ shirudo_kernel_config_cb cb,
+ void *ctx);
void shirudo_sysinfo_emit_json(struct shirudo_json_emit *e,
const struct shirudo_sysinfo *si);