Commit d65e51b8 authored by sletz's avatar sletz
Browse files

Server and user directory related code moved in a JackTools file.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1683 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 0e5bc3bf
......@@ -13,6 +13,10 @@ Tom Szilagyi
Jackdmp changes log
---------------------------
2007-10-31 Stephane Letz <letz@grame.fr>
* Server and user directory related code moved in a JackTools file.
2007-10-30 Stephane Letz <letz@grame.fr>
* Fix a bug in freewheel management in async mode: drivers now receive the kStartFreewheelCallback and kStopFreewheelCallback notifications.
......
......@@ -523,7 +523,7 @@ int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl
return 0;
}
// Used for externall clients
// Used for external clients
int JackEngine::ClientExternalClose(int refnum)
{
JackClientInterface* client = fClientTable[refnum];
......
......@@ -23,6 +23,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackServerGlobals.h"
#include "JackError.h"
#include "JackTools.h"
#include "shm.h"
#include <getopt.h>
......@@ -30,8 +31,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <dirent.h>
#endif
#define DEFAULT_TMP_DIR "/tmp"
static char* jack_tmpdir = DEFAULT_TMP_DIR;
static char* server_name = NULL;
namespace Jack
......@@ -40,106 +39,6 @@ namespace Jack
long JackServerGlobals::fClientCount = 0;
JackServer* JackServerGlobals::fServer = NULL;
#ifndef WIN32
static char* jack_default_server_name(void)
{
char* server_name;
if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
server_name = "default";
return server_name;
}
/* returns the name of the per-user subdirectory of jack_tmpdir */
static char* jack_user_dir(void)
{
static char user_dir[PATH_MAX] = "";
/* format the path name on the first call */
if (user_dir[0] == '\0') {
snprintf(user_dir, sizeof(user_dir), "%s/jack-%d", jack_tmpdir, getuid());
}
return user_dir;
}
/* returns the name of the per-server subdirectory of jack_user_dir() */
static char* get_jack_server_dir(const char* server_name)
{
static char server_dir[PATH_MAX] = "";
// format the path name on the first call
if (server_dir[0] == '\0') {
snprintf(server_dir, sizeof(server_dir), "%s/%s", jack_user_dir(), server_name);
}
return server_dir;
}
static void
jack_cleanup_files(const char* server_name)
{
DIR *dir;
struct dirent *dirent;
char *dir_name = get_jack_server_dir(server_name);
/* On termination, we remove all files that jackd creates so
* subsequent attempts to start jackd will not believe that an
* instance is already running. If the server crashes or is
* terminated with SIGKILL, this is not possible. So, cleanup
* is also attempted when jackd starts.
*
* There are several tricky issues. First, the previous JACK
* server may have run for a different user ID, so its files
* may be inaccessible. This is handled by using a separate
* JACK_TMP_DIR subdirectory for each user. Second, there may
* be other servers running with different names. Each gets
* its own subdirectory within the per-user directory. The
* current process has already registered as `server_name', so
* we know there is no other server actively using that name.
*/
/* nothing to do if the server directory does not exist */
if ((dir = opendir(dir_name)) == NULL) {
return ;
}
/* unlink all the files in this directory, they are mine */
while ((dirent = readdir(dir)) != NULL) {
char fullpath[PATH_MAX];
if ((strcmp(dirent->d_name, ".") == 0)
|| (strcmp(dirent->d_name, "..") == 0)) {
continue;
}
snprintf(fullpath, sizeof (fullpath), "%s/%s", dir_name, dirent->d_name);
if (unlink(fullpath)) {
jack_error("cannot unlink `%s' (%s)", fullpath, strerror(errno));
}
}
closedir(dir);
/* now, delete the per-server subdirectory, itself */
if (rmdir(dir_name)) {
jack_error("cannot remove `%s' (%s)", dir_name,
strerror(errno));
}
/* finally, delete the per-user subdirectory, if empty */
if (rmdir (jack_user_dir())) {
if (errno != ENOTEMPTY) {
jack_error("cannot remove `%s' (%s)",
jack_user_dir(), strerror(errno));
}
}
}
#endif
int JackServerGlobals::JackStart(const char* server_name, jack_driver_desc_t* driver_desc, JSList* driver_params, int sync, int temporary, int time_out_ms, int rt, int priority, int loopback, int verbose)
{
......@@ -353,7 +252,7 @@ bool JackServerGlobals::Init()
#ifndef WIN32
if (server_name == NULL)
server_name = jack_default_server_name();
server_name = JackTools::DefaultServerName();
#endif
rc = jack_register_server(server_name, false);
......@@ -375,7 +274,7 @@ bool JackServerGlobals::Init()
/* clean up shared memory and files from any previous instance of this server name */
jack_cleanup_shm();
#ifndef WIN32
jack_cleanup_files(server_name);
JackTools::CleanupFiles(server_name);
#endif
if (!realtime && client_timeout == 0)
......@@ -391,7 +290,7 @@ bool JackServerGlobals::Init()
JackDelete();
jack_cleanup_shm();
#ifndef WIN32
jack_cleanup_files(server_name);
JackTools::CleanupFiles(server_name);
#endif
jack_unregister_server(server_name);
goto error;
......@@ -412,7 +311,7 @@ void JackServerGlobals::Destroy()
JackStop();
jack_cleanup_shm();
#ifndef WIN32
jack_cleanup_files(server_name);
JackTools::CleanupFiles(server_name);
#endif
jack_unregister_server(server_name);
}
......
......@@ -200,9 +200,6 @@ int JackServerSocket::Bind(const char* dir, const char* name, int which) // A re
JackLog("Bind: addr.sun_path %s\n", addr.sun_path);
unlink(fName); // Security...
JackLog("Bind: addr.sun_path %s\n", addr.sun_path);
unlink(fName); // Security...
if (bind(fSocket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
jack_error("Cannot bind server to socket (%s)", strerror(errno));
goto error;
......
/*
Copyright (C) 2001 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "JackTools.h"
#include "JackError.h"
namespace Jack
{
#define DEFAULT_TMP_DIR "/tmp"
char* jack_tmpdir = DEFAULT_TMP_DIR;
int JackTools::GetPID()
{
#ifdef WIN32
return _getpid();
#else
return getpid();
#endif
}
int JackTools::GetUID()
{
#ifdef WIN32
//return _getpid();
#error "No getuid function available"
#else
return getuid();
#endif
}
char* JackTools::DefaultServerName()
{
char* server_name;
if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
server_name = "default";
return server_name;
}
/* returns the name of the per-user subdirectory of jack_tmpdir */
char* JackTools::UserDir()
{
static char user_dir[PATH_MAX + 1] = "";
/* format the path name on the first call */
if (user_dir[0] == '\0') {
if (getenv ("JACK_PROMISCUOUS_SERVER")) {
snprintf(user_dir, sizeof(user_dir), "%s/jack", jack_tmpdir);
} else {
snprintf(user_dir, sizeof(user_dir), "%s/jack-%d", jack_tmpdir, GetUID());
}
}
return user_dir;
}
/* returns the name of the per-server subdirectory of jack_user_dir() */
char* JackTools::ServerDir(const char* server_name, char* server_dir)
{
/* format the path name into the suppled server_dir char array,
* assuming that server_dir is at least as large as PATH_MAX+1 */
snprintf(server_dir, PATH_MAX + 1, "%s/%s", UserDir(), server_name);
return server_dir;
}
void JackTools::CleanupFiles(const char* server_name)
{
DIR* dir;
struct dirent *dirent;
char dir_name[PATH_MAX + 1] = "";
ServerDir(server_name, dir_name);
/* On termination, we remove all files that jackd creates so
* subsequent attempts to start jackd will not believe that an
* instance is already running. If the server crashes or is
* terminated with SIGKILL, this is not possible. So, cleanup
* is also attempted when jackd starts.
*
* There are several tricky issues. First, the previous JACK
* server may have run for a different user ID, so its files
* may be inaccessible. This is handled by using a separate
* JACK_TMP_DIR subdirectory for each user. Second, there may
* be other servers running with different names. Each gets
* its own subdirectory within the per-user directory. The
* current process has already registered as `server_name', so
* we know there is no other server actively using that name.
*/
/* nothing to do if the server directory does not exist */
if ((dir = opendir(dir_name)) == NULL) {
return;
}
/* unlink all the files in this directory, they are mine */
while ((dirent = readdir(dir)) != NULL) {
char fullpath[PATH_MAX + 1];
if ((strcmp(dirent->d_name, ".") == 0) || (strcmp (dirent->d_name, "..") == 0)) {
continue;
}
snprintf(fullpath, sizeof(fullpath), "%s/%s", dir_name, dirent->d_name);
if (unlink(fullpath)) {
jack_error("cannot unlink `%s' (%s)", fullpath, strerror(errno));
}
}
closedir(dir);
/* now, delete the per-server subdirectory, itself */
if (rmdir(dir_name)) {
jack_error("cannot remove `%s' (%s)", dir_name, strerror(errno));
}
/* finally, delete the per-user subdirectory, if empty */
if (rmdir(UserDir())) {
if (errno != ENOTEMPTY) {
jack_error("cannot remove `%s' (%s)", UserDir(), strerror(errno));
}
}
}
}
/*
Copyright (C) 2001 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __JackTools__
#define __JackTools__
#ifdef WIN32
#include <windows.h>
#else
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#endif
namespace Jack
{
struct JackTools {
static int GetPID();
static int GetUID();
static char* UserDir();
static char* ServerDir(const char* server_name, char* server_dir);
static char* DefaultServerName();
static void CleanupFiles(const char* server_name);
};
}
#endif
......@@ -33,6 +33,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackDriverLoader.h"
#include "jslist.h"
#include "JackError.h"
#include "JackTools.h"
#include "shm.h"
#include "jack.h"
......@@ -49,12 +50,8 @@ static int temporary = 0;
static int client_timeout = 0; /* msecs; if zero, use period size. */
static int do_unlock = 0;
static JSList* drivers = NULL;
static sigset_t signals;
#define DEFAULT_TMP_DIR "/tmp"
char* jack_tmpdir = DEFAULT_TMP_DIR;
static void silent_jack_error_callback(const char *desc)
{}
......@@ -137,107 +134,6 @@ static void FilterSIGPIPE()
pthread_sigmask(SIG_BLOCK, &set, 0);
}
static char* jack_default_server_name(void)
{
char* server_name;
if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
server_name = "default";
return server_name;
}
/* returns the name of the per-user subdirectory of jack_tmpdir */
static char* jack_user_dir(void)
{
static char user_dir[PATH_MAX] = "";
/* format the path name on the first call */
if (user_dir[0] == '\0') {
snprintf(user_dir, sizeof(user_dir), "%s/jack-%d",
jack_tmpdir, getuid());
}
return user_dir;
}
/* returns the name of the per-server subdirectory of jack_user_dir() */
static char* get_jack_server_dir(const char* toto)
{
static char server_dir[PATH_MAX] = "";
// format the path name on the first call
if (server_dir[0] == '\0') {
snprintf(server_dir, sizeof(server_dir), "%s/%s",
jack_user_dir(), server_name);
}
return server_dir;
}
static void
jack_cleanup_files(const char *server_name)
{
DIR *dir;
struct dirent *dirent;
char *dir_name = get_jack_server_dir(server_name);
/* On termination, we remove all files that jackd creates so
* subsequent attempts to start jackd will not believe that an
* instance is already running. If the server crashes or is
* terminated with SIGKILL, this is not possible. So, cleanup
* is also attempted when jackd starts.
*
* There are several tricky issues. First, the previous JACK
* server may have run for a different user ID, so its files
* may be inaccessible. This is handled by using a separate
* JACK_TMP_DIR subdirectory for each user. Second, there may
* be other servers running with different names. Each gets
* its own subdirectory within the per-user directory. The
* current process has already registered as `server_name', so
* we know there is no other server actively using that name.
*/
/* nothing to do if the server directory does not exist */
if ((dir = opendir(dir_name)) == NULL) {
return ;
}
/* unlink all the files in this directory, they are mine */
while ((dirent = readdir(dir)) != NULL) {
char fullpath[PATH_MAX];
if ((strcmp(dirent->d_name, ".") == 0)
|| (strcmp(dirent->d_name, "..") == 0)) {
continue;
}
snprintf(fullpath, sizeof(fullpath), "%s/%s",
dir_name, dirent->d_name);
if (unlink(fullpath)) {
jack_error("cannot unlink `%s' (%s)", fullpath,
strerror(errno));
}
}
closedir(dir);
/* now, delete the per-server subdirectory, itself */
if (rmdir(dir_name)) {
jack_error("cannot remove `%s' (%s)", dir_name,
strerror(errno));
}
/* finally, delete the per-user subdirectory, if empty */
if (rmdir(jack_user_dir())) {
if (errno != ENOTEMPTY) {
jack_error("cannot remove `%s' (%s)",
jack_user_dir(), strerror(errno));
}
}
}
int main(int argc, char* argv[])
{
int sig;
......@@ -407,7 +303,7 @@ int main(int argc, char* argv[])
}
if (server_name == NULL)
server_name = jack_default_server_name();
server_name = JackTools::DefaultServerName();
copyright(stdout);
......@@ -430,7 +326,7 @@ int main(int argc, char* argv[])
/* clean up shared memory and files from any previous
* instance of this server name */
jack_cleanup_shm();
jack_cleanup_files(server_name);
JackTools::CleanupFiles(server_name);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
......@@ -518,7 +414,7 @@ int main(int argc, char* argv[])
JackStop();
jack_cleanup_shm();
jack_cleanup_files(server_name);
JackTools::CleanupFiles(server_name);
jack_unregister_server(server_name);
return 1;
......
This diff is collapsed.
......@@ -1561,7 +1561,7 @@ int main (int argc, char *argv[])
jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
jack_connect(client1, outports[0], jack_port_name(input_port1));
jack_connect(client2, jack_port_name(output_port2), inports[0]);
jack_port_set_latency (output_port2, 256);
jack_port_set_latency(output_port2, 256);
jack_recompute_total_latencies(client1);
if ((jack_port_get_latency (output_port1) != 0) ||
......@@ -1577,12 +1577,12 @@ int main (int argc, char *argv[])
printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency (output_port1) );
printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
printf("!!! get_latency(PHY[0]) : %i (must be external latency : %i)\n", jack_port_get_latency (jack_port_by_name(client1, inports[0])), ext_latency);
printf("!!! get_latency(PHY[0]) : %i (must be external latency : %i)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])), ext_latency);
printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) , (ext_latency + 256));
printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (ext_latency + 256));
printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), ext_latency);
printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency (jack_port_by_name(client1, outports[0])), ext_latency);
printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), ext_latency);
printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])), ext_latency);
} else {
......@@ -1594,10 +1594,10 @@ int main (int argc, char *argv[])
jack_port_disconnect(client1, input_port1);
jack_port_disconnect(client1, input_port2);
Log("Checking a parallel model with 2 clients...\n");
jack_connect(client2, outports[0], jack_port_name(input_port1) );
jack_connect(client2, outports[0], jack_port_name(input_port2) );
jack_connect(client2, jack_port_name(output_port1), inports[0] );
jack_connect(client2, jack_port_name(output_port2), inports[0] );
jack_connect(client2, outports[0], jack_port_name(input_port1));
jack_connect(client2, outports[0], jack_port_name(input_port2));
jack_connect(client2, jack_port_name(output_port1), inports[0]);
jack_connect(client2, jack_port_name(output_port2), inports[0]);
jack_port_set_latency (output_port1, 256);
jack_port_set_latency (output_port2, 512);
jack_recompute_total_latencies(client1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment