Menu

#1 mmap core dumps when shm is full

1.0
open
nobody
2014-11-16
2012-10-03
No

mmap in the following code in controller.cpp core dumps when mmap is called if the shared memory file system is full.

    do {
            pid_t   pid = getpid ();
#ifdef HAVE_MACOSX
            sprintf (pVideoMixer->m_output_memory_handle_name, "/shmpipe.%d.%d", pid, no);
            pVideoMixer->m_output_memory_handle =
                    shm_open (pVideoMixer->m_output_memory_handle_name,
                            O_RDWR | O_CREAT | O_EXCL,  S_IRUSR | S_IWUSR | S_IRGRP);
#else
            sprintf (pVideoMixer->m_output_memory_handle_name, "/shmpipe.%5d.%5d", pid, no);
            pVideoMixer->m_output_memory_handle =
                    shm_open (pVideoMixer->m_output_memory_handle_name,
                            O_RDWR | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP);
#endif
    } while (pVideoMixer->m_output_memory_handle < 0 && errno == EEXIST);
    if (pVideoMixer->m_output_memory_handle < 0) {
            fprintf (stderr, "Unable to open shared memory handle: name %s. Error : %s\n",
                    pVideoMixer->m_output_memory_handle_name, strerror (errno));
            exit (1);
    }
    if (ftruncate (pVideoMixer->m_output_memory_handle,
            pVideoMixer->m_output_memory_size) < 0) {
            perror ("Unable to resize shm area.");
            exit (1);
    }
    pVideoMixer->m_pOutput_memory_base = (uint8_t*) mmap (NULL,
            pVideoMixer->m_output_memory_size, PROT_READ | PROT_WRITE, MAP_SHARED,
            pVideoMixer->m_output_memory_handle, 0);

Discussion


Log in to post a comment.