tools: acrn-manager: fix the possibility of creating directory at will by no permission process

There are several duplicate definitions for check_dir, it can check or create directory at will. However, only acrnd and dm monitor can create the directory. This commit fixs the possibility of creating directory at will by no permission process, which adds a param flags to conctrl if it should create the directory. By the way, this commit collates related MACRO into the same file , deletes the duplicate definitions in another files and fixs some format issues.

Tracked-On: #2886
Signed-off-by: Mao Jiang <maox.jiang@intel.com>
Acked-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
Jiang,Mao
2019-04-16 12:16:04 +08:00
committed by ACRN System Integration
parent 16a2af5715
commit e50c0c88fb
7 changed files with 83 additions and 93 deletions

View File

@@ -225,28 +225,6 @@ int acrn_parse_intr_monitor(const char *opt)
return 0;
}
/* helpers */
/* Check if @path is a directory, and create if not exist */
static int check_dir(const char *path)
{
struct stat st;
if (stat(path, &st)) {
if (mkdir(path, 0666)) {
perror(path);
return -1;
}
return 0;
}
if (S_ISDIR(st.st_mode))
return 0;
fprintf(stderr, "%s exist, and not a directory!\n", path);
return -1;
}
struct vm_ops {
char name[16];
void *arg;
@@ -426,13 +404,13 @@ int monitor_init(struct vmctx *ctx)
int ret;
char path[128] = {};
ret = check_dir("/run/acrn/");
ret = check_dir(ACRN_DM_BASE_PATH, CHK_CREAT);
if (ret) {
fprintf(stderr, "%s %d\r\n", __FUNCTION__, __LINE__);
goto dir_err;
}
ret = check_dir("/run/acrn/mngr");
ret = check_dir(ACRN_DM_SOCK_PATH, CHK_CREAT);
if (ret) {
fprintf(stderr, "%s %d\r\n", __FUNCTION__, __LINE__);
goto dir_err;