diff --git a/tools/acrn-crashlog/Makefile b/tools/acrn-crashlog/Makefile new file mode 100644 index 000000000..9567a40fb --- /dev/null +++ b/tools/acrn-crashlog/Makefile @@ -0,0 +1,30 @@ +# +# ACRN-Crashlog Makefile +# + +BASEDIR := $(shell pwd) +OUT_DIR ?= $(BASEDIR) +BUILDDIR := $(OUT_DIR)/acrn-crashlog +CC := gcc +RM = rm + +CFLAGS := -Wall -Wextra -pedantic +CFLAGS += -m64 -D_GNU_SOURCE -DDEBUG_ACRN_CRASHLOG +INCLUDE := -I $(BASEDIR)/common/include +export INCLUDE +export BUILDDIR + +.PHONY:all +all: + $(MAKE) -C common + $(MAKE) -C acrnprobe + $(MAKE) -C usercrash + +.PHONY:clean +clean: + $(MAKE) -C common clean + $(MAKE) -C acrnprobe clean + $(MAKE) -C usercrash clean + @if [ -d "$(BUILDDIR)" ]; then \ + $(RM) -rf $(BUILDDIR); \ + fi diff --git a/tools/acrn-crashlog/acrnprobe/Makefile b/tools/acrn-crashlog/acrnprobe/Makefile new file mode 100644 index 000000000..24e6f5d12 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/Makefile @@ -0,0 +1,38 @@ +BASEDIR := $(shell pwd) + +LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry +CFLAGS += $(INCLUDE) +CFLAGS += -g -O0 -std=gnu11 +CFLAGS += -ffunction-sections -fdata-sections + +LDFLAGS += $(LIBS) -Wl,--gc-sections + +TARGET = $(BUILDDIR)/acrnprobe/bin/acrnprobe + +all: check_dirs $(TARGET) + +$(BUILDDIR)/acrnprobe/obj/%.o:%.c + $(CC) -c $(CFLAGS) $< -o $@ + +$(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o + $(CC) -o $@ $^ $(LDFLAGS) + +clean: + @echo "Clean objects and binaries" + @if [ -d $(BUILDDIR)/acrnprobe/obj ]; then \ + find $(BUILDDIR)/acrnprobe/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \ + fi + @if [ -d $(BUILDDIR)/acrnprobe/bin ]; then \ + $(RM) -r $(BUILDDIR)/acrnprobe/bin ; \ + fi + @if [ -d $(BUILDDIR)/acrnprobe/obj ]; then \ + $(RM) -r $(BUILDDIR)/acrnprobe/obj ; \ + fi + +check_dirs: + @if [ ! -d $(BUILDDIR)/acrnprobe/bin ]; then \ + mkdir -p $(BUILDDIR)/acrnprobe/bin ; \ + fi + @if [ ! -d $(BUILDDIR)/acrnprobe/obj ]; then \ + mkdir -p $(BUILDDIR)/acrnprobe/obj ; \ + fi diff --git a/tools/acrn-crashlog/acrnprobe/main.c b/tools/acrn-crashlog/acrnprobe/main.c new file mode 100644 index 000000000..a3faee2c8 --- /dev/null +++ b/tools/acrn-crashlog/acrnprobe/main.c @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2018 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +int main(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. + return 0; +} diff --git a/tools/acrn-crashlog/common/Makefile b/tools/acrn-crashlog/common/Makefile new file mode 100644 index 000000000..efa201786 --- /dev/null +++ b/tools/acrn-crashlog/common/Makefile @@ -0,0 +1,20 @@ +objects = log_sys.o + +all: check_obj $(objects) +check_obj: + @if [ ! -d $(BUILDDIR)/common/obj ]; then \ + mkdir -p $(BUILDDIR)/common/obj/; \ + fi + +$(objects):%.o:%.c + $(CC) -c $(CFLAGS) $(INCLUDE) $< -o $(BUILDDIR)/common/obj/$@ + +.PHONY:clean +clean: + @echo "Clean objects and binaries" + @if [ -d $(BUILDDIR)/common/obj ]; then \ + find $(BUILDDIR)/common/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \ + fi + @if [ -d $(BUILDDIR)/common/obj ]; then \ + $(RM) -r $(BUILDDIR)/common/obj ; \ + fi diff --git a/tools/acrn-crashlog/common/include/log_sys.h b/tools/acrn-crashlog/common/include/log_sys.h new file mode 100644 index 000000000..7fa4b8171 --- /dev/null +++ b/tools/acrn-crashlog/common/include/log_sys.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef __LOG_SYS_H__ +#define __LOG_SYS_H__ + +#include +#include + +void do_log(int level, +#ifdef DEBUG_ACRN_CRASHLOG + const char *func, int line, +#endif + ...); + +#define MAX_LOG_LEN 1024 +#define LOG_LEVEL LOG_WARNING + +#ifdef DEBUG_ACRN_CRASHLOG +#define LOGE(...) \ + do_log(LOG_ERR, __func__, __LINE__, __VA_ARGS__) + +#define LOGW(...) \ + do_log(LOG_WARNING, __func__, __LINE__, __VA_ARGS__) + +#define LOGI(...) \ + do_log(LOG_INFO, __func__, __LINE__, __VA_ARGS__) + +#define LOGD(...) \ + do_log(LOG_DEBUG, __func__, __LINE__, __VA_ARGS__) +#else +#define LOGE(...) \ + do_log(LOG_ERR, __VA_ARGS__) + +#define LOGW(...) \ + do_log(LOG_WARNING, __VA_ARGS__) + +#define LOGI(...) \ + do_log(LOG_INFO, __VA_ARGS__) + +#define LOGD(...) \ + do_log(LOG_DEBUG, __VA_ARGS__) +#endif + +#endif diff --git a/tools/acrn-crashlog/common/log_sys.c b/tools/acrn-crashlog/common/log_sys.c new file mode 100644 index 000000000..6dfa30170 --- /dev/null +++ b/tools/acrn-crashlog/common/log_sys.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "log_sys.h" + +void do_log(int level, +#ifdef DEBUG_ACRN_CRASHLOG + const char *func, int line, +#endif + ...) +{ + va_list args; + char *fmt; + char log[MAX_LOG_LEN] = {0}; +#ifdef DEBUG_ACRN_CRASHLOG + char header_fmt[] = "<%-20s%d>: "; +#endif + + if (level > LOG_LEVEL) + return; + +#ifdef DEBUG_ACRN_CRASHLOG + va_start(args, line); +#else + va_start(args, level); +#endif + fmt = va_arg(args, char *); + if (!fmt) + return; + +#ifdef DEBUG_ACRN_CRASHLOG + /* header */ + snprintf(log, sizeof(log) - 1, header_fmt, func, line); +#endif + /* msg */ + vsnprintf(log + strlen(log), sizeof(log) - strlen(log) - 1, fmt, args); + va_end(args); + + sd_journal_print(level, log); +} diff --git a/tools/acrn-crashlog/data/40-watchdog.conf b/tools/acrn-crashlog/data/40-watchdog.conf new file mode 100644 index 000000000..f8dabd7e2 --- /dev/null +++ b/tools/acrn-crashlog/data/40-watchdog.conf @@ -0,0 +1,2 @@ +[Manager] +RuntimeWatchdogSec=40 diff --git a/tools/acrn-crashlog/usercrash/Makefile b/tools/acrn-crashlog/usercrash/Makefile new file mode 100644 index 000000000..5975048c5 --- /dev/null +++ b/tools/acrn-crashlog/usercrash/Makefile @@ -0,0 +1,33 @@ +all: check_obj usercrash_s usercrash_c + +LIBS = -levent -lpthread + +usercrash_s: $(BUILDDIR)/usercrash/obj/server.o + $(CC) -g $(CFLAGS) $(LIBS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + +usercrash_c: $(BUILDDIR)/usercrash/obj/client.o + $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + +$(BUILDDIR)/usercrash/obj/%.o:%.c + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + +check_obj: + @if [ ! -d $(BUILDDIR)/usercrash/bin ]; then \ + mkdir -p $(BUILDDIR)/usercrash/bin ; \ + fi + @if [ ! -d $(BUILDDIR)/usercrash/obj ]; then \ + mkdir -p $(BUILDDIR)/usercrash/obj ; \ + fi + +.PHONY:clean +clean: + @echo "Clean objects and binaries" + @if [ -d $(BUILDDIR)/usercrash/obj ]; then \ + find $(BUILDDIR)/usercrash/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \ + fi + @if [ -d $(BUILDDIR)/usercrash/bin ]; then \ + $(RM) -r $(BUILDDIR)/usercrash/bin ; \ + fi + @if [ -d $(BUILDDIR)/usercrash/obj ]; then \ + $(RM) -r $(BUILDDIR)/usercrash/obj ; \ + fi diff --git a/tools/acrn-crashlog/usercrash/client.c b/tools/acrn-crashlog/usercrash/client.c new file mode 100644 index 000000000..7756dfda1 --- /dev/null +++ b/tools/acrn-crashlog/usercrash/client.c @@ -0,0 +1,22 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * Usercrash works as C/S model: usercrash_c works as usercrash client to + * collect crash logs and information once crash event occurs. For each time, + * usercrash_c receives 3 params from core_dump and sends connect request event + * to usercrash_s, then it receives file fd from server to fill crash info into + * the file. After this work is done, it will notify server that dump work is + * completed. + */ + +int main(void) +{ + //TO BE DONE + //This empty function is to satisfy the dependency of Makefile. + //This is the entry of usercrash_c, the implementation will be + //filled by following patches. + return 0; +} diff --git a/tools/acrn-crashlog/usercrash/server.c b/tools/acrn-crashlog/usercrash/server.c new file mode 100644 index 000000000..846878c69 --- /dev/null +++ b/tools/acrn-crashlog/usercrash/server.c @@ -0,0 +1,22 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * Usercrash works as C/S model: usercrash_s works as usercrash server, which + * is to handle events from client in endless loop. Once server receives events + * from client, it will create usercrash_0x file under /var/log/usercrashes/ + * and send file fd to client. Then server will wait for client filling the + * event info completely to the crash file. After client's work has been done, + * server will be responsiable to free the crash node and process other events. + */ + +int main(void) +{ + //TO BE DONE + //This empty function is to satisfy the dependency of Makefile. + //This is the entry of usercrash_s, the implementation will be filled + //by following patches. + return 0; +}