From c73b58707848ef3996bd9656902e08482fe50057 Mon Sep 17 00:00:00 2001 From: twoneis Date: Fri, 4 Apr 2025 00:43:22 +0200 Subject: [PATCH] error handling for non-loaded module --- code/leak.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/leak.c b/code/leak.c index d590d9390..061798b81 100644 --- a/code/leak.c +++ b/code/leak.c @@ -9,9 +9,10 @@ #include "pipe_utils.c" +#define LKM_DEVICE "/dev/lkm" + // where does this come from? #define OBJS_PER_SLAB 42 - #define PIPE_BUFFER (OBJS_PER_SLAB * 10) int pipes[PIPE_BUFFER][2]; @@ -20,9 +21,15 @@ int main(void) { printf("main: start\n"); - FILE *device = fopen("/dev/lkm", "r+"); + FILE *device = fopen(LKM_DEVICE, "r+"); printf("main: fopen: %p\n", device); + if (!device) { + printf( + "main: fopen: Error opening %s. Make sure the kernel module is loaded\n", + LKM_DEVICE); + exit(1); + } printf("main: draining lower page free lists: %u objects\n", PIPE_BUFFER);