fix: SysOpenat返回值应该为进程fd,而非系统全局fd。

close #I3TNAK

Signed-off-by: chenjing <chenjing139@huawei.com>
Change-Id: Ie754259ead7fc8f4c3b0fa36ef31969dd728b235
This commit is contained in:
chenjing 2021-06-07 15:01:42 +08:00
parent c39c10c978
commit 3457c0b11d
1 changed files with 19 additions and 2 deletions

View File

@ -1557,6 +1557,7 @@ int SysFtruncate64(int fd, off64_t length)
int SysOpenat(int dirfd, const char *path, int oflags, ...)
{
int ret;
int procFd;
char *pathRet = NULL;
mode_t mode;
#ifdef LOSCFG_FILE_MODE
@ -1572,10 +1573,16 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...)
if (path != NULL) {
ret = UserPathCopy(path, &pathRet);
if (ret != 0) {
goto OUT;
return ret;
}
}
procFd = AllocProcessFd();
if (procFd < 0) {
ret = -EMFILE;
goto ERROUT;
}
if (dirfd != AT_FDCWD) {
/* Process fd convert to system global fd */
dirfd = GetAssociatedSystemFd(dirfd);
@ -1584,12 +1591,22 @@ int SysOpenat(int dirfd, const char *path, int oflags, ...)
ret = do_open(dirfd, (path ? pathRet : NULL), oflags, mode);
if (ret < 0) {
ret = -get_errno();
goto ERROUT;
}
OUT:
AssociateSystemFd(procFd, ret);
if (pathRet != NULL) {
(void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
return procFd;
ERROUT:
if (pathRet != NULL) {
(void)LOS_MemFree(OS_SYS_MEM_ADDR, pathRet);
}
if (procFd >= 0) {
FreeProcessFd(procFd);
}
return ret;
}