diff options
author | Gary E. Miller <gem@rellim.com> | 2016-04-15 21:01:17 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2016-04-15 21:01:17 -0700 |
commit | 22c3fafb25b742973d7122edc626b30d03bdb36c (patch) | |
tree | 26ca010535a3290dde3f114d3c1373fc60b1967e | |
parent | 5e584724b6350ea3baf24f8b08d8c14db82f141c (diff) | |
download | gpsd-22c3fafb25b742973d7122edc626b30d03bdb36c.tar.gz |
Do not let the SHM linger forever.
If the SHM hangs around, and then the size increases, then the
SHM can no longer be opened.
-rw-r--r-- | shmexport.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/shmexport.c b/shmexport.c index 179a6142..2a0e4166 100644 --- a/shmexport.c +++ b/shmexport.c @@ -34,6 +34,7 @@ PERMISSIONS bool shm_acquire(struct gps_context_t *context) /* initialize the shared-memory segment to be used for export */ { + int status; long shmkey = getenv("GPSD_SHM_KEY") ? strtol(getenv("GPSD_SHM_KEY"), NULL, 0) : GPSD_SHM_KEY; int shmid = shmget((key_t)shmkey, sizeof(struct shmexport_t), (int)(IPC_CREAT|0666)); @@ -57,6 +58,17 @@ bool shm_acquire(struct gps_context_t *context) context->shmexport = NULL; return false; } + /* mark shmid to go away when no longer used + * Having it linger forever is bad, and when the size enlarges + * it can no longer be opened */ + status = shmctl(shmid, IPC_RMID, NULL); + if (status == -1) { + gpsd_log(&context->errout, LOG_ERROR, + "shmctl failed, errno = %d (%s)\n", + errno, strerror(errno)); + exit(1); + } + gpsd_log(&context->errout, LOG_PROG, "shmat() for SHM export succeeded, segment %d\n", shmid); return true; |