Browse Source

Shared memory manager was calling abort in case of fatal error, now return an error in caller.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3859 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/v1.9.5
sletz 15 years ago
parent
commit
6ec1cee8b1
4 changed files with 84 additions and 37 deletions
  1. +4
    -0
      ChangeLog
  2. +3
    -0
      common/JackLibClient.cpp
  3. +76
    -36
      common/shm.c
  4. +1
    -1
      common/shm.h

+ 4
- 0
ChangeLog View File

@@ -28,6 +28,10 @@ Mario Lang
Jackdmp changes log Jackdmp changes log
--------------------------- ---------------------------


2009-12-15 Stephane Letz <letz@grame.fr>
* Shared memory manager was calling abort in case of fatal error, now return an error in caller.

2009-12-13 Stephane Letz <letz@grame.fr> 2009-12-13 Stephane Letz <letz@grame.fr>
* Mario Lang alsa_io time calculation overflow patch. * Mario Lang alsa_io time calculation overflow patch.


+ 3
- 0
common/JackLibClient.cpp View File

@@ -103,6 +103,9 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
} catch (int n) { } catch (int n) {
jack_error("Map shared memory segments exception %d", n); jack_error("Map shared memory segments exception %d", n);
goto error; goto error;
} catch (...) {
jack_error("Unknown error...");
goto error;
} }


SetupDriverSync(false); SetupDriverSync(false);


+ 76
- 36
common/shm.c View File

@@ -18,23 +18,23 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *
*/ */
/* This module provides a set of abstract shared memory interfaces
* with support using both System V and POSIX shared memory
* implementations. The code is divided into three sections:
*
* - common (interface-independent) code
* - POSIX implementation
* - System V implementation
*
* The implementation used is determined by whether USE_POSIX_SHM was
* set in the ./configure step.
*/
/* This module provides a set of abstract shared memory interfaces
* with support using both System V and POSIX shared memory
* implementations. The code is divided into three sections:
*
* - common (interface-independent) code
* - POSIX implementation
* - System V implementation
*
* The implementation used is determined by whether USE_POSIX_SHM was
* set in the ./configure step.
*/


#include "JackConstants.h" #include "JackConstants.h"


#ifdef WIN32 #ifdef WIN32
#include <process.h>
#include <process.h>
#include <stdio.h> #include <stdio.h>
#else #else


@@ -156,12 +156,11 @@ semaphore_add (int value) {}
static void static void
semaphore_error (char *msg) semaphore_error (char *msg)
{ {
jack_error ("Fatal JACK semaphore error: %s (%s)",
jack_error ("JACK semaphore error: %s (%s)",
msg, strerror (errno)); msg, strerror (errno));
abort ();
} }


static void
static int
semaphore_init () semaphore_init ()
{ {
key_t semkey = JACK_SEMAPHORE_KEY; key_t semkey = JACK_SEMAPHORE_KEY;
@@ -180,21 +179,26 @@ semaphore_init ()
sbuf.sem_op = 1; sbuf.sem_op = 1;
sbuf.sem_flg = 0; sbuf.sem_flg = 0;
if (semop(semid, &sbuf, 1) == -1) { if (semop(semid, &sbuf, 1) == -1) {
semaphore_error ("semop");
semaphore_error ("semop");
return -1;
} }


} else if (errno == EEXIST) { } else if (errno == EEXIST) {
if ((semid = semget(semkey, 0, 0)) == -1) { if ((semid = semget(semkey, 0, 0)) == -1) {
semaphore_error ("semget");
semaphore_error ("semget");
return -1;
} }


} else { } else {
semaphore_error ("semget creation");
semaphore_error ("semget creation");
return -1;
} }
} }
return 0;
} }


static inline void
static inline int
semaphore_add (int value) semaphore_add (int value)
{ {
struct sembuf sbuf; struct sembuf sbuf;
@@ -202,23 +206,29 @@ semaphore_add (int value)
sbuf.sem_num = 0; sbuf.sem_num = 0;
sbuf.sem_op = value; sbuf.sem_op = value;
sbuf.sem_flg = SEM_UNDO; sbuf.sem_flg = SEM_UNDO;
if (semop(semid, &sbuf, 1) == -1) { if (semop(semid, &sbuf, 1) == -1) {
semaphore_error ("semop"); semaphore_error ("semop");
return -1;
} }
return 0;
} }


#endif #endif


static void
static int
jack_shm_lock_registry (void) jack_shm_lock_registry (void)
{ {
if (semid == -1)
semaphore_init ();
if (semid == -1) {
if (semaphore_init () < 0)
return -1;
}


semaphore_add (-1);
return semaphore_add (-1);
} }


static void
static void
jack_shm_unlock_registry (void) jack_shm_unlock_registry (void)
{ {
semaphore_add (1); semaphore_add (1);
@@ -297,7 +307,10 @@ jack_server_initialize_shm (int new_registry)
if (jack_shm_header) if (jack_shm_header)
return 0; /* already initialized */ return 0; /* already initialized */


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


rc = jack_access_registry (&registry_info); rc = jack_access_registry (&registry_info);


@@ -353,7 +366,11 @@ jack_initialize_shm (const char *server_name)


jack_set_server_prefix (server_name); jack_set_server_prefix (server_name);


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}
if ((rc = jack_access_registry (&registry_info)) == 0) { if ((rc = jack_access_registry (&registry_info)) == 0) {
if ((rc = jack_shm_validate_registry ()) != 0) { if ((rc = jack_shm_validate_registry ()) != 0) {
jack_error ("Incompatible shm registry, " jack_error ("Incompatible shm registry, "
@@ -412,15 +429,20 @@ jack_release_shm_entry (jack_shm_registry_index_t index)
sizeof (jack_shm_registry[index].id)); sizeof (jack_shm_registry[index].id));
} }


void
int
jack_release_shm_info (jack_shm_registry_index_t index) jack_release_shm_info (jack_shm_registry_index_t index)
{ {
/* must NOT have the registry locked */ /* must NOT have the registry locked */
if (jack_shm_registry[index].allocator == GetPID()) { if (jack_shm_registry[index].allocator == GetPID()) {
jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}
jack_release_shm_entry (index); jack_release_shm_entry (index);
jack_shm_unlock_registry (); jack_shm_unlock_registry ();
} }
return 0;
} }


/* Claim server_name for this process. /* Claim server_name for this process.
@@ -440,7 +462,10 @@ jack_register_server (const char *server_name, int new_registry)
if (jack_server_initialize_shm (new_registry)) if (jack_server_initialize_shm (new_registry))
return ENOMEM; return ENOMEM;


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


/* See if server_name already registered. Since server names /* See if server_name already registered. Since server names
* are per-user, we register the unique server prefix string. * are per-user, we register the unique server prefix string.
@@ -497,7 +522,10 @@ void
jack_unregister_server (const char *server_name /* unused */) jack_unregister_server (const char *server_name /* unused */)
{ {
int i; int i;
jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


for (i = 0; i < MAX_SERVERS; i++) { for (i = 0; i < MAX_SERVERS; i++) {
if (jack_shm_header->server[i].pid == GetPID()) { if (jack_shm_header->server[i].pid == GetPID()) {
@@ -517,7 +545,10 @@ jack_cleanup_shm ()
int destroy; int destroy;
jack_shm_info_t copy; jack_shm_info_t copy;


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


for (i = 0; i < MAX_SHM_ID; i++) { for (i = 0; i < MAX_SHM_ID; i++) {
jack_shm_registry_t* r; jack_shm_registry_t* r;
@@ -741,7 +772,10 @@ jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si)
int rc = -1; int rc = -1;
char name[SHM_NAME_MAX+1]; char name[SHM_NAME_MAX+1];


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


if ((registry = jack_get_free_shm_info ()) == NULL) { if ((registry = jack_get_free_shm_info ()) == NULL) {
jack_error ("shm registry full"); jack_error ("shm registry full");
@@ -780,7 +814,7 @@ jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si)
close (shm_fd); close (shm_fd);
registry->size = size; registry->size = size;
strncpy (registry->id, name, sizeof (registry->id)); strncpy (registry->id, name, sizeof (registry->id));
registry->allocator = getpid();
registry->allocator = GetPID();
si->index = registry->index; si->index = registry->index;
si->ptr.attached_at = MAP_FAILED; /* not attached */ si->ptr.attached_at = MAP_FAILED; /* not attached */
rc = 0; /* success */ rc = 0; /* success */
@@ -936,7 +970,10 @@ jack_shmalloc (const char *shm_name, jack_shmsize_t size, jack_shm_info_t* si)
int rc = -1; int rc = -1;
char name[SHM_NAME_MAX+1]; char name[SHM_NAME_MAX+1];


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


if ((registry = jack_get_free_shm_info ()) == NULL) { if ((registry = jack_get_free_shm_info ()) == NULL) {
jack_error ("shm registry full"); jack_error ("shm registry full");
@@ -1133,7 +1170,10 @@ jack_shmalloc (const char* name_not_used, jack_shmsize_t size,
int rc = -1; int rc = -1;
jack_shm_registry_t* registry; jack_shm_registry_t* registry;


jack_shm_lock_registry ();
if (jack_shm_lock_registry () < 0) {
jack_error ("jack_shm_lock_registry fails...");
return -1;
}


if ((registry = jack_get_free_shm_info ())) { if ((registry = jack_get_free_shm_info ())) {




+ 1
- 1
common/shm.h View File

@@ -132,7 +132,7 @@ extern "C"
jack_shm_registry_index_t); jack_shm_registry_index_t);
void jack_shm_copy_to_registry (jack_shm_info_t*, void jack_shm_copy_to_registry (jack_shm_info_t*,
jack_shm_registry_index_t*); jack_shm_registry_index_t*);
void jack_release_shm_info (jack_shm_registry_index_t);
int jack_release_shm_info (jack_shm_registry_index_t);
char* jack_shm_addr (jack_shm_info_t* si); char* jack_shm_addr (jack_shm_info_t* si);


// here begin the API // here begin the API


Loading…
Cancel
Save