tools: acrn-manager: refine the usage of api 'snprintf'

Return value check for snprintf function

Tracked-On: #1254
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Yan, Like <like.yan@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Kaige Fu <kaige.fu@intel.com>
This commit is contained in:
Tianhua Sun
2018-10-26 18:10:35 +08:00
committed by lijinxia
parent 5493804cab
commit af760f8dce
4 changed files with 113 additions and 41 deletions

View File

@@ -219,14 +219,18 @@ static void acrnd_run_vm(char *name)
{
char log_path[128] = {};
snprintf(log_path, sizeof(log_path) -1, ACRND_LOG_FMT, name);
unlink(log_path);
stdin = freopen(log_path, "w+", stdin);
stdout = freopen(log_path, "w+", stdout);
stderr = freopen(log_path, "w+", stderr);
fflush(stdin);
fflush(stdout);
fflush(stderr);
if (snprintf(log_path, sizeof(log_path) -1, ACRND_LOG_FMT, name)
>= sizeof(log_path) -1) {
printf("WARN: log path is truncated\n");
} else {
unlink(log_path);
stdin = freopen(log_path, "w+", stdin);
stdout = freopen(log_path, "w+", stdout);
stderr = freopen(log_path, "w+", stderr);
fflush(stdin);
fflush(stdout);
fflush(stderr);
}
start_vm(name);
printf("%s exited!\n", name);