capture acrnd AaaG booting messages to journald

It's for AaaG boot time measurement only.

Tracked-On: #1759
Signed-off-by: Yan, Like <like.yan@intel.com>
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
This commit is contained in:
Yan, Like 2018-10-26 23:57:00 +08:00 committed by lijinxia
parent c4161c8784
commit d49a6f6fca
2 changed files with 24 additions and 13 deletions

View File

@ -215,20 +215,16 @@ static int load_timer_list(void)
return ret; return ret;
} }
#define ACRND_LOG_FMT "/opt/acrn/%s.log" static int logfile = 1;
static void acrnd_run_vm(char *name) static void acrnd_run_vm(char *name)
{ {
char log_path[128] = {}; /*If do not use logfile, then output to stdout,
so that it can be redirected to journal by systemd */
if (snprintf(log_path, sizeof(log_path) -1, ACRND_LOG_FMT, name) if (logfile) {
>= sizeof(log_path) -1) { stdin = freopen("/dev/null", "r+", stdin);
printf("WARN: log path is truncated\n"); stdout = freopen("/dev/null", "r+", stdout);
} else { stderr = freopen("/dev/null", "r+", stderr);
unlink(log_path);
stdin = freopen(log_path, "w+", stdin);
stdout = freopen(log_path, "w+", stdout);
stderr = freopen(log_path, "w+", stderr);
fflush(stdin); fflush(stdin);
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
@ -653,8 +649,22 @@ static void sigterm_handler(int signo)
sigterm = 1; sigterm = 1;
} }
static const char optString[] = "t";
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt;
while ((opt = getopt(argc, argv, optString)) != -1) {
switch (opt) {
case 't':
logfile = 0;
break;
default:
printf("Ingrone unknown opt: %c\n", opt);
}
}
/* create listening thread */ /* create listening thread */
acrnd_fd = mngr_open_un(ACRND_NAME, MNGR_SERVER); acrnd_fd = mngr_open_un(ACRND_NAME, MNGR_SERVER);
if (acrnd_fd < 0) { if (acrnd_fd < 0) {

View File

@ -7,8 +7,9 @@ ConditionPathExists=/dev/acrn_vhm
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/bin/acrnd ExecStart=/usr/bin/acrnd -t
StandardOutput=journal
StandardError=journal
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target