mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 14:25:03 +02:00
debug: add a logging module
This commit is contained in:
parent
90c0903f25
commit
7db89e973d
@ -2,6 +2,7 @@ Checks: >
|
|||||||
clang-analyzer-*,
|
clang-analyzer-*,
|
||||||
-clang-analyzer-security.insecureAPI.str*,
|
-clang-analyzer-security.insecureAPI.str*,
|
||||||
-clang-analyzer-security.insecureAPI.mem*,
|
-clang-analyzer-security.insecureAPI.mem*,
|
||||||
|
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
|
||||||
bugprone-*,
|
bugprone-*,
|
||||||
cert-*,
|
cert-*,
|
||||||
modernize-*,
|
modernize-*,
|
||||||
|
4
Makefile
4
Makefile
@ -12,10 +12,10 @@ ALLFLAGS=$(CFLAGS) -I$(IDIR)
|
|||||||
|
|
||||||
LIBS=-lpam
|
LIBS=-lpam
|
||||||
|
|
||||||
_DEPS = util.h ui.h config.h desktop.h auth.h efield.h keys.h users.h sessions.h chvt.h macros.h
|
_DEPS = log.h util.h ui.h config.h desktop.h auth.h efield.h keys.h users.h sessions.h chvt.h macros.h
|
||||||
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
|
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
|
||||||
|
|
||||||
_OBJ = main.o util.o ui.o config.o desktop.o auth.o efield.o users.o sessions.o chvt.o
|
_OBJ = main.o log.o util.o ui.o config.o desktop.o auth.o efield.o users.o sessions.o chvt.o
|
||||||
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
||||||
|
|
||||||
$(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
|
$(ODIR)/%.o: $(CDIR)/%.c $(DEPS)
|
||||||
|
12
include/log.h
Normal file
12
include/log.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef LOGH_
|
||||||
|
#define LOGH_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void log_init(FILE* fd);
|
||||||
|
void log_puts(const char* msg);
|
||||||
|
void log_printf(const char* fmt, ...);
|
||||||
|
// NOLINTNEXTLINE(readability-identifier-length)
|
||||||
|
void log_perror(const char* s);
|
||||||
|
|
||||||
|
#endif
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef MACROSH_
|
||||||
|
#define MACROSH_
|
||||||
|
|
||||||
// Do we just replace the compiler with clang??
|
// Do we just replace the compiler with clang??
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#define NULLABLE _Nullable
|
#define NULLABLE _Nullable
|
||||||
@ -16,3 +19,5 @@
|
|||||||
#else
|
#else
|
||||||
#define UNULLABLE
|
#define UNULLABLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
38
src/log.c
Normal file
38
src/log.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
static FILE* logger_out = NULL;
|
||||||
|
|
||||||
|
void log_init(FILE* fd) {
|
||||||
|
if (logger_out) (void)fclose(logger_out);
|
||||||
|
logger_out = fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_puts(const char* msg) {
|
||||||
|
if (!logger_out) return;
|
||||||
|
(void)fputs(msg, logger_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_printf(const char* fmt, ...) {
|
||||||
|
if (!logger_out) return;
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
(void)vfprintf(logger_out, fmt, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(readability-identifier-length)
|
||||||
|
void log_perror(const char* s) {
|
||||||
|
if (!logger_out) return;
|
||||||
|
|
||||||
|
if (s)
|
||||||
|
(void)fprintf(logger_out, "%s: %s", s, strerror(errno));
|
||||||
|
else
|
||||||
|
(void)fprintf(logger_out, "%s", strerror(errno));
|
||||||
|
}
|
14
src/main.c
14
src/main.c
@ -1,11 +1,13 @@
|
|||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "chvt.h"
|
#include "chvt.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
#include "sessions.h"
|
#include "sessions.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
@ -14,6 +16,18 @@
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc == 2) chvt_str(argv[1]);
|
if (argc == 2) chvt_str(argv[1]);
|
||||||
|
|
||||||
|
char* log_output = getenv("LIDM_LOG");
|
||||||
|
if (log_output) {
|
||||||
|
FILE* log_fd = fopen(log_output, "w");
|
||||||
|
if (!log_fd) {
|
||||||
|
perror("fopen");
|
||||||
|
(void)fputs("failed to open logfile in write mode", stderr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_init(log_fd);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user