diff --git a/tools/acrn-crashlog/acrnprobe/Makefile b/tools/acrn-crashlog/acrnprobe/Makefile index 24e6f5d12..5ba15accf 100644 --- a/tools/acrn-crashlog/acrnprobe/Makefile +++ b/tools/acrn-crashlog/acrnprobe/Makefile @@ -1,6 +1,7 @@ BASEDIR := $(shell pwd) LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry +INCLUDE += -I $(BASEDIR)/include CFLAGS += $(INCLUDE) CFLAGS += -g -O0 -std=gnu11 CFLAGS += -ffunction-sections -fdata-sections @@ -14,7 +15,17 @@ all: check_dirs $(TARGET) $(BUILDDIR)/acrnprobe/obj/%.o:%.c $(CC) -c $(CFLAGS) $< -o $@ -$(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o +$(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o \ + $(BUILDDIR)/common/obj/log_sys.o \ + $(BUILDDIR)/common/obj/cmdutils.o \ + $(BUILDDIR)/common/obj/fsutils.o \ + $(BUILDDIR)/common/obj/strutils.o \ + $(BUILDDIR)/acrnprobe/obj/load_conf.o \ + $(BUILDDIR)/acrnprobe/obj/channels.o \ + $(BUILDDIR)/acrnprobe/obj/event_queue.o \ + $(BUILDDIR)/acrnprobe/obj/event_handler.o \ + $(BUILDDIR)/acrnprobe/obj/crash_reclassify.o \ + $(BUILDDIR)/acrnprobe/obj/sender.o $(CC) -o $@ $^ $(LDFLAGS) clean: diff --git a/tools/acrn-crashlog/acrnprobe/channels.c b/tools/acrn-crashlog/acrnprobe/channels.c new file mode 100644 index 000000000..45d55e6b8 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/channels.c @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "channels.h" + +int init_channels(void) +{ + return 0; +} diff --git a/tools/acrn-crashlog/acrnprobe/crash_reclassify.c b/tools/acrn-crashlog/acrnprobe/crash_reclassify.c new file mode 100644 index 000000000..8b46dba09 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/crash_reclassify.c @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "crash_reclassify.h" + +void init_crash_reclassify(void) +{ +} diff --git a/tools/acrn-crashlog/acrnprobe/event_handler.c b/tools/acrn-crashlog/acrnprobe/event_handler.c new file mode 100644 index 000000000..2393a657f --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/event_handler.c @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "event_handler.h" + +int init_event_handler(void) +{ + return 0; +} diff --git a/tools/acrn-crashlog/acrnprobe/event_queue.c b/tools/acrn-crashlog/acrnprobe/event_queue.c new file mode 100644 index 000000000..51c097e2f --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/event_queue.c @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "event_queue.h" + +void init_event(void) +{ +} diff --git a/tools/acrn-crashlog/acrnprobe/include/channels.h b/tools/acrn-crashlog/acrnprobe/include/channels.h new file mode 100644 index 000000000..0c6ac84f7 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/channels.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _CHANNELS_H +#define _CHANNELS_H + +extern int init_channels(void); + +#endif diff --git a/tools/acrn-crashlog/acrnprobe/include/crash_reclassify.h b/tools/acrn-crashlog/acrnprobe/include/crash_reclassify.h new file mode 100644 index 000000000..c939077eb --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/crash_reclassify.h @@ -0,0 +1,6 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +extern void init_crash_reclassify(void); diff --git a/tools/acrn-crashlog/acrnprobe/include/event_handler.h b/tools/acrn-crashlog/acrnprobe/include/event_handler.h new file mode 100644 index 000000000..270bcb798 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/event_handler.h @@ -0,0 +1,6 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +extern int init_event_handler(void); diff --git a/tools/acrn-crashlog/acrnprobe/include/event_queue.h b/tools/acrn-crashlog/acrnprobe/include/event_queue.h new file mode 100644 index 000000000..b33831c3e --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/event_queue.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __EVENT_QUEUE_H__ +#define __EVENT_QUEUE_H__ + +void init_event_queue(void); + +#endif diff --git a/tools/acrn-crashlog/acrnprobe/include/load_conf.h b/tools/acrn-crashlog/acrnprobe/include/load_conf.h new file mode 100644 index 000000000..3bea6bffa --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/load_conf.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __LOAD_CONF_H__ +#define __LOAD_CONF_H__ + +#define SENDER_MAX 3 + +struct uptime_t { + char *name; + char *frequency; + char *eventhours; + + int wd; + char *path; +}; + +struct sender_t { + struct uptime_t *uptime; +}; + +struct conf_t { + struct sender_t *sender[SENDER_MAX]; +}; + +struct conf_t conf; + +#define for_each_sender(id, sender, conf) \ + for (id = 0, sender = conf.sender[0]; \ + id < SENDER_MAX; \ + id++, sender = conf.sender[id]) + +int load_conf(char *path); + +#endif diff --git a/tools/acrn-crashlog/acrnprobe/include/sender.h b/tools/acrn-crashlog/acrnprobe/include/sender.h new file mode 100644 index 000000000..531c415c0 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/include/sender.h @@ -0,0 +1,6 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +extern int init_sender(void); diff --git a/tools/acrn-crashlog/acrnprobe/load_conf.c b/tools/acrn-crashlog/acrnprobe/load_conf.c new file mode 100644 index 000000000..c84e8d18a --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/load_conf.c @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "load_conf.h" + +int load_conf(char *path __attribute__((unused))) +{ + return 0; +} diff --git a/tools/acrn-crashlog/acrnprobe/main.c b/tools/acrn-crashlog/acrnprobe/main.c index a3faee2c8..e9d1fdc3e 100644 --- a/tools/acrn-crashlog/acrnprobe/main.c +++ b/tools/acrn-crashlog/acrnprobe/main.c @@ -3,11 +3,121 @@ * SPDX-License-Identifier: BSD-3-Clause */ -int main(void) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "load_conf.h" +#include "fsutils.h" +#include "crash_reclassify.h" +#include "sender.h" +#include "event_queue.h" +#include "event_handler.h" +#include "channels.h" +#include "log_sys.h" + +#define CONFIG_INSTALL "/usr/share/defaults/telemetrics/acrnprobe.xml" +#define CONFIG_CUSTOMIZE "/etc/acrnprobe.xml" +#define VERSION "1.0" + +void usage(void) { - //TO BE DONE - //This empty function is to satisfy the dependency of Makefile. - //This is the entry of acrnprobe, the implementation will be filled - //by following patches. + printf("[Usage]\n"); + printf("\tacrnprobe -c [configuration file path] [-hV]\n"); + printf("[Options]\n"); + printf("\t-c, --config Configuration file\n"); + printf("\t-h, --help print the help message\n"); + printf("\t-V, --version Print the program version\n"); +} + +static void uptime(struct sender_t *sender) +{ + int fd; + int frequency; + struct uptime_t *uptime; + + uptime = sender->uptime; + frequency = atoi(uptime->frequency); + sleep(frequency); + fd = open(uptime->path, O_RDWR | O_CREAT, 0666); + if (fd < 0) + LOGE("open uptime_file with (%d, %s) failed, error (%s)\n", + atoi(uptime->frequency), uptime->path, + strerror(errno)); + else + close(fd); +} + +int main(int argc, char *argv[]) +{ + int ret; + int id; + int op; + struct sender_t *sender; + char cfg[PATH_MAX] = {0}; + char *config_path[2] = {CONFIG_CUSTOMIZE, + CONFIG_INSTALL}; + struct option opts[] = { + { "config", required_argument, NULL, 'c' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } + }; + + while ((op = getopt_long(argc, argv, "c:hV", opts, + NULL)) != -1) { + switch (op) { + case 'c': + strcpy(cfg, optarg); + break; + case 'h': + usage(); + return 0; + case 'V': + printf(VERSION "\n"); + return 0; + case '?': + usage(); + return -1; + } + } + + if (!cfg[0]) { + if (file_exists(config_path[0])) + strcpy(cfg, config_path[0]); + else + strcpy(cfg, config_path[1]); + } + + ret = load_conf(cfg); + if (ret) + return -1; + + init_crash_reclassify(); + ret = init_sender(); + if (ret) + return -1; + + init_event_queue(); + ret = init_event_handler(); + if (ret) + return -1; + + ret = init_channels(); + if (ret) + return -1; + + while (1) { + for_each_sender(id, sender, conf) { + if (!sender) + continue; + uptime(sender); + } + } return 0; } diff --git a/tools/acrn-crashlog/acrnprobe/sender.c b/tools/acrn-crashlog/acrnprobe/sender.c new file mode 100644 index 000000000..ad1cdcf2d --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/sender.c @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "sender.h" + +int init_sender(void) +{ + return 0; +}