22 #include "JackChannel.h"
23 #include "JackLibGlobals.h"
24 #include "JackServerLaunch.h"
25 #include "JackPlatformPlug.h"
35 #if defined(_MSC_VER) || defined(__MINGW__) || defined(__MINGW32__)
38 find_path_to_jackdrc(
char *path_to_jackdrc)
40 char user_jackdrc[1024];
44 user_jackdrc[0] = user_jackdrc[1] = 0;
46 if (S_OK == SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, user_jackdrc))
49 char ch = user_jackdrc[strlen(user_jackdrc)-1];
51 if ((
'/' != ch) && (
'\\' != ch))
52 strcat(user_jackdrc,
"\\");
54 if (user_jackdrc[1] ==
':')
57 strcat(user_jackdrc,
".jackdrc");
58 strcpy(path_to_jackdrc, user_jackdrc);
60 ret = path_to_jackdrc;
63 path_to_jackdrc[0] =
'\0';
66 path_to_jackdrc[0] =
'\0';
74 find_path_to_jackdrc(
char *path_to_jackdrc)
89 static int start_server_aux(
const char* server_name)
102 char arguments [256];
103 char buffer [MAX_PATH];
104 char filename [MAX_PATH];
105 char curr_wd [MAX_PATH];
106 char temp_wd [MAX_PATH];
109 if (find_path_to_jackdrc(filename))
110 fp = fopen(filename,
"r");
122 fgets(filename, MAX_PATH, fp);
124 if (p = strstr(filename,
".exe")) {
127 pos = (size_t)(p - filename);
128 fseek(fp, 0, SEEK_SET);
130 if (command = (
char*)malloc(pos+1))
131 ret = fread(command, 1, pos, fp);
133 if (ret && !ferror(fp)) {
135 back_slash = strrchr(command,
'\\');
136 forward_slash = strrchr(command,
'/');
137 if (back_slash > forward_slash)
140 p = forward_slash + 1;
143 while (ret != 0 && ret != EOF) {
144 strcat(arguments, buffer);
145 strcat(arguments,
" ");
146 ret = fscanf(fp,
"%s", buffer);
149 if (strlen(arguments) > 0) {
159 strcpy(buffer, JACK_LOCATION
"/jackd.exe");
160 command = (
char*)malloc((strlen(buffer))+1);
161 strcpy(command, buffer);
162 strncpy(arguments,
"jackd.exe -S -d " JACK_DEFAULT_DRIVER, 255);
165 int buffer_termination;
166 bool verbose_mode =
false;
167 argv = (
char**)malloc(255);
173 argv[i] = (
char*)malloc(strlen (
"-T") + 1);
174 strcpy (argv[i++],
"-T");
176 size_t optlen = strlen(
"-n");
177 char* buf = (
char*)malloc(optlen + strlen(server_name) + 1);
179 strcpy(buf + optlen, server_name);
185 if ((pos < strlen(arguments)) && (arguments[pos+1]) && (arguments[pos+1] !=
' ')) {
186 strncpy(buffer, arguments + pos++, 1);
187 buffer_termination = 1;
190 buffer_termination = 0;
194 if (buffer[0] ==
'\"')
195 result = strcspn(arguments + pos,
"\"");
197 result = strcspn(arguments + pos,
" ");
203 strcat(buffer, arguments + pos);
206 buffer[result + buffer_termination] =
'\0';
207 if (buffer[0] ==
'\"') {
208 strcat(buffer,
"\"");
212 argv[i] = (
char*)malloc(strlen(buffer) + 1);
213 strcpy(argv[i], buffer);
217 if ((0 == strcmp(buffer,
"-v")) || (0 == strcmp(buffer,
"--verbose")))
224 #ifdef SUPPORT_PRE_1_9_8_SERVER
226 if (_getcwd(curr_wd, MAX_PATH)) {
227 strcpy(temp_wd, command);
228 back_slash = strrchr(temp_wd,
'\\');
229 forward_slash = strrchr(temp_wd,
'/');
230 if (back_slash > forward_slash)
246 ret = _spawnv(_P_NOWAIT, command, argv);
249 ret = _spawnv(_P_DETACH, command, argv);
255 fprintf(stderr,
"Execution of JACK server (command = \"%s\") failed: %s\n", command, strerror(errno));
257 if (strlen(curr_wd)) {
266 for (i = 0; argv[i] != 0; i++)
272 return (ret == (-1) ?
false :
true);
275 static int start_server(
const char* server_name, jack_options_t options)
277 if ((options & JackNoStartServer) || getenv(
"JACK_NO_START_SERVER")) {
281 return (((-1) != (start_server_aux(server_name)) ? 0 : (-1)));
284 static int server_connect(
const char* server_name)
287 int res = channel.ServerCheck(server_name);
294 int try_start_server(
jack_varargs_t* va, jack_options_t options, jack_status_t* status)
296 if (server_connect(va->server_name) < 0) {
298 if (start_server(va->server_name, options)) {
299 int my_status1 = *status | JackFailure | JackServerFailed;
300 *status = (jack_status_t)my_status1;
307 int my_status1 = *status | JackFailure | JackServerFailed;
308 *status = (jack_status_t)my_status1;
311 }
while (server_connect(va->server_name) < 0);
312 int my_status1 = *status | JackServerStarted;
313 *status = (jack_status_t)my_status1;