sim_rptun: unlink shm when quit

if not unlink shm, the shared memory object still exists in host /dev/shm after quit
if nuttx is started with administrator privileges, or if it is restarted with user
privileges, there will be a problem with the permission to open this shm file

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao 2023-09-22 16:45:34 +08:00 committed by Mateusz Szafoni
parent 4256dd934f
commit da7d6ef37b
3 changed files with 11 additions and 2 deletions

View File

@ -119,7 +119,7 @@ void *host_allocshmem(const char *name, size_t size, int master)
{
/* Avoid the second slave instance open successfully */
host_uninterruptible(shm_unlink, name);
host_unlinkshmem(name);
}
ret = host_uninterruptible(ftruncate, fd, size);
@ -145,6 +145,11 @@ void host_freeshmem(void *mem)
host_uninterruptible(munmap, mem, 0);
}
int host_unlinkshmem(const char *name)
{
return host_uninterruptible(shm_unlink, name);
}
size_t host_mallocsize(void *mem)
{
#ifdef __APPLE__

View File

@ -222,6 +222,7 @@ void *host_memalign(size_t alignment, size_t size);
void host_free(void *mem);
void *host_realloc(void *oldmem, size_t size);
void host_mallinfo(int *aordblks, int *uordblks);
int host_unlinkshmem(const char *name);
/* sim_hosttime.c ***********************************************************/

View File

@ -201,11 +201,14 @@ static int sim_rptun_stop(struct rptun_dev_s *dev)
if ((priv->master & SIM_RPTUN_BOOT) && (priv->pid > 0))
{
priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT;
host_waitpid(priv->pid);
}
if (priv->shmem)
{
host_freeshmem(priv->shmem);
priv->shmem = NULL;
host_unlinkshmem(priv->shmemname);
}
return 0;