summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUladox <uladoxiental@gmail.com>2016-08-14 22:38:28 -1000
committerUladox <uladoxiental@gmail.com>2016-08-14 22:38:28 -1000
commit04a18e8914a1f1c2d5e43bcaeb2fd44b37b9cfe6 (patch)
treea76d31892a6c7a8f1179eecf5b0d01c34349a1e3
parent8a7253575c58134bb33b2b24f10eec7ce7bd051d (diff)
downloadjack1-04a18e8914a1f1c2d5e43bcaeb2fd44b37b9cfe6.tar.gz
Removes use of gloabl jack_tmpdir.
Uses static local variable like how jack_user_dir does. jack_get_tmpdir() replaces jack_tmpdir for the most part except in jackd -l where it would cause an infinite loop, and instead DEFAULT_TMP_DIR is used, which is what it would happen anyway. Also in jack_user_dir the default value is used if jack_user_dir returns NULL from some error, but an error message is printed with jack_error(), this is the same as the old behavior, but I am not sure this is quite what should happen. Still, the exact same behavior as before is acheived except without the use of the jack_tmpdir global and the memory issues caused by calling jack_get_tmpdir().
-rw-r--r--include/internal.h2
-rw-r--r--jackd/engine.c12
-rw-r--r--jackd/jackd.c3
-rw-r--r--libjack/client.c46
4 files changed, 39 insertions, 24 deletions
diff --git a/include/internal.h b/include/internal.h
index 5a14237..e3574bd 100644
--- a/include/internal.h
+++ b/include/internal.h
@@ -509,7 +509,7 @@ extern jack_client_t *jack_client_alloc_internal(jack_client_control_t*,
/* internal clients call this. it's defined in jack/engine.c */
void handle_internal_client_request(jack_control_t*, jack_request_t*);
-extern char *jack_tmpdir;
+extern const char *jack_get_tmpdir(void);
extern char *jack_user_dir(void);
diff --git a/jackd/engine.c b/jackd/engine.c
index c6b2e60..365a29a 100644
--- a/jackd/engine.c
+++ b/jackd/engine.c
@@ -227,16 +227,22 @@ make_socket_subdirectories (const char *server_name)
{
struct stat statbuf;
char server_dir[PATH_MAX + 1] = "";
+ const char *tmpdir = jack_get_tmpdir ();
+
+ if (tmpdir == NULL) {
+ jack_error ("Unable to get tmpdir in engine");
+ return -1;
+ }
/* check tmpdir directory */
- if (stat (jack_tmpdir, &statbuf)) {
+ if (stat (tmpdir, &statbuf)) {
jack_error ("cannot stat() %s (%s)\n",
- jack_tmpdir, strerror (errno));
+ tmpdir, strerror (errno));
return -1;
} else {
if (!S_ISDIR (statbuf.st_mode)) {
jack_error ("%s exists, but is not a directory!\n",
- jack_tmpdir);
+ tmpdir);
return -1;
}
}
diff --git a/jackd/jackd.c b/jackd/jackd.c
index 0faae93..90fb38f 100644
--- a/jackd/jackd.c
+++ b/jackd/jackd.c
@@ -812,7 +812,8 @@ main (int argc, char *argv[])
case 'l':
/* special flag to allow libjack to determine jackd's idea of where tmpdir is */
- printf ("%s\n", jack_tmpdir);
+ printf("%s\n", DEFAULT_TMP_DIR);
+
exit (0);
case 'I':
diff --git a/libjack/client.c b/libjack/client.c
index 34e8b09..7724868 100644
--- a/libjack/client.c
+++ b/libjack/client.c
@@ -119,11 +119,10 @@ init_cpu ()
#endif /* USE_DYNSIMD */
-char *jack_tmpdir = DEFAULT_TMP_DIR;
-
-static int
+const char *
jack_get_tmpdir ()
{
+ static char tmpdir[PATH_MAX + 1] = "";
FILE* in;
size_t len;
char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */
@@ -131,6 +130,11 @@ jack_get_tmpdir ()
char *pathcopy;
char *p;
+ /* return tmpdir if set */
+ if (tmpdir[0] != '\0') {
+ return tmpdir;
+ }
+
/* some implementations of popen(3) close a security loophole by
resetting PATH for the exec'd command. since we *want* to
use the user's PATH setting to locate jackd, we have to
@@ -138,13 +142,13 @@ jack_get_tmpdir ()
*/
if ((pathenv = getenv ("PATH")) == 0) {
- return -1;
+ return NULL;
}
/* don't let strtok(3) mess with the real environment variable */
if ((pathcopy = strdup (pathenv)) == NULL) {
- return -1;
+ return NULL;
}
p = strtok (pathcopy, ":");
@@ -169,13 +173,13 @@ jack_get_tmpdir ()
if (p == NULL) {
/* no command successfully started */
free (pathcopy);
- return -1;
+ return NULL;
}
if (fgets (buf, sizeof(buf), in) == NULL) {
pclose (in);
free (pathcopy);
- return -1;
+ return NULL;
}
len = strlen (buf);
@@ -184,21 +188,16 @@ jack_get_tmpdir ()
/* didn't get a whole line */
pclose (in);
free (pathcopy);
- return -1;
- }
-
- if ((jack_tmpdir = (char*)malloc (len)) == NULL) {
- free (pathcopy);
- return -1;
+ return NULL;
}
- memcpy (jack_tmpdir, buf, len - 1);
- jack_tmpdir[len - 1] = '\0';
+ memcpy (tmpdir, buf, len - 1);
+ tmpdir[len - 1] = '\0';
pclose (in);
free (pathcopy);
- return 0;
+ return tmpdir;
}
void
@@ -1260,7 +1259,7 @@ jack_client_open_aux (const char *client_name,
/* External clients need to know where the tmpdir used for
communication with the server lives
*/
- if (jack_get_tmpdir ()) {
+ if (jack_get_tmpdir () == NULL) {
*status |= JackFailure;
jack_messagebuffer_exit ();
return NULL;
@@ -1458,15 +1457,24 @@ char *
jack_user_dir (void)
{
static char user_dir[PATH_MAX + 1] = "";
+ const char *tmpdir;
/* format the path name on the first call */
if (user_dir[0] == '\0') {
+ tmpdir = jack_get_tmpdir ();
+
+ /* previous behavior of jack_tmpdir, should be changed later */
+ if (tmpdir == NULL) {
+ jack_error ("Unable to get tmpdir in user dir");
+ tmpdir = DEFAULT_TMP_DIR;
+ }
+
if (getenv ("JACK_PROMISCUOUS_SERVER")) {
snprintf (user_dir, sizeof(user_dir), "%s/jack",
- jack_tmpdir);
+ tmpdir);
} else {
snprintf (user_dir, sizeof(user_dir), "%s/jack-%d",
- jack_tmpdir, getuid ());
+ tmpdir, getuid ());
}
}