add new content
This commit is contained in:
3 files changed
+62
-40
No files matched your search
+10
-11
@@ -1,18 +1,17 @@
|
|||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -g
|
CFLAGS = -Wall -Wextra -I../libmysyslog
|
||||||
LDFLAGS = -lm
|
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
|
libmysyslog.o: libmysyslog-client.c
|
||||||
$(CC) -o $@ $^ $(LIBS)
|
$(cc) $(CFLAGS) -c libmysyslog-client.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f src/*.o mysyslog-client
|
rm -f $(TARGET) *.o
|
||||||
|
|
||||||
deb:
|
.PHONY: all clean
|
||||||
# Deb package building logic
|
|
||||||
|
|
||||||
.PHONY: all clean deb
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user