tools: acrn-crashlog: framework of acrn-crashlog

This is the first patch of acrn-crashlog.

This patch initializes the framework of acrn-crashlog: acrnprobe,
common, data, and usercrash. And it initializes the Makefile for
each part.

Signed-off-by: Liu Xinwu <xinwu.liu@intel.com>
Signed-off-by: CHEN Gang <gang.c.chen@intel.com>
Reviewed-by: Zhang Yanmin <yanmin.zhang@intel.com>
Reviewed-by: Liu Chuansheng <chuansheng.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Acked-by: Eddie Dong <Eddie.dong@intel.com>
This commit is contained in:
Liu Xinwu 2018-04-25 10:19:46 +08:00 committed by lijinxia
parent 7c9cc6bcd4
commit 6f9dfa49bf
10 changed files with 272 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __LOG_SYS_H__
#define __LOG_SYS_H__
#include <stdarg.h>
#include <syslog.h>
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

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <string.h>
#include <systemd/sd-journal.h>
#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);
}

View File

@ -0,0 +1,2 @@
[Manager]
RuntimeWatchdogSec=40

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}