mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-09 02:24:45 +00:00
tools: acrn-crashlog: main thread of acrn-crashlog/acrnprobe
This patch implements the main thread of acrnprobe. As a log collection mechanism to record critical events on the platform, acrnprobe provides the following features: 1. detect event. 2. analyze event and determine the event type. 3. collect information for the detected events. 4. archive these information as logs, and generate records. 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:
@@ -3,11 +3,121 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user