Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Jul 23, 2024
1 parent d72a577 commit 49f8ef0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include <argp.h>
#include <arpa/inet.h>
#include <asm-generic/errno-base.h>
#include <errno.h>
#include <limits.h>
#include <linux/types.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 2 additions & 0 deletions src/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>

#include "common/defs.h"
#include "mimic.h"

static int notify_systemd(const char* msg) {
Expand Down
28 changes: 14 additions & 14 deletions tools/extract-btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include <assert.h>
#include <linux/btf.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/defs.h"
#include "common/log.h"
#include "common/log_impl.h" // IWYU pragma: export
#include "common/try.h"
Expand All @@ -31,10 +33,8 @@ int main(int argc, char** argv) {
char* buf _cleanup_malloc_str = try_p(malloc(size), "cannot malloc: %s", strret);
try_e(fread(buf, 1, size, file), "failed to read file content: %s", strret);

struct {
struct btf_header* hdr;
char *type, *str;
} cur_btf = {};
struct btf_header* btf_hdr = NULL;
char *btf_type, *btf_str;

char *search_ptr, *old_search_ptr = buf;
size_t remain;
Expand All @@ -58,23 +58,23 @@ int main(int argc, char** argv) {
search_ptr - buf, hdr->flags, hdr->type_len, hdr->type_off, hdr->str_len,
hdr->str_off);

if (!cur_btf.hdr ||
cur_btf.hdr->type_len + cur_btf.hdr->str_len < hdr->type_len + hdr->str_len) {
cur_btf.hdr = hdr;
cur_btf.type = type;
cur_btf.str = str;
// Select largest BTF blob found, as it is most likely to be vmlinux's
if (!btf_hdr || btf_hdr->type_len + btf_hdr->str_len < hdr->type_len + hdr->str_len) {
btf_hdr = hdr;
btf_type = type;
btf_str = str;
}

cont:
old_search_ptr = search_ptr + sizeof(__u16);
}

// Stitch three parts together
cur_btf.hdr->type_off = 0;
cur_btf.hdr->str_off = cur_btf.hdr->type_len;
fwrite(cur_btf.hdr, 1, sizeof(*cur_btf.hdr), stdout);
fwrite(cur_btf.type, 1, cur_btf.hdr->type_len, stdout);
fwrite(cur_btf.str, 1, cur_btf.hdr->str_len, stdout);
btf_hdr->type_off = 0;
btf_hdr->str_off = btf_hdr->type_len;
fwrite(btf_hdr, 1, sizeof(*btf_hdr), stdout);
fwrite(btf_type, 1, btf_hdr->type_len, stdout);
fwrite(btf_str, 1, btf_hdr->str_len, stdout);

return 0;
}

0 comments on commit 49f8ef0

Please sign in to comment.