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

@@ -18,25 +18,32 @@
#include "acrn_mngr.h"
/* helpers */
/* Check if @path is a directory, and create if not exist */
static int check_dir(const char *path)
/* Check if @path exists and if is a directory, if not existence, create or warn according to the flag */
int check_dir(const char *path, int flags)
{
struct stat st;
struct stat st;
if (stat(path, &st)) {
if (mkdir(path, 0666)) {
perror(path);
return -1;
}
return 0;
}
if (stat(path, &st)) {
if (flags) {
if (mkdir(path, 0666)) {
perror(path);
return -1;
}
return 0;
} else {
printf("%s doesn't exist!\n", path);
return -1;
}
}
if (S_ISDIR(st.st_mode))
return 0;
if (S_ISDIR(st.st_mode))
return 0;
return -1;
fprintf(stderr, "%s exist, and not a directory!\n", path);
return -1;
}
#define MNGR_SOCK_FMT "/run/acrn/mngr/%s.%d.socket"
#define MNGR_MAX_HANDLER 8
#define MNGR_MAX_CLIENT 4
@@ -489,8 +496,8 @@ static void close_client(struct mngr_fd *mfd)
int mngr_open_un(const char *name, int flags)
{
check_dir("/run/acrn");
check_dir("/run/acrn/mngr");
check_dir(ACRN_DM_BASE_PATH, CHK_ONLY);
check_dir(ACRN_DM_SOCK_PATH, CHK_ONLY);
if (!name) {
printf("%s: No socket name configured\n", __func__);