jackaudio / jack2

jack2 codebase
GNU General Public License v2.0
2.16k stars 371 forks source link

jack_client_open(JackNoStartServer) tries to start the server? #341

Open apronchenkov opened 6 years ago

apronchenkov commented 6 years ago

I'm using jack2-1.9.12. When I run the following simple client:

// xyz
#include <jack/jack.h>

int main() {
  jack_options_t options;
  jack_client_t *jclient;
  const char *id = "test";
  jack_status_t status;

  options = JackNoStartServer;

  jclient = jack_client_open (id, options, &status, NULL);
}

I expected that if there is no jackd process running, it will produce an error that the client is unable to connect to the server. And if the server is running, it will connect to it.

What I got. If there is no ~/.jackrc`, the client crashes because it's unable to find a driver name (=NULL):

#0 0x4c736f in __interceptor_strcmp.part.60 (xyz+0x4c736f)
#1 0x7f484b326b86 in jack_find_driver_descriptor(_JSList*, char const*) ../common/JackDriverLoader.cpp:405
#2 0x7f484b32883c in Jack::JackServerGlobals::Init() ../common/JackServerGlobals.cpp:288
#3 0x7f484b325523 in jack_client_open_aux(char const*, JackOptions, JackStatus*, __va_list_tag*) ../common/JackServerAPI.cpp:128
#4 0x7f484b3257ac in jack_client_open ../common/JackServerAPI.cpp:161
#5 0x41f5c8 in main xyz.cpp:8
#6 0x7f4848d01857 in __libc_start_main
#7 0x41f3e8 in _start

If I create the file with the following content: jackd --no-realtime -n default --verbose -d dummy but with no running jackd -- the client prints the following message:

server `default' registered JACK server starting in non-realtime mode self-connect-mode is "Don't restrict self connect requests"

and crashes

    #0 0x454e78 in strncpy (xyz+0x454e78)
    #1 0x7f19aa0fa037 in strncpy gcc-5-glibc-2.23/ca1d1c0/include/bits/string3.h:126
    #2 0x7f19aa0fa037 in _ZN4Jack17JackEngineControlC4Ebblblb17jack_timer_type_tPKc ../common/JackEngineControl.h:120
    #3 0x7f19aa0fa037 in Jack::JackServer::JackServer(bool, bool, int, bool, int, int, bool, jack_timer_type_t, char, char const*) ../common/JackServer.cpp:57
    #4 0x7f19aa0fdb5b in Jack::JackServerGlobals::Start(char const*, jack_driver_desc_t*, _JSList*, int, int, int, int, int, int, int, jack_timer_type_t, char) ../common/JackServerGlobals.cpp:54
    #5 0x7f19aa0ff19f in Jack::JackServerGlobals::Init() ../common/JackServerGlobals.cpp:350
    #6 0x7f19aa0fb523 in jack_client_open_aux(char const*, JackOptions, JackStatus*, __va_list_tag*) ../common/JackServerAPI.cpp:128
    #7 0x7f19aa0fb7ac in jack_client_open ../common/JackServerAPI.cpp:161
    #8 0x41f5c8 in main xyz.cpp:8
    #9 0x7f19a7ad7857 in __libc_start_main
    #10 0x41f3e8 in _start

If there is jackd already running in background, the client prints

`default' server already active

and crashes

    #0 0x7ff0ac77ecaf in Jack::JackServer::Stop() ../common/JackServer.cpp:184
    #1 0x7ff0ac783be5 in Jack::JackServerGlobals::Stop() ../common/JackServerGlobals.cpp:62
    #2 0x7ff0ac783dfc in Jack::JackServerGlobals::Destroy() ../common/JackServerGlobals.cpp:410
    #3 0x7ff0ac78489a in Jack::JackServerGlobals::Init() ../common/JackServerGlobals.cpp:402
    #4 0x7ff0ac781523 in jack_client_open_aux(char const*, JackOptions, JackStatus*, __va_list_tag*) ../common/JackServerAPI.cpp:128
    #5 0x7ff0ac7817ac in jack_client_open ../common/JackServerAPI.cpp:161
    #6 0x41f5c8 in main xyz.cpp:8
    #7 0x7ff0aa15d857 in __libc_start_main
    #8 0x41f3e8 in _start

I'm not sure what happens, but the feeling is that jack_client_open(JackNoStartServer) tries to start a jackd server. Will appreciate any help.

-- Thanks, Alexander

falkTX commented 6 years ago

remove the last "NULL" on client_open and try again. looks suspicious...

apronchenkov commented 6 years ago

I have tried the following code. The result is the same, the client crashes.

#include <jack/jack.h>

int main() {
  jack_status_t status;
  jack_client_t* jclient =
      jack_client_open("default", JackNoStartServer, &status);
  return status;
}
falkTX commented 6 years ago

is this all the code the application have? or are you mixing it with some other stuff? (as mentioned countless times, mixing libjackserver and libjack stuff won't work...)

do the jack examples work for you?

apronchenkov commented 6 years ago

For this issue it's the all code that I have.

apronchenkov commented 6 years ago

I have identified at least one of the issues #342

apronchenkov commented 6 years ago

I'm curious, do you know why there are two versions of jack_client_open? One in JackLibApi.cpp and in JackServerApi.cpp?

7890 commented 5 years ago

@apronchenkov FYI I tried the example code and it works as expected:

$ ./jc
Jack: JackClient::SetupDriverSync driver sem in flush mode
Jack: JackLinuxFutex::Connect name = jack_sem.1000_default_default
Jack: Clock source : system clock via clock_gettime
Jack: JackLibClient::Open name = default refnum = 3
$ echo $?
0
$ ./jc
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
$ echo $?
17

The JackNoStartServer is used in several example clients and there it seems to work too. Not sure what problem we are facing here, checking #341 now.

@apronchenkov If you have new insights, please post them here, thanks.