[vorbis-dev] ogg123 doesn't destroy shm segment

Christian Weisgerber naddy at mips.inka.de
Sat Mar 17 06:49:15 PST 2001



Every time ogg123 -bXXX is run, it creates another shared memory
segment but fails to destroy it on exit.  Thus an increasing number
of shm segments keeps piling up and eat all the (often rather
limited amount of) available shared memory.

The patch below corrects this and also fixes the bizarre abuse of
stat() permission bits for shmget().

On systems that support it, I'd very much like to get rid of using
SYSVSHM altogether and instead use a shared memory mapping of
/dev/zero.  The code is very simple and I have it running on BSD,
but I still need to steal an autoconf fragment to test for availability
of this feature in a portable manner.  More on this later.

Index: ogg123/buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.3
diff -u -r1.3 buffer.c
--- ogg123/buffer.c	2001/01/30 10:42:48	1.3
+++ ogg123/buffer.c	2001/03/17 14:38:36
@@ -8,7 +8,6 @@
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
-#include <sys/stat.h>
 #include <sys/time.h>
 #include <unistd.h> /* for fork and pipe*/
 #include <fcntl.h>
@@ -76,7 +75,7 @@
   /* Get the shared memory segment. */
   int shmid = shmget (IPC_PRIVATE,
                           sizeof(buf_t) + sizeof (chunk_t) * (size - 1),
-			  IPC_CREAT|S_IREAD|S_IWRITE);
+			  IPC_CREAT|SHM_R|SHM_W);
 
   if (shmid == -1)
     {
@@ -92,7 +91,10 @@
       perror ("shmat");
       exit (1);
     }
-  
+
+  /* Remove segment after last process detaches it or terminates. */
+  shmctl(shmid, IPC_RMID, 0);
+
   buffer_init (buf, size);
   
   /* Create a pipe for communication between the two processes. Unlike

-- 
Christian "naddy" Weisgerber                          naddy at mips.inka.de

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Vorbis-dev mailing list