!1152 修复获取容器信息失败
Merge pull request !1152 from zhushengle/container_bug
This commit is contained in:
commit
a04ab13c76
|
@ -103,6 +103,8 @@ static ssize_t ProcessContainerLink(unsigned int containerID, ContainerType type
|
||||||
|
|
||||||
static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen)
|
static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer, size_t bufLen)
|
||||||
{
|
{
|
||||||
|
char *freeBuf = NULL;
|
||||||
|
char *buf = buffer;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
unsigned int intSave;
|
unsigned int intSave;
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
|
@ -112,17 +114,41 @@ static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) {
|
||||||
|
buf = LOS_MemAlloc(m_aucSysMem1, bufLen);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
(void)memset_s(buf, bufLen, 0, bufLen);
|
||||||
|
freeBuf = buf;
|
||||||
|
}
|
||||||
|
|
||||||
LosProcessCB *processCB = ProcGetProcessCB(data);
|
LosProcessCB *processCB = ProcGetProcessCB(data);
|
||||||
SCHEDULER_LOCK(intSave);
|
SCHEDULER_LOCK(intSave);
|
||||||
UINT32 containerID = OsGetContainerID(processCB, (ContainerType)data->type);
|
UINT32 containerID = OsGetContainerID(processCB, (ContainerType)data->type);
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
if (containerID != OS_INVALID_VALUE) {
|
if (containerID != OS_INVALID_VALUE) {
|
||||||
return ProcessContainerLink(containerID, (ContainerType)data->type, buffer, bufLen);
|
count = ProcessContainerLink(containerID, (ContainerType)data->type, buf, bufLen);
|
||||||
}
|
} else {
|
||||||
count = strlen("(unknown)");
|
count = strlen("(unknown)");
|
||||||
if (memcpy_s(buffer, bufLen, "(unknown)", count + 1) != EOK) {
|
if (memcpy_s(buf, bufLen, "(unknown)", count + 1) != EOK) {
|
||||||
|
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (count < 0) {
|
||||||
|
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)buffer, bufLen)) {
|
||||||
|
if (LOS_ArchCopyToUser(buffer, buf, bufLen) != 0) {
|
||||||
|
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(void)LOS_MemFree(m_aucSysMem1, freeBuf);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,7 +321,7 @@ static unsigned int ProcRealProcessIDGet(unsigned int pid)
|
||||||
|
|
||||||
SCHEDULER_LOCK(intSave);
|
SCHEDULER_LOCK(intSave);
|
||||||
LosProcessCB *pcb = OsGetPCBFromVpid(pid);
|
LosProcessCB *pcb = OsGetPCBFromVpid(pid);
|
||||||
if (pcb == NULL) {
|
if (OsProcessIsInactive(pcb)) {
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,13 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "It_process_fs_test.h"
|
#include "It_process_fs_test.h"
|
||||||
|
|
||||||
static const int ini_process_max = 3;
|
|
||||||
|
|
||||||
void ItProcessFs013(void)
|
void ItProcessFs013(void)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
DIR *dirp = nullptr;
|
DIR *dirp = nullptr;
|
||||||
for (int i = 1; i <= ini_process_max; i++) {
|
path = GenProcPidPath(1);
|
||||||
if (i != 2) { /* 2: skip kernel process */
|
|
||||||
path = GenProcPidPath(i);
|
|
||||||
printf("path: %s\n", path.c_str());
|
printf("path: %s\n", path.c_str());
|
||||||
dirp = opendir(path.data());
|
dirp = opendir(path.data());
|
||||||
ASSERT_NE(dirp, nullptr);
|
ASSERT_NE(dirp, nullptr);
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue