提交 c9fc6475 编写于 作者: R renwei

fix bug for dev restorecon

Signed-off-by: Nrenwei <renwei8@huawei.com>
Change-Id: I122eea706d4e295792fbfb3246367df87f47828f
上级 fc73b989
...@@ -82,18 +82,41 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid ...@@ -82,18 +82,41 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid
} }
} }
static void SetDeviceLable(const char *dir, const char *path) static void SetDeviceLable(const char *path)
{ {
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
int rc = 0; int rc = 0;
if (!STRINGEQUAL(dir, "/dev")) { char buffer[PATH_MAX] = {};
rc = RestoreconRecurse(dir); const char *p = NULL;
char *slash = NULL;
p = path;
slash = strchr(path, '/');
while (slash != NULL) {
int gap = slash - p;
p = slash + 1;
if (gap == 0) {
slash = strchr(p, '/');
continue;
}
if (gap < 0) { // end with '/'
break;
}
if (memcpy_s(buffer, PATH_MAX, path, p - path - 1) != EOK) {
INIT_LOGE("[uevent] Failed to memcpy path %s", path);
return;
}
rc += Restorecon(buffer);
slash = strchr(p, '/');
} }
rc += Restorecon(path); rc += Restorecon(path);
if (rc != 0) { if (rc != 0) {
INIT_LOGI("restorecon device node[%s] failed. %d", path, errno); INIT_LOGE("[uevent] Failed to Restorecon \" %s \"", path);
} }
return;
#endif #endif
} }
...@@ -144,7 +167,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, ...@@ -144,7 +167,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
if (symLinks != NULL) { if (symLinks != NULL) {
CreateSymbolLinks(deviceNode, symLinks); CreateSymbolLinks(deviceNode, symLinks);
} }
SetDeviceLable(devicePath, deviceNode); SetDeviceLable(deviceNode);
// No matter what result the symbol links returns, // No matter what result the symbol links returns,
// as long as create device node done, just returns success. // as long as create device node done, just returns success.
rc = 0; rc = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册