Christian Weisgerber
2001-Mar-17 06:49 UTC
[vorbis-dev] ogg123 doesn't destroy shm segment
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@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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
On Sat, Mar 17, 2001 at 02:49:15PM +0000, Christian Weisgerber wrote:> 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().I stole some of that shm code from buffer(1). I need to go back and steal some more :) Well okay I didn't "steal" it per se, just used it as an example of how to use the Unix shm functions.> 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.I was aware of this solution, and indeed it does seem cleaner. However I still do not know how portable this method is. Anyone?> - IPC_CREAT|S_IREAD|S_IWRITE); > + IPC_CREAT|SHM_R|SHM_W);duh. Those weren't in my manpage, though, IIRC.> + /* Remove segment after last process detaches it or terminates. */ > + shmctl(shmid, IPC_RMID, 0); > +ure. But wait a second -- a shared memory segment stays around even after the last process using it dies? Sounds like Win32... Patch will be applied as soon as I copy it over from my server, test-compile and commit. Oops, gotta switch out my mobo now... -- Kenneth Arnold <ken@arnoldnet.net> / kcarnold / Linux user #180115 http://arnoldnet.net/~kcarnold/ <HR NOSHADE> <UL> <LI>application/pgp-signature attachment: stored </UL> -------------- next part -------------- A non-text attachment was scrubbed... Name: part Type: application/octet-stream Size: 233 bytes Desc: not available Url : http://lists.xiph.org/pipermail/vorbis-dev/attachments/20010317/929c53e4/part-0001.obj