From a9e36bdb4ed6fc4af397b933a7e22f59b7b3dfa4 Mon Sep 17 00:00:00 2001 From: CHEN Gang Date: Fri, 18 May 2018 16:38:19 +0800 Subject: [PATCH] tools: acrn-crashlog: add service/config files and scripts This patch adds the service files, config files and script to run automatically at boot. And it adds install/uninstall part in Makefile. Compatiblity code for libsystemd.so and libsystemd-journal.so is added in Makefile also. Signed-off-by: Jin Zhi Signed-off-by: CHEN Gang Reviewed-by: Zhang Yanmin Reviewed-by: Liu Chuansheng Reviewed-by: Zhao Yakui Reviewed-by: Geoffroy Van Cutsem Acked-by: Eddie Dong --- Makefile | 5 +- tools/acrn-crashlog/Makefile | 67 ++++++++++++++++++- tools/acrn-crashlog/acrnprobe/Makefile | 2 +- tools/acrn-crashlog/data/acrnprobe.service | 14 ++++ tools/acrn-crashlog/data/acrnprobe_prepare.sh | 42 ++++++++++++ tools/acrn-crashlog/data/prepare.service | 12 ++++ tools/acrn-crashlog/data/usercrash.service | 13 ++++ tools/acrn-crashlog/usercrash/Makefile | 8 +-- 8 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 tools/acrn-crashlog/data/acrnprobe.service create mode 100755 tools/acrn-crashlog/data/acrnprobe_prepare.sh create mode 100644 tools/acrn-crashlog/data/prepare.service create mode 100644 tools/acrn-crashlog/data/usercrash.service diff --git a/Makefile b/Makefile index 5d2a97f7b..9a7f352cc 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,12 @@ tools: make -C $(T)/tools/acrnlog OUT_DIR=$(TOOLS_OUT) make -C $(T)/tools/acrn-manager OUT_DIR=$(TOOLS_OUT) make -C $(T)/tools/acrntrace OUT_DIR=$(TOOLS_OUT) + make -C $(T)/tools/acrn-crashlog OUT_DIR=$(TOOLS_OUT) RELEASE=$(RELEASE) .PHONY: clean clean: rm -rf $(ROOT_OUT) - + .PHONY: install install: hypervisor-install devicemodel-install tools-install @@ -44,4 +45,4 @@ tools-install: make -C $(T)/tools/acrnlog OUT_DIR=$(TOOLS_OUT) install make -C $(T)/tools/acrn-manager OUT_DIR=$(TOOLS_OUT) install make -C $(T)/tools/acrntrace OUT_DIR=$(TOOLS_OUT) install - + make -C $(T)/tools/acrn-crashlog OUT_DIR=$(TOOLS_OUT) install diff --git a/tools/acrn-crashlog/Makefile b/tools/acrn-crashlog/Makefile index 9567a40fb..a1572dd15 100644 --- a/tools/acrn-crashlog/Makefile +++ b/tools/acrn-crashlog/Makefile @@ -7,12 +7,27 @@ OUT_DIR ?= $(BASEDIR) BUILDDIR := $(OUT_DIR)/acrn-crashlog CC := gcc RM = rm +RELEASE ?= 0 CFLAGS := -Wall -Wextra -pedantic -CFLAGS += -m64 -D_GNU_SOURCE -DDEBUG_ACRN_CRASHLOG +CFLAGS += -m64 -D_GNU_SOURCE +ifeq ($(RELEASE),0) +CFLAGS += -DDEBUG_ACRN_CRASHLOG +endif INCLUDE := -I $(BASEDIR)/common/include export INCLUDE export BUILDDIR +export CC +export RM +export CFLAGS + +SYSTEMD_LIBS = -lsystemd +LDCNF := $(shell ldconfig -p) +LIB_EXIST = $(findstring libsystemd-journal.so, $(LDCNF)) +ifeq ($(strip $(LIB_EXIST)),libsystemd-journal.so) + SYSTEMD_LIBS = -lsystemd-journal +endif +export SYSTEMD_LIBS .PHONY:all all: @@ -28,3 +43,53 @@ clean: @if [ -d "$(BUILDDIR)" ]; then \ $(RM) -rf $(BUILDDIR); \ fi + +.PHONY:install +install: + @install -d $(DESTDIR)/usr/bin/ + @install -p -D -m 0755 $(BUILDDIR)/acrnprobe/bin/acrnprobe $(DESTDIR)/usr/bin/ + @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/debugger $(DESTDIR)/usr/bin/ + @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_c $(DESTDIR)/usr/bin/ + @install -p -D -m 0755 $(BUILDDIR)/usercrash/bin/usercrash_s $(DESTDIR)/usr/bin/ + @install -p -D -m 0755 data/acrnprobe_prepare.sh $(DESTDIR)/usr/bin/ + @install -d $(DESTDIR)/usr/lib/systemd/system.conf.d/ + @install -p -D -m 0644 data/40-watchdog.conf $(DESTDIR)/usr/lib/systemd/system.conf.d/ + @install -d $(DESTDIR)/usr/share/defaults/telemetrics/ + @install -p -D -m 0644 data/acrnprobe.xml $(DESTDIR)/usr/share/defaults/telemetrics/ + @install -d $(DESTDIR)/usr/lib/systemd/system/ + @install -p -D -m 0644 data/acrnprobe.service $(DESTDIR)/usr/lib/systemd/system/ + @install -p -D -m 0644 data/prepare.service $(DESTDIR)/usr/lib/systemd/system/ + @install -p -D -m 0644 data/usercrash.service $(DESTDIR)/usr/lib/systemd/system/ + +.PHONY:uninstall +uninstall: + @if [ -e "$(DESTDIR)/usr/bin/acrnprobe" ];then \ + $(RM) $(DESTDIR)/usr/bin/acrnprobe; \ + fi + @if [ -e "$(DESTDIR)/usr/bin/acrnprobe_prepare.sh" ];then \ + $(RM) $(DESTDIR)/usr/bin/acrnprobe_prepare.sh; \ + fi + @if [ -e "$(DESTDIR)/usr/bin/debugger" ];then \ + $(RM) $(DESTDIR)/usr/bin/debugger; \ + fi + @if [ -e "$(DESTDIR)/usr/bin/usercrash_c" ];then \ + $(RM) $(DESTDIR)/usr/bin/usercrash_c; \ + fi + @if [ -e "$(DESTDIR)/usr/bin/usercrash_s" ];then \ + $(RM) $(DESTDIR)/usr/bin/usercrash_s; \ + fi + @if [ -e "$(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf" ];then \ + $(RM) $(DESTDIR)/usr/lib/systemd/system.conf.d/40-watchdog.conf; \ + fi + @if [ -e "$(DESTDIR)/usr/share/defaults/telemetrics/acrnprobe.xml" ];then \ + $(RM) $(DESTDIR)/usr/share/defaults/telemetrics/acrnprobe.xml; \ + fi + @if [ -e "$(DESTDIR)/usr/lib/systemd/system/acrnprobe.service" ];then \ + $(RM) $(DESTDIR)/usr/lib/systemd/system/acrnprobe.service; \ + fi + @if [ -e "$(DESTDIR)/usr/lib/systemd/system/prepare.service" ];then \ + $(RM) $(DESTDIR)/usr/lib/systemd/system/prepare.service; \ + fi + @if [ -e "$(DESTDIR)/usr/lib/systemd/system/usercrash.service" ];then \ + $(RM) $(DESTDIR)/usr/lib/systemd/system/usercrash.service; \ + fi diff --git a/tools/acrn-crashlog/acrnprobe/Makefile b/tools/acrn-crashlog/acrnprobe/Makefile index 0952e5b94..b7eb4cda1 100644 --- a/tools/acrn-crashlog/acrnprobe/Makefile +++ b/tools/acrn-crashlog/acrnprobe/Makefile @@ -3,7 +3,7 @@ MINOR_VERSION=0 BASEDIR := $(shell pwd) -LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry +LIBS = -lpthread -lxml2 -lcrypto -lrt $(SYSTEMD_LIBS) -ltelemetry INCLUDE += -I $(BASEDIR)/include -I /usr/include/libxml2 CFLAGS += $(INCLUDE) CFLAGS += -g -O0 -std=gnu11 diff --git a/tools/acrn-crashlog/data/acrnprobe.service b/tools/acrn-crashlog/data/acrnprobe.service new file mode 100644 index 000000000..611d3b410 --- /dev/null +++ b/tools/acrn-crashlog/data/acrnprobe.service @@ -0,0 +1,14 @@ +[Unit] +Description=ACRN crashlog probe +Requires=telemd.socket +Requires=usercrash_s +After=usercrash.service +After=prepare.service + +[Service] +Type=simple +ExecStart=/usr/bin/acrnprobe +ExecStop=/usr/bin/killall -s TERM acrnprobe + +[Install] +WantedBy=multi-user.target diff --git a/tools/acrn-crashlog/data/acrnprobe_prepare.sh b/tools/acrn-crashlog/data/acrnprobe_prepare.sh new file mode 100755 index 000000000..718b78730 --- /dev/null +++ b/tools/acrn-crashlog/data/acrnprobe_prepare.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Copyright (C) <2018> Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# + +# modify the core_pattern +echo "|/usr/bin/usercrash_c %p %e %s" > /proc/sys/kernel/core_pattern + +conf="/usr/share/defaults/telemetrics/telemetrics.conf" + +grep -q "record_server_delivery_enabled=false" $conf +if [ "$?" -eq "0" ];then + exit; +fi + +telemd_services=( +hprobe.timer +telemd-update-trigger.service +pstore-clean.service +pstore-probe.service +oops-probe.service +klogscanner.service +journal-probe.service +bert-probe.service +) + +for ((i=0;i<${#telemd_services[*]};i++)) +do + if [ ! -L "/etc/systemd/system/${telemd_services[$i]}" ];then + systemctl mask ${telemd_services[$i]} --now + fi +done + +# modify the configure file + +sed -i "s/server_delivery_enabled=true/server_delivery_enabled=false/g" $conf +sed -i "s/record_retention_enabled=false/record_retention_enabled=true/g" $conf + +# restart telemd +sleep 3 +systemctl restart telemd.service diff --git a/tools/acrn-crashlog/data/prepare.service b/tools/acrn-crashlog/data/prepare.service new file mode 100644 index 000000000..430ba35e5 --- /dev/null +++ b/tools/acrn-crashlog/data/prepare.service @@ -0,0 +1,12 @@ +[Unit] +Description=ACRN probe prepare +Requires=telemd.service +After=telemd.service +Before=acrnprobe.service + +[Service] +Type=oneshot +ExecStart=/bin/sh /usr/bin/acrnprobe_prepare.sh + +[Install] +WantedBy=multi-user.target diff --git a/tools/acrn-crashlog/data/usercrash.service b/tools/acrn-crashlog/data/usercrash.service new file mode 100644 index 000000000..a3c4268fd --- /dev/null +++ b/tools/acrn-crashlog/data/usercrash.service @@ -0,0 +1,13 @@ +[Unit] +Description=ACRN usercrash Demon +Requires=telemd.socket +After=telemd.service +Before=acrnprobe.service + +[Service] +Type=simple +ExecStart=/usr/bin/usercrash_s +ExecStop=/usr/bin/killall -s TERM usercrash_s + +[Install] +WantedBy=multi-user.target diff --git a/tools/acrn-crashlog/usercrash/Makefile b/tools/acrn-crashlog/usercrash/Makefile index baaac212c..9542dfae0 100644 --- a/tools/acrn-crashlog/usercrash/Makefile +++ b/tools/acrn-crashlog/usercrash/Makefile @@ -6,12 +6,12 @@ all: include/version.h check_obj usercrash_s usercrash_c debugger CURRDIR := $(shell pwd) INCLUDE += -I $(CURRDIR)/include/ -LIBS = -levent -lpthread +LIBS = -levent -lpthread $(SYSTEMD_LIBS) usercrash_s: $(BUILDDIR)/usercrash/obj/protocol.o \ $(BUILDDIR)/usercrash/obj/server.o \ $(BUILDDIR)/common/obj/log_sys.o - $(CC) -g $(CFLAGS) $(LIBS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS) usercrash_c: $(BUILDDIR)/usercrash/obj/protocol.o \ $(BUILDDIR)/usercrash/obj/client.o \ @@ -20,7 +20,7 @@ usercrash_c: $(BUILDDIR)/usercrash/obj/protocol.o \ $(BUILDDIR)/common/obj/cmdutils.o \ $(BUILDDIR)/common/obj/fsutils.o \ $(BUILDDIR)/common/obj/strutils.o - $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS) debugger: $(BUILDDIR)/usercrash/obj/debugger.o \ $(BUILDDIR)/usercrash/obj/crash_dump.o \ @@ -28,7 +28,7 @@ debugger: $(BUILDDIR)/usercrash/obj/debugger.o \ $(BUILDDIR)/common/obj/cmdutils.o \ $(BUILDDIR)/common/obj/fsutils.o \ $(BUILDDIR)/common/obj/strutils.o - $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ -lsystemd + $(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS) $(BUILDDIR)/usercrash/obj/%.o:%.c $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<