From 27164dce5f0788476449057c978fa24e62245cb8 Mon Sep 17 00:00:00 2001 From: Chia-chi Yeh Date: Fri, 8 Jul 2011 12:57:36 -0700 Subject: [PATCH] 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 --- init/builtins.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init/builtins.c b/init/builtins.c index bfdd65402..06ef96d6e 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -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 [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; }