change makefile

This commit is contained in:
gandc committed 2024-11-29 21:28:10 +03:00
1 parent aadd29ac73
commit bf94bc25a5
6 files changed
+222 -47

No files matched your search

+11 -10
View File
@@ -1,16 +1,17 @@
CC = gcc
CFLAGS = -Wall -g
LDFLAGS = -lm
CFLAGS = -Wall -Wextra -I../libmysyslog
LDFLAGS = -L../libmysyslog -lmysyslog
TARGET = libmysyslog-daemon
LIBS = -lmysyslog -lmysyslog-text -lmysyslog-json
all: $(TARGET)
all: mysyslog-daemon
$(TARGET): libmysyslog-daemon.o
$(CC) -o $(TARGET) libmysyslog-daemon.o $(LDFLAGS)
mysyslog-daemon: src/mysyslog-daemon.o
$(CC) -o $@ $^ $(LIBS)
libmysyslog-daemon.o: libmysyslog-daemon.c
$(CC) $(CFLAGS) -c libmysyslog-daemon.c
clean: rm -f src/*.o mysyslog-daemon
clean:
rm -f $(TARGET) *.o
deb: # Deb package building logic
.PHONY: all clean deb
.PHONY: all clean
+44
View File
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "libmysyslog.h"
#define CONFIG_PATH "/etc/mysyslog/mysyslog.cfg"
static volatile int keepRunning = 1;
void intHandler(int dummy) {
keepRunning = 0;
}
void read_config(const char* path, int* level, int* driver, int* format, char* log_path) {
FILE* file = fopen(path, "r");
if (!file) {
fprintf(stderr, "Could not open config file: %s\n", path);
exit(EXIT_FAILURE);
}
fscanf(file, "level=%d\n", level);
fscanf(file, "driver=%d\n", driver);
fscanf(file, "format=%d\n", format);
fscanf(file, "path=%s\n", log_path);
fclose(file);
}
int main() {
signal(SIGINT, intHandler);
signal(SIGTERM, intHandler);
int level, driver, format;
char log_path[256];
read_config(CONFIG_PATH, &level, &driver, &format, log_path);
while (keepRunning) {
mysyslog("Daemon log message", level, driver, format, log_path);
sleep(5); // Log every 5 seconds
}
return 0;
}
+4
View File
@@ -0,0 +1,4 @@
level=1
driver=0
format=0
path=/var/log/mysyslog.log
-27
View File
@@ -1,27 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include "mysyslog.h"
static volatile int keep_running = 1;
void int_handler(int dummy) {
keep_running = 0;
}
int main() {
signal(SIGINT, int_handler);
signal(SIGTERM, int_handler);
const char* path = "/var/log/mysyslog.log";
int driver = 1; // Default to text driver
int format = 1; // Default to text format
while (keep_running) {
mysyslog("Daemon log message", INFO, driver, format, path);
sleep(60); // Log every minute
}
return 0;
}