From 56dfc084148507ecdea3029701b68981cf09cc67 Mon Sep 17 00:00:00 2001 From: joq Date: Tue, 21 Dec 2004 03:50:47 +0000 Subject: [PATCH] [0.99.37] better jack_client_open() error checking git-svn-id: svn+ssh://jackaudio.org/trunk/jack@847 0c269be4-1314-0410-8aa9-9f06e86f4224 --- configure.ac | 4 ++-- jack/internal.h | 2 +- jack/types.h | 12 +++++++++++- jackd/clientengine.c | 20 +++++++++++++++++--- jackd/engine.c | 6 ------ libjack/client.c | 16 ++++++++-------- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 00008a6..c798358 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=36 +JACK_MICRO_VERSION=37 dnl --- dnl HOWTO: updating the jack protocol version @@ -25,7 +25,7 @@ dnl made to the way libjack communicates with jackd dnl that would break applications linked with an older dnl version of libjack. dnl --- -JACK_PROTOCOL_VERSION=14 +JACK_PROTOCOL_VERSION=15 dnl --- dnl HOWTO: updating the libjack interface version diff --git a/jack/internal.h b/jack/internal.h index 9e4610f..1d8ce11 100644 --- a/jack/internal.h +++ b/jack/internal.h @@ -250,6 +250,7 @@ typedef volatile struct { typedef struct { + uint32_t protocol_v; /* protocol version, must go first */ int32_t load; ClientType type; jack_options_t options; @@ -262,7 +263,6 @@ typedef struct { typedef struct { - uint32_t protocol_v; jack_status_t status; jack_shm_info_t client_shm; diff --git a/jack/types.h b/jack/types.h index 2b4cee5..029e469 100644 --- a/jack/types.h +++ b/jack/types.h @@ -351,7 +351,17 @@ enum JackStatus { /** * Unable to initialize client */ - JackInitFailure = 0x100 + JackInitFailure = 0x100, + + /** + * Unable to access shared memory + */ + JackShmFailure = 0x200, + + /** + * Client's protocol version does not match + */ + JackVersionError = 0x400 }; /** diff --git a/jackd/clientengine.c b/jackd/clientengine.c index 9d4d99f..2dee845 100644 --- a/jackd/clientengine.c +++ b/jackd/clientengine.c @@ -650,10 +650,25 @@ jack_client_create (jack_engine_t *engine, int client_fd) jack_client_internal_t *client; jack_client_connect_request_t req; jack_client_connect_result_t res; + ssize_t nbytes; res.status = 0; - if (read (client_fd, &req, sizeof (req)) != sizeof (req)) { + nbytes = read (client_fd, &req, sizeof (req)); + + if ((nbytes < sizeof (req.protocol_v)) + || (req.protocol_v != jack_protocol_version)) { + + /* JACK protocol incompatibility */ + res.status |= (JackFailure|JackVersionError); + jack_error ("JACK protocol mismatch"); + if (write (client_fd, &res, sizeof (res)) != sizeof (res)) { + jack_error ("cannot write client connection response"); + } + return -1; + } + + if (nbytes != sizeof (req)) { jack_error ("cannot read connection request from client"); return -1; } @@ -680,7 +695,6 @@ jack_client_create (jack_engine_t *engine, int client_fd) res.status |= JackFailure; /* just making sure */ return -1; } - res.protocol_v = jack_protocol_version; res.client_shm = client->control_shm; res.engine_shm = engine->control_shm; res.realtime = engine->control->real_time; @@ -699,7 +713,7 @@ jack_client_create (jack_engine_t *engine, int client_fd) strcpy (res.fifo_prefix, engine->fifo_prefix); } - if (write (client->request_fd, &res, sizeof (res)) != sizeof (res)) { + if (write (client_fd, &res, sizeof (res)) != sizeof (res)) { jack_error ("cannot write connection response to client"); jack_client_delete (engine, client); return -1; diff --git a/jackd/engine.c b/jackd/engine.c index 53b15a9..69a7796 100644 --- a/jackd/engine.c +++ b/jackd/engine.c @@ -1489,12 +1489,6 @@ jack_server_thread (void *arg) return 0; } - -static void -jack_engine_reset_frame_timer (jack_engine_t* engine) -{ -} - jack_engine_t * jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock, const char *server_name, int temporary, int verbose, diff --git a/libjack/client.c b/libjack/client.c index 5ebba06..3f4a0df 100644 --- a/libjack/client.c +++ b/libjack/client.c @@ -600,6 +600,8 @@ jack_request_client (ClientType type, *status |= JackServerStarted; } + /* format connection request */ + req.protocol_v = jack_protocol_version; req.load = TRUE; req.type = type; snprintf (req.name, sizeof (req.name), @@ -641,18 +643,15 @@ jack_request_client (ClientType type, *status |= res->status; /* return server status bits */ if (*status & JackFailure) { - jack_error ("could not attach as client"); + if (*status & JackVersionError) { + jack_error ("client linked with incompatible libjack" + " version."); + } + jack_error ("could not attach to JACK server"); *status |= JackServerError; goto fail; } - if (res->protocol_v != jack_protocol_version){ - jack_error ("application linked against incompatible libjack" - " version."); - *status |= (JackFailure|JackServerError); - goto fail; - } - switch (type) { case ClientDriver: case ClientInternal: @@ -788,6 +787,7 @@ jack_client_open (const char *client_name, /* don't access shared memory until server connected */ if (jack_initialize_shm ()) { jack_error ("Unable to initialize shared memory."); + *status |= (JackFailure|JackShmFailure); return NULL; }