mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-06 12:06:25 +00:00
tools: acrntrace: Remove use of binary "mkdir"
The tools currently rely on the availability of binary "mkdir" to be available in the $PATH on the Service OS. This creates an obscure dependency. The patch changes the code to use standard C APIs to perform the same functionality which makes the code more self-contained. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
parent
e699462161
commit
636515aac2
@ -10,6 +10,8 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -166,11 +168,12 @@ static int get_cpu_num(void)
|
|||||||
|
|
||||||
static int create_trace_file_dir(char *dir)
|
static int create_trace_file_dir(char *dir)
|
||||||
{
|
{
|
||||||
int status;
|
int err;
|
||||||
char cmd[CMD_MAX_LEN];
|
char cmd[CMD_MAX_LEN];
|
||||||
char time_str[TIME_STR_LEN];
|
char time_str[TIME_STR_LEN];
|
||||||
time_t timep;
|
time_t timep;
|
||||||
struct tm *p;
|
struct tm *p;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
time(&timep);
|
time(&timep);
|
||||||
p = localtime(&timep);
|
p = localtime(&timep);
|
||||||
@ -183,18 +186,29 @@ static int create_trace_file_dir(char *dir)
|
|||||||
|
|
||||||
pr_info("start tracing at %s\n", time_str);
|
pr_info("start tracing at %s\n", time_str);
|
||||||
|
|
||||||
|
/* Pre-condition: Make sure tmpfs is mounted on /tmp */
|
||||||
|
if (stat(TRACE_FILE_ROOT, &st)) {
|
||||||
|
err = mkdir(TRACE_FILE_ROOT, 0644);
|
||||||
|
if (err) {
|
||||||
|
pr_err("Fail to create dir %s, Error: %s\n",
|
||||||
|
TRACE_FILE_ROOT, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(dir, TRACE_FILE_DIR_LEN, "%s%s", TRACE_FILE_ROOT, time_str);
|
snprintf(dir, TRACE_FILE_DIR_LEN, "%s%s", TRACE_FILE_ROOT, time_str);
|
||||||
|
if (stat(dir, &st)) {
|
||||||
memset(cmd, 0, CMD_MAX_LEN);
|
err = mkdir(dir, 0644);
|
||||||
snprintf(cmd, CMD_MAX_LEN, "%s %s", "mkdir -p ", dir);
|
if (err) {
|
||||||
|
pr_err("Fail to create dir %s, Error: %s\n",
|
||||||
status = system(cmd);
|
dir, strerror(errno));
|
||||||
if (-1 == status)
|
return -1;
|
||||||
return -1; /* failed to execute sh */
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pr_dbg("dir %s creted\n", dir);
|
pr_dbg("dir %s creted\n", dir);
|
||||||
|
|
||||||
return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
|
return WIFEXITED(err) ? WEXITSTATUS(err) : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function executed in each consumer thread */
|
/* function executed in each consumer thread */
|
||||||
|
Loading…
Reference in New Issue
Block a user