mkdir in init.rc

2019-08-12 16:50发布

问题:

Init.rc

Line No-264---mkdir /data/misc/radio 0770 radio radio

I want to change permission of /data/misc/radio to 0775.

I have written this next to above line: Line No-265---chmod 0775 /data/misc/radio.

If I change line 264 to this ---mkdir /data/misc/radio 0775 radio radio..

what is problem with this line? Someone says that if mkdir fails(In case directory exis already) then permission will not be set to 0775. So to make sure that permission changes to 0775 if mkdir fails we have written chmod command in different line.

But there are so many mkdir commands which is making different directories with different permissions,so then if we go by above scenario then we should provide different chmod command in correspond to each mkdir command?

回答1:

When init executes the the init.rc script the mkdir will make the directory if it is not present with the permissions you provide, if the directory does exist then the permissions are set according to the mkdir command.

from aosp system/core/init/builtins.c in the function do_mkdir()

ret = make_dir(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;
}