mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 12:42:54 +00:00
tools: acrn-crashlog: system properties for acrnprobe
Acrnprobe needs to know some HW/SW properties, such as board version, build version. These properties APIs are provided in this file. Signed-off-by: Liu Xinwu <xinwu.liu@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:
parent
f1a557aeaa
commit
50e62d900f
@ -26,7 +26,8 @@ $(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/event_handler.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/crash_reclassify.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/sender.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/startupreason.o
|
||||
$(BUILDDIR)/acrnprobe/obj/startupreason.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/property.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
|
34
tools/acrn-crashlog/acrnprobe/include/property.h
Normal file
34
tools/acrn-crashlog/acrnprobe/include/property.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __PROPERTY_H__
|
||||
#define __PROPERTY_H__
|
||||
#include "load_conf.h"
|
||||
|
||||
#define VERSION_SIZE 256
|
||||
|
||||
char guuid[VERSION_SIZE];
|
||||
char gbuildversion[VERSION_SIZE];
|
||||
|
||||
int init_properties(struct sender_t *sender);
|
||||
int swupdated(struct sender_t *sender);
|
||||
|
||||
#endif
|
128
tools/acrn-crashlog/acrnprobe/property.c
Normal file
128
tools/acrn-crashlog/acrnprobe/property.c
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "property.h"
|
||||
#include "log_sys.h"
|
||||
#include "fsutils.h"
|
||||
|
||||
#define MACHINE_ID "/etc/machine-id"
|
||||
#define OS_VERSION "/usr/lib/os-release"
|
||||
#define OS_VERSION_KEY "VERSION_ID="
|
||||
#define DEVICE_ID_UNKNOWN "UnknownId"
|
||||
#define LOG_UUID "uuid.txt"
|
||||
#define LOG_BUILDID "buildid.txt"
|
||||
|
||||
static void get_device_id(struct sender_t *sender)
|
||||
{
|
||||
int ret;
|
||||
char *loguuid;
|
||||
|
||||
|
||||
ret = asprintf(&loguuid, "%s/%s", sender->outdir, LOG_UUID);
|
||||
if (ret < 0) {
|
||||
LOGE("compute string failed, out of memory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = file_read_string(MACHINE_ID, guuid, VERSION_SIZE);
|
||||
if (ret <= 0)
|
||||
LOGE("Could not get mmc id: %d (%s)\n",
|
||||
ret, strerror(-ret));
|
||||
else
|
||||
goto write;
|
||||
|
||||
LOGE("Could not find DeviceId, set it to '%s'\n",
|
||||
DEVICE_ID_UNKNOWN);
|
||||
strncpy(guuid, DEVICE_ID_UNKNOWN, strlen(DEVICE_ID_UNKNOWN));
|
||||
|
||||
write:
|
||||
overwrite_file(loguuid, guuid);
|
||||
free(loguuid);
|
||||
}
|
||||
|
||||
static int get_buildversion(struct sender_t *sender)
|
||||
{
|
||||
int ret;
|
||||
char lastbuild[VERSION_SIZE];
|
||||
char *logbuildid;
|
||||
char *currentbuild = gbuildversion;
|
||||
|
||||
ret = file_read_key_value(OS_VERSION, OS_VERSION_KEY, gbuildversion);
|
||||
if (ret <= 0) {
|
||||
LOGE("failed to get version from %s, error (%s)\n",
|
||||
OS_VERSION, strerror(-ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = asprintf(&logbuildid, "%s/%s", sender->outdir, LOG_BUILDID);
|
||||
if (ret < 0) {
|
||||
LOGE("compute string failed, out of memory\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = file_read_string(logbuildid, lastbuild, VERSION_SIZE);
|
||||
if (ret == -ENOENT ||
|
||||
(ret > 0 && strcmp(currentbuild, lastbuild))) {
|
||||
/* build changed or file not found, overwrite it */
|
||||
ret = overwrite_file(logbuildid, gbuildversion);
|
||||
if (ret) {
|
||||
LOGE("create (%s) failed, error (%s)\n", logbuildid,
|
||||
strerror(-ret));
|
||||
goto free;
|
||||
}
|
||||
|
||||
sender->sw_updated = 1;
|
||||
ret = 0;
|
||||
} else if (ret <= 0) {
|
||||
LOGE("Cannot read %s, error (%s)\n",
|
||||
logbuildid, strerror(errno));
|
||||
} else {
|
||||
/* buildid is the same */
|
||||
sender->sw_updated = 0;
|
||||
ret = 0;
|
||||
}
|
||||
free:
|
||||
free(logbuildid);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int swupdated(struct sender_t *sender)
|
||||
{
|
||||
return sender->sw_updated;
|
||||
}
|
||||
|
||||
int init_properties(struct sender_t *sender)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = get_buildversion(sender);
|
||||
if (ret) {
|
||||
LOGE("init properties failed\n");
|
||||
return ret;
|
||||
}
|
||||
get_device_id(sender);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user