diff --git a/src/container.c b/src/container.c index 02e6283..269b3bc 100644 --- a/src/container.c +++ b/src/container.c @@ -144,6 +144,7 @@ static int container_setup_volume(struct hyper_container *container) } } } else { + hyper_filize(mountpoint); if (hyper_create_file(mountpoint) < 0) { perror("create volume file failed"); return -1; diff --git a/src/util.c b/src/util.c index 2308c68..2256fd8 100644 --- a/src/util.c +++ b/src/util.c @@ -208,6 +208,21 @@ int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroup return ret; } +/* Trim all trailing '/' of a hyper_path except for the prefix one. */ +void hyper_filize(char *hyper_path) +{ + char *p; + + if (strlen(hyper_path) == 0) + return; + + p = &hyper_path[strlen(hyper_path) - 1]; + + for (; *p == '/' && p != hyper_path; p--) { + *p = '\0'; + } +} + static int hyper_create_parent_dir(const char *hyper_path) { char *p, *path = strdup(hyper_path); @@ -225,6 +240,7 @@ static int hyper_create_parent_dir(const char *hyper_path) return ret; } +/* hyper_path must point to a file rather than a directory, e.g., having trailing '/' */ int hyper_create_file(const char *hyper_path) { int fd; diff --git a/src/util.h b/src/util.h index 7a1eeb1..18ab657 100644 --- a/src/util.h +++ b/src/util.h @@ -26,6 +26,7 @@ void online_cpu(void); void online_memory(void); int hyper_cmd(char *cmd); int hyper_create_file(const char *hyper_path); +void hyper_filize(char *hyper_path); int hyper_mkdir(char *path, mode_t mode); int hyper_open_channel(char *channel, int mode); int hyper_open_serial_dev(char *tty);