diff options
author | joq <joq@0c269be4-1314-0410-8aa9-9f06e86f4224> | 2004-12-26 05:23:02 +0000 |
---|---|---|
committer | joq <joq@0c269be4-1314-0410-8aa9-9f06e86f4224> | 2004-12-26 05:23:02 +0000 |
commit | 898c65f920653f3271b3aef82ac1605fecd8ded1 (patch) | |
tree | 933158ed02bc4176e41261d7067e6bfdb064914b | |
parent | 5246f2a1045a452bbd9881fea01b7ccfbf6994de (diff) | |
download | jack1-898c65f920653f3271b3aef82ac1605fecd8ded1.tar.gz |
[0.99.40] POSIX shm workarounds for OSX
git-svn-id: svn+ssh://jackaudio.org/trunk/jack@853 0c269be4-1314-0410-8aa9-9f06e86f4224
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | jack/shm.h | 12 | ||||
-rw-r--r-- | libjack/shm.c | 77 |
3 files changed, 50 insertions, 41 deletions
diff --git a/configure.ac b/configure.ac index 9ea5f11..a4ea791 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ dnl changes are made dnl --- JACK_MAJOR_VERSION=0 JACK_MINOR_VERSION=99 -JACK_MICRO_VERSION=39 +JACK_MICRO_VERSION=40 dnl --- dnl HOWTO: updating the jack protocol version @@ -12,12 +12,20 @@ #define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */ #define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */ + +/* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory + * segment name (instead of NAME_MAX or PATH_MAX as defined by the + * standard). + */ #ifdef USE_POSIX_SHM -typedef char shm_name_t[JACK_SERVER_NAME_SIZE]; +#ifndef SHM_NAME_MAX +#define SHM_NAME_MAX NAME_MAX +#endif +typedef char shm_name_t[SHM_NAME_MAX]; typedef shm_name_t jack_shm_id_t; #else /* System V SHM */ typedef int jack_shm_id_t; -#endif +#endif /* SHM type */ /* shared memory type */ typedef enum { diff --git a/libjack/shm.c b/libjack/shm.c index a2e6c54..e72bd2d 100644 --- a/libjack/shm.c +++ b/libjack/shm.c @@ -665,59 +665,60 @@ jack_release_shm (jack_shm_info_t* si) } } -/* allocate a POSIX shared memory segment - * - * The shm_name should not have a leading slash, that will be provided - * here along with a prefix making it unique to this server. - */ +/* allocate a POSIX shared memory segment */ int jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si) { jack_shm_registry_t* registry; int shm_fd; int rc = -1; - char name[NAME_MAX+1]; - - /* concatenate jack_shm_server_prefix and shm_name to build a - * unique name per user and per server */ - snprintf (name, sizeof (name), "%s%s", - jack_shm_server_prefix, shm_name); - - if (strlen (name) >= sizeof (jack_shm_id_t)) { - jack_error ("shm segment name too long %s", name); - return -1; - } + char name[SHM_NAME_MAX+1]; jack_shm_lock_registry (); - if ((registry = jack_get_free_shm_info ())) { - - if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) >= 0) { + if ((registry = jack_get_free_shm_info ()) == NULL) { + jack_error ("shm registry full"); + goto unlock; + } - if (ftruncate (shm_fd, size) >= 0) { + /* On Mac OS X, the maximum length of a shared memory segment + * name is SHM_NAME_MAX (instead of NAME_MAX or PATH_MAX as + * defined by the standard). Unfortunately, Apple sets this + * value so small (about 31 bytes) that it is useless for + * actual names. So, we construct a short name from the + * registry index for uniqueness and ignore the shm_name + * parameter. Bah! + */ + snprintf (name, sizeof (name), "/jack-%d", registry->index); - close (shm_fd); - registry->size = size; - //JOQ: better to use strncpy() here... - snprintf (registry->id, sizeof (registry->id), - "%s", name); - registry->allocator = getpid(); - si->index = registry->index; - si->attached_at = MAP_FAILED; /* not attached */ - rc = 0; /* success */ + if (strlen (name) >= sizeof (registry->id)) { + jack_error ("shm segment name too long %s", name); + goto unlock; + } - } else { - jack_error ("cannot set size of engine shm " - "registry 0 (%s)", - strerror (errno)); - } + if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) < 0) { + jack_error ("cannot create shm segment %s (%s)", + name, strerror (errno)); + goto unlock; + } - } else { - jack_error ("cannot create shm segment %s (%s)", - name, strerror (errno)); - } + if (ftruncate (shm_fd, size) < 0) { + jack_error ("cannot set size of engine shm " + "registry 0 (%s)", + strerror (errno)); + close (shm_fd); + goto unlock; } + close (shm_fd); + registry->size = size; + strncpy (registry->id, name, sizeof (registry->id)); + registry->allocator = getpid(); + si->index = registry->index; + si->attached_at = MAP_FAILED; /* not attached */ + rc = 0; /* success */ + + unlock: jack_shm_unlock_registry (); return rc; } |