gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 3/3] Fix access to shared memory on Linux


From: Robert Norris
Subject: [gpsd-dev] [PATCH 3/3] Fix access to shared memory on Linux
Date: Sun, 5 Mar 2017 23:16:18 +0000

Using shmctl() with IPC_RMID on Linux results in the IPC Key changing to 0.
Thus clients attempting to connect to the key 0x47505344 fail to connect.

Unfortunately this means the shared memory segment still needs to be
managed manually on Linux.

TESTED:
Confirmed the shared memory key for GPSD is correctly 0x47505344
(using the command ipcs).
Clients such as 'gpxlogger -e shm' on Linux connect to the shared memory.
---
 shmexport.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/shmexport.c b/shmexport.c
index 2edf0776..c046f201 100644
--- a/shmexport.c
+++ b/shmexport.c
@@ -37,7 +37,6 @@ 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));
@@ -61,17 +60,22 @@ bool shm_acquire(struct gps_context_t *context)
        context->shmexport = NULL;
        return false;
     }
+#ifndef __linux__
     /* 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);
+    /*
+     * Alternatively this segment can be removed manually like this:
+     *  ipcrm -M 0x47505344
+     */
+    int 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);
     }
-
+#endif /* !__linux__ */
     gpsd_log(&context->errout, LOG_PROG,
             "shmat() for SHM export succeeded, segment %d\n", shmid);
     return true;
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]