Skip to content

Commit da7d6ef

Browse files
yintaoraiden00pl
authored andcommitted
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 <[email protected]>
1 parent 4256dd9 commit da7d6ef

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

arch/sim/src/sim/posix/sim_hostmemory.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void *host_allocshmem(const char *name, size_t size, int master)
119119
{
120120
/* Avoid the second slave instance open successfully */
121121

122-
host_uninterruptible(shm_unlink, name);
122+
host_unlinkshmem(name);
123123
}
124124

125125
ret = host_uninterruptible(ftruncate, fd, size);
@@ -145,6 +145,11 @@ void host_freeshmem(void *mem)
145145
host_uninterruptible(munmap, mem, 0);
146146
}
147147

148+
int host_unlinkshmem(const char *name)
149+
{
150+
return host_uninterruptible(shm_unlink, name);
151+
}
152+
148153
size_t host_mallocsize(void *mem)
149154
{
150155
#ifdef __APPLE__

arch/sim/src/sim/sim_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void *host_memalign(size_t alignment, size_t size);
222222
void host_free(void *mem);
223223
void *host_realloc(void *oldmem, size_t size);
224224
void host_mallinfo(int *aordblks, int *uordblks);
225+
int host_unlinkshmem(const char *name);
225226

226227
/* sim_hosttime.c ***********************************************************/
227228

arch/sim/src/sim/sim_rptun.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ static int sim_rptun_stop(struct rptun_dev_s *dev)
201201
if ((priv->master & SIM_RPTUN_BOOT) && (priv->pid > 0))
202202
{
203203
priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT;
204-
205204
host_waitpid(priv->pid);
205+
}
206206

207+
if (priv->shmem)
208+
{
207209
host_freeshmem(priv->shmem);
208210
priv->shmem = NULL;
211+
host_unlinkshmem(priv->shmemname);
209212
}
210213

211214
return 0;

0 commit comments

Comments
 (0)