cmds: mkdir: restore SELinux security contexts only if the folder is newly created

Init scans pre-init existed folders and each new created folder. So don't
do duplicated jobs.

Issue: https://gitee.com/openharmony/startup_init/issues/I8QSAL
Signed-off-by: Changbin Du <changbin.du@huawei.com>
This commit is contained in:
Changbin Du 2023-12-23 15:55:59 +08:00
parent aea671b2b7
commit e8a1aad901

View File

@ -350,7 +350,13 @@ static void DoMkDir(const struct CmdArgs *ctx)
return;
}
PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]);
/*
* Skip restoring default SELinux security contexts if the the folder already
* existed and its under /dev. These files will be proceed by loadSelinuxPolicy.
*/
if (errno != EEXIST || strncmp(ctx->argv[0], "/dev", strlen("/dev")) != 0) {
PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]);
}
if (ctx->argc <= 1) {
return;