Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27164dce authored by Chia-chi Yeh's avatar Chia-chi Yeh
Browse files

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
parent e8967558
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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;
    }