Compare commits

...

2 Commits

Author SHA1 Message Date
f850b75dfb
change dir name 2024-11-24 04:48:19 +03:00
5a7a9ad8bb
add new content 2024-11-24 04:47:28 +03:00
6 changed files with 183 additions and 40 deletions

52
libmysyslog-client/.gitignore vendored Normal file
View File

@ -0,0 +1,52 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

View File

@ -0,0 +1,17 @@
CC = gcc
CFLAGS = -Wall -Wextra -I../libmysyslog
LDFLAGS = -L../libmysyslog -lmysyslog
TARGET = libmysyslog-client
all: $(TARGET)
$(TARGET): libmysyslog-client.o
$(CC) -o $(TARGET) libmysyslog-client.o $(LDFLAGS)
libmysyslog.o: libmysyslog-client.c
$(cc) $(CFLAGS) -c libmysyslog-client.c
clean:
rm -f $(TARGET) *.o
.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,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;
}