fix[common]: Add mpp_dup function

mpp_dup function use fnctl F_DUPFD_CLOEXEC for fd dup with CLOEXEC flag.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: Idd82eb935b06d2885685aeb696b95e910981539d
This commit is contained in:
Herman Chen
2024-01-09 16:38:33 +08:00
parent ccf32c1da3
commit 8db63d761a
10 changed files with 12 additions and 12 deletions

View File

@@ -17,7 +17,6 @@
#define MODULE_TAG "vpu"
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

View File

@@ -16,7 +16,6 @@
#define MODULE_TAG "vpu_api_legacy"
#include <fcntl.h>
#include "string.h"
#include "mpp_mem.h"

View File

@@ -16,7 +16,6 @@
#define MODULE_TAG "vpu_api_mlvec"
#include <fcntl.h>
#include "string.h"
#include "mpp_mem.h"

View File

@@ -17,7 +17,6 @@
#define MODULE_TAG "iep"
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include "mpp_env.h"

View File

@@ -17,7 +17,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>

View File

@@ -19,7 +19,6 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
@@ -113,7 +112,7 @@ static MPP_RET try_flip_flag(RK_U32 orig, RK_U32 flag)
src = &heap_infos[used];
if (src->fd > 0) {
/* found valid heap use it */
dst->fd = dup(src->fd);
dst->fd = mpp_dup(src->fd);
dst->flags = src->flags;
dma_heap_dbg_chk("dma-heap type %x %s remap to %x %s\n",
@@ -278,7 +277,7 @@ static MPP_RET os_allocator_dma_heap_import(void *ctx, MppBufferInfo *data)
mpp_assert(fd_ext > 0);
data->fd = dup(fd_ext);
data->fd = mpp_dup(fd_ext);
data->ptr = NULL;
dma_heap_dbg_ops("dev %d import %3d -> %3d\n", p->device, fd_ext, data->fd);

View File

@@ -19,7 +19,6 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
@@ -254,7 +253,7 @@ static MPP_RET os_allocator_drm_import(void *ctx, MppBufferInfo *data)
mpp_assert(fd_ext > 0);
data->fd = dup(fd_ext);
data->fd = mpp_dup(fd_ext);
data->ptr = NULL;
if (data->fd <= 0) {

View File

@@ -19,7 +19,6 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

View File

@@ -135,6 +135,7 @@
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#define chdir _chdir
#define mkdir _mkdir
#define access _access
@@ -150,6 +151,7 @@
#else
#include <unistd.h>
#include <stddef.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define mkdir(x) mkdir(x, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
@@ -210,6 +212,12 @@ static __inline RK_U32 mpp_is_32bit()
return ((sizeof(void *) == 4) ? (1) : (0));
}
static __inline RK_S32 mpp_dup(RK_S32 fd)
{
/* avoid stdin / stdout / stderr so start from 3 */
return fcntl(fd, F_DUPFD_CLOEXEC, 3);
}
RK_S32 axb_div_c(RK_S32 a, RK_S32 b, RK_S32 c);
RK_U32 mpp_align_16(RK_U32 val);
RK_U32 mpp_align_64(RK_U32 val);

View File

@@ -125,7 +125,7 @@ CamSource *camera_source_init(const char *device, RK_U32 bufcnt, RK_U32 width, R
return NULL;
ctx->bufcnt = bufcnt;
ctx->fd = open(device, O_RDWR, 0);
ctx->fd = open(device, O_RDWR | O_CLOEXEC, 0);
if (ctx->fd < 0) {
mpp_err_f("Cannot open device\n");
goto FAIL;