Bug 940819 - Signaling - use IPC_PRIVATE instead of generating unique key for IPC r=jesup
authorEthan Hugg <ethanhugg@gmail.com>
Thu, 21 Nov 2013 11:08:15 -0800
changeset 157171 e58ce8839585a598ef47a139ea8adacfdc54eeb9
parent 157170 f7b3e94e3d502d6ec998b2da2671518c272bf140
child 157172 febf82ab059650839546c76433000dc83870091e
push id25703
push userphilringnalda@gmail.com
push dateSat, 23 Nov 2013 16:19:02 +0000
treeherdermozilla-central@ad6589ed742c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs940819
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 940819 - Signaling - use IPC_PRIVATE instead of generating unique key for IPC r=jesup
media/webrtc/signaling/src/sipcc/cpr/linux/cpr_linux_ipc.c
--- a/media/webrtc/signaling/src/sipcc/cpr/linux/cpr_linux_ipc.c
+++ b/media/webrtc/signaling/src/sipcc/cpr/linux/cpr_linux_ipc.c
@@ -273,105 +273,70 @@ cprMoveMsgToQueue(cpr_msg_queue_t *msgq)
  * @note the actual message queue depth will be bounded by the
  *       standard system message queue depth and CPR_MAX_MSG_Q_DEPTH.
  *       If 'depth' is outside of the bounds, the value will be
  *       reset automatically.
  */
 cprMsgQueue_t
 cprCreateMessageQueue (const char *name, uint16_t depth)
 {
-    static const char fname[] = "cprCreateMessageQueue";
     cpr_msg_queue_t *msgq;
-    key_t key;
-    static int key_id = 100; /* arbitrary starting number */
     struct msqid_ds buf;
 
     msgq =(cpr_msg_queue_t *)cpr_calloc(1, sizeof(cpr_msg_queue_t));
     if (msgq == NULL) {
-        CPR_ERROR("%s: Malloc failed: %s\n", fname,
+        CPR_ERROR("%s: Malloc failed: %s\n", __FUNCTION__,
                   name ? name : unnamed_string);
         errno = ENOMEM;
         return NULL;
     }
 
     msgq->name = name ? name : unnamed_string;
 
     /*
-     * Find a unique key
-     */
-    key = ftok("/proc/self", key_id++);
-    CSFLogDebug(logTag, "key = %x\n", key);
-
-    if (key == -1) {
-        CPR_ERROR("%s: Key generation failed: %d\n", fname, errno);
-        cpr_free(msgq);
-        return NULL;
-    }
-
-    /*
      * Set creation flag so that OS will create the message queue
      */
-    msgq->queueId = msgget(key, (IPC_EXCL | IPC_CREAT | 0666));
-    if (msgq->queueId == -1) {
-        if (errno == EEXIST) {
-            CSFLogDebug(logTag, "Q exists so first remove it and then create again\n");
-                /* Remove message queue */
-            msgq->queueId = msgget(key, (IPC_CREAT | 0666));
-            if (msgctl(msgq->queueId, IPC_RMID, &buf) == -1) {
-
-                CPR_ERROR("%s: Destruction failed: %s: %d\n", fname,
-                          msgq->name, errno);
-
-                return NULL;
-            }
-            msgq->queueId = msgget(key, (IPC_CREAT | 0666));
-        }
-    } else {
-        CSFLogDebug(logTag, "there was no preexisting q..\n");
-
-    }
-
-
+    msgq->queueId = msgget(IPC_PRIVATE, (IPC_EXCL | IPC_CREAT | 0666));
 
     if (msgq->queueId == -1) {
-        CPR_ERROR("%s: Creation failed: %s: %d\n", fname, name, errno);
+        CPR_ERROR("%s: Creation failed: %s: %d\n", __FUNCTION__, name, errno);
         if (errno == EEXIST) {
 
         }
 
         cpr_free(msgq);
         return NULL;
     }
     CSFLogDebug(logTag, "create message q with id=%x\n", msgq->queueId);
 
     /* flush the q before ?? */
 
     /*
      * Create mutex for extended (overflow) queue
      */
     if (pthread_mutex_init(&msgq->mutex, NULL) != 0) {
         CPR_ERROR("%s: Failed to create msg queue (%s) mutex: %d\n",
-                  fname, name, errno);
+                  __FUNCTION__, name, errno);
         (void) msgctl(msgq->queueId, IPC_RMID, &buf);
         cpr_free(msgq);
         return NULL;
     }
 
     /*
      * Set the extended message queue depth (within bounds)
      */
     if (depth > CPR_MAX_MSG_Q_DEPTH) {
-        CPR_INFO("%s: Depth too large (%d) reset to %d\n", fname, depth,
+        CPR_INFO("%s: Depth too large (%d) reset to %d\n", __FUNCTION__, depth,
                  CPR_MAX_MSG_Q_DEPTH);
         depth = CPR_MAX_MSG_Q_DEPTH;
     }
 
     if (depth < OS_MSGTQL) {
         if (depth) {
-            CPR_INFO("%s: Depth too small (%d) reset to %d\n", fname, depth, OS_MSGTQL);
+            CPR_INFO("%s: Depth too small (%d) reset to %d\n", __FUNCTION__, depth, OS_MSGTQL);
         }
         depth = OS_MSGTQL;
     }
     msgq->maxExtendedQDepth = depth - OS_MSGTQL;
 
     /*
      * Add message queue to list for statistics reporting
      */