From 844687809b7958d1c12ad80ec708157ee45154f4 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 26 Jul 2024 14:25:22 +0200 Subject: [PATCH] fix: missing \n (added perror too) --- src/sessions.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sessions.c b/src/sessions.c index eb2437c..8b8f14b 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -40,6 +40,7 @@ static u_int16_t used_size = 0; static struct session *sessions = NULL; static struct sessions_list *__sessions_list = NULL; +// NOTE: commented printf's here would be nice to have debug logs if I ever implement it static enum session_type session_type; static int fn(const char *fpath, const struct stat *sb, int typeflag) { // practically impossible to reach this @@ -47,12 +48,14 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { if (used_size == 0xffff) return 0; - if (!S_ISREG(sb->st_mode)) + if (sb == NULL || !S_ISREG(sb->st_mode)) return 0; + /*printf("gonna open %s\n", fpath);*/ FILE *fd = fopen(fpath, "r"); if (fd == NULL) { - fprintf(stderr, "error opening file (r) %s", fpath); + perror("fopen"); + fprintf(stderr, "error opening file (r) %s\n", fpath); return 0; } @@ -63,6 +66,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { char *exec_buf = NULL; char *tryexec_buf = NULL; while (true) { + /*printf(".");*/ char *buf = malloc(sb->st_blksize); ssize_t read_size = getline(&buf, &alloc_size, fd); if (read_size == -1) { @@ -91,11 +95,13 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { if (found == 0b111) break; } + /*printf("\nend parsing...\n");*/ fclose(fd); // just add this to the list if (name_buf != NULL && exec_buf != NULL) { + /*printf("gonna add to session list\n");*/ if (used_size >= alloc_size) { alloc_size += bs; sessions = realloc(sessions, alloc_size * unit_size); @@ -128,6 +134,7 @@ struct sessions_list *get_avaliable_sessions() { for (uint i = 0; i < sources_size; i++) { session_type = sources[i].type; + /*printf("recurring into %s\n", sources[i].dir);*/ ftw(sources[i].dir, &fn, 1); }