init: make "mkdir" work even when the directory already exists.

This allows us to change permissions and ownerships of directories
in init scripts without adding additional commands.

Change-Id: I1815d6015953035251b98f28c0f3efd3c7f25f80
This commit is contained in:
Chia-chi Yeh 2011-07-08 12:57:36 -07:00
parent e89675584d
commit 27164dce5f
1 changed files with 7 additions and 1 deletions

View File

@ -229,6 +229,7 @@ int do_insmod(int nargs, char **args)
int do_mkdir(int nargs, char **args)
{
mode_t mode = 0755;
int ret;
/* mkdir <path> [mode] [owner] [group] */
@ -236,7 +237,12 @@ int do_mkdir(int nargs, char **args)
mode = strtoul(args[2], 0, 8);
}
if (mkdir(args[1], mode)) {
ret = mkdir(args[1], mode);
/* chmod in case the directory already exists */
if (ret == -1 && errno == EEXIST) {
ret = chmod(args[1], mode);
}
if (ret == -1) {
return -errno;
}