dev: start to implement logger in some places

This commit is contained in:
javalsai 2025-06-11 17:15:30 +02:00
parent c88bdaea06
commit a95f71f7a5
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
3 changed files with 18 additions and 9 deletions

View File

@ -14,8 +14,6 @@
#include "util.h" #include "util.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc == 2) chvt_str(argv[1]);
char* log_output = getenv("LIDM_LOG"); char* log_output = getenv("LIDM_LOG");
if (log_output) { if (log_output) {
FILE* log_fd = fopen(log_output, "w"); FILE* log_fd = fopen(log_output, "w");
@ -28,6 +26,8 @@ int main(int argc, char* argv[]) {
log_init(log_fd); log_init(log_fd);
} }
if (argc == 2) chvt_str(argv[1]);
char* conf_override = getenv("LIDM_CONF"); char* conf_override = getenv("LIDM_CONF");
struct config* config = struct config* config =
parse_config(conf_override == NULL ? "/etc/lidm.ini" : conf_override); parse_config(conf_override == NULL ? "/etc/lidm.ini" : conf_override);

View File

@ -8,6 +8,7 @@
#include <sys/types.h> #include <sys/types.h>
#include "desktop.h" #include "desktop.h"
#include "log.h"
#include "sessions.h" #include "sessions.h"
#include "util.h" #include "util.h"
@ -48,8 +49,10 @@ struct status cb(void* _ctx, char* NULLABLE table, char* key, char* value) {
if (copy_at != NULL) { if (copy_at != NULL) {
*copy_at = strdup(value); *copy_at = strdup(value);
if (*copy_at == NULL) { if (*copy_at == NULL) {
log_perror("strdup");
log_puts("[E] failed to allocate memory");
ret.finish = true; ret.finish = true;
ret.ret = -1; // malloc error ret.ret = -1;
} }
} }
@ -70,6 +73,7 @@ static int fn(const char* fpath, const struct stat* sb, int typeflag) {
// - FTW_PHYS if set doesn't follow symlinks, so ftw() has no flags and it // - FTW_PHYS if set doesn't follow symlinks, so ftw() has no flags and it
// follows symlinks, we should never get to handle that // follows symlinks, we should never get to handle that
if (typeflag != FTW_F) return 0; if (typeflag != FTW_F) return 0;
log_printf("[I] found file %s\n", fpath);
struct ctx_typ ctx = { struct ctx_typ ctx = {
.name = NULL, .name = NULL,
@ -79,14 +83,14 @@ static int fn(const char* fpath, const struct stat* sb, int typeflag) {
FILE* fd = fopen(fpath, "r"); FILE* fd = fopen(fpath, "r");
if (fd == NULL) { if (fd == NULL) {
perror("fopen"); log_perror("fopen");
// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) log_printf("[E] error opening file '%s' for read\n", fpath);
(void)fprintf(stderr, "error opening file '%s' for read\n", fpath);
return 0; return 0;
} }
int ret = read_desktop(fd, &ctx, &cb); int ret = read_desktop(fd, &ctx, &cb);
if (ret < 0) { // any error if (ret < 0) { // any error
log_printf("[E] format error parsing %s", fpath);
return 0; return 0;
} }
@ -118,7 +122,7 @@ struct Vector get_avaliable_sessions() {
cb_sessions = &sessions; cb_sessions = &sessions;
for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) { for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {
/*printf("recurring into %s\n", sources[i].dir);*/ log_printf("[I] parsing into %s\n", sources[i].dir);
session_type = sources[i].type; session_type = sources[i].type;
ftw(sources[i].dir, &fn, 1); ftw(sources[i].dir, &fn, 1);
} }

View File

@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "log.h"
#include "macros.h" #include "macros.h"
#include "users.h" #include "users.h"
#include "util.h" #include "util.h"
@ -46,15 +47,19 @@ struct Vector get_human_users() {
struct passwd* NULLABLE pwd; struct passwd* NULLABLE pwd;
while ((pwd = getpwent()) != NULL) { while ((pwd = getpwent()) != NULL) {
log_printf("[I] handling user %s\n", pwd->pw_name);
// `- 1` bcs sizeof counts the nullbyte // `- 1` bcs sizeof counts the nullbyte
if (pwd->pw_dir && strncmp(pwd->pw_dir, "/home/", sizeof("/home/") - 1) != 0) if (pwd->pw_dir &&
strncmp(pwd->pw_dir, "/home/", sizeof("/home/") - 1) != 0)
continue; continue;
log_printf("[I] found %s\n", pwd->pw_name);
struct user* user_i = malloc(sizeof(struct user)); struct user* user_i = malloc(sizeof(struct user));
if (user_i == NULL) continue; // malloc error if (user_i == NULL) continue; // malloc error
if (build_user(user_i, pwd) != 0) { if (build_user(user_i, pwd) != 0) {
// ... log_printf("[E] failed to allocate allocate memory for %s\n",
pwd->pw_name);
} }
vec_push(&users, user_i); vec_push(&users, user_i);
} }