add new content

This commit is contained in:
gandc 2024-11-24 04:47:28 +03:00
parent 7fc9618d17
commit 5a7a9ad8bb
Signed by: gandc
GPG Key ID: 9F77B03D43C42CB4
3 changed files with 62 additions and 40 deletions

View File

@ -1,18 +1,17 @@
CC = gcc
CFLAGS = -Wall -g
LDFLAGS = -lm
CFLAGS = -Wall -Wextra -I../libmysyslog
LDFLAGS = -L../libmysyslog -lmysyslog
TARGET = libmysyslog-client
LIBS = -lmysyslog -lmysyslog-text -lmysyslog-json
all: $(TARGET)
all: mysyslog-client
$(TARGET): libmysyslog-client.o
$(CC) -o $(TARGET) libmysyslog-client.o $(LDFLAGS)
mysyslog-client: src/mysyslog-client.o
$(CC) -o $@ $^ $(LIBS)
libmysyslog.o: libmysyslog-client.c
$(cc) $(CFLAGS) -c libmysyslog-client.c
clean:
rm -f src/*.o mysyslog-client
rm -f $(TARGET) *.o
deb:
# Deb package building logic
.PHONY: all clean deb
.PHONY: all clean

View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "libmysyslog.h"
void print_usage(const char* prog_name) {
printf("Usage: %s -m <message> -l <log_level> -d <driver> -f <format> -p <path>\n", prog_name);
}
int main(int argc, char* argv[]) {
int opt;
char* message = NULL;
int level = INFO;
int driver = TEXT_DRIVER;
int format = 0;
char* path = NULL;
while ((opt = getopt(argc, argv, "m:l:d:f:p:")) != -1) {
switch (opt) {
case 'm':
message = optarg;
break;
case 'l':
level = atoi(optarg);
break;
case 'd':
driver = atoi(optarg);
break;
case 'f':
format = atoi(optarg);
break;
case 'p':
path = optarg;
break;
default:
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
}
if (!message || !path) {
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
if (mysyslog(message, level, driver, format, path) != 0) {
fprintf(stderr, "Failed to log message\n");
exit(EXIT_FAILURE);
}
return 0;
}

View File

@ -1,29 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "mysyslog.h"
int main(int argc, char *argv[]) {
int level = INFO;
int driver = 1; // Default to text driver
int format = 1; // Default to text format
const char* msg = NULL;
const char* path = "/var/log/mysyslog.log";
int opt;
while ((opt = getopt(argc, argv, "m:l:d:f:p:")) != -1) {
switch (opt) {
case 'm': msg = optarg; break;
case 'l': level = atoi(optarg); break;
case 'd': driver = atoi(optarg); break;
case 'f': format = atoi(optarg); break;
case 'p': path = optarg; break;
}
}
if (msg != NULL) {
mysyslog(msg, level, driver, format, path);
}
return 0;
}