summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/JackPosixSemaphore.cpp22
-rw-r--r--posix/JackPosixSemaphore.h7
-rw-r--r--posix/JackSocket.cpp28
-rw-r--r--posix/JackSocket.h10
4 files changed, 55 insertions, 12 deletions
diff --git a/posix/JackPosixSemaphore.cpp b/posix/JackPosixSemaphore.cpp
index 9e511647..1f4df7a4 100644
--- a/posix/JackPosixSemaphore.cpp
+++ b/posix/JackPosixSemaphore.cpp
@@ -24,10 +24,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
+#ifdef __linux__
+#include "promiscuous.h"
+#endif
namespace Jack
{
+JackPosixSemaphore::JackPosixSemaphore() : JackSynchro(), fSemaphore(NULL)
+{
+ const char* promiscuous = getenv("JACK_PROMISCUOUS_SERVER");
+ fPromiscuous = (promiscuous != NULL);
+#ifdef __linux__
+ fPromiscuousGid = jack_group2gid(promiscuous);
+#endif
+}
+
void JackPosixSemaphore::BuildName(const char* client_name, const char* server_name, char* res, int size)
{
char ext_client_name[SYNC_MAX_NAME_SIZE + 1];
@@ -35,7 +47,7 @@ void JackPosixSemaphore::BuildName(const char* client_name, const char* server_n
#if __APPLE__ // POSIX semaphore names are limited to 32 characters...
snprintf(res, 32, "js_%s", ext_client_name);
#else
- if (getenv("JACK_PROMISCUOUS_SERVER")) {
+ if (fPromiscuous) {
snprintf(res, size, "jack_sem.%s_%s", server_name, ext_client_name);
} else {
snprintf(res, size, "jack_sem.%d_%s_%s", JackTools::GetUID(), server_name, ext_client_name);
@@ -147,6 +159,14 @@ bool JackPosixSemaphore::Allocate(const char* name, const char* server_name, int
jack_error("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno));
return false;
} else {
+#ifdef __linux__
+ if (fPromiscuous) {
+ char sempath[SYNC_MAX_NAME_SIZE+13];
+ snprintf(sempath, sizeof(sempath), "/dev/shm/sem.%s", fName);
+ if (jack_promiscuous_perms(-1, sempath, fPromiscuousGid) < 0)
+ return false;
+ }
+#endif
return true;
}
}
diff --git a/posix/JackPosixSemaphore.h b/posix/JackPosixSemaphore.h
index 94f4d60f..bc5e0cea 100644
--- a/posix/JackPosixSemaphore.h
+++ b/posix/JackPosixSemaphore.h
@@ -39,6 +39,10 @@ class SERVER_EXPORT JackPosixSemaphore : public detail::JackSynchro
private:
sem_t* fSemaphore;
+ bool fPromiscuous;
+#ifdef __linux__
+ int fPromiscuousGid;
+#endif
protected:
@@ -46,8 +50,7 @@ class SERVER_EXPORT JackPosixSemaphore : public detail::JackSynchro
public:
- JackPosixSemaphore():JackSynchro(), fSemaphore(NULL)
- {}
+ JackPosixSemaphore();
bool Signal();
bool SignalAll();
diff --git a/posix/JackSocket.cpp b/posix/JackSocket.cpp
index e8b528d9..73f1fc44 100644
--- a/posix/JackSocket.cpp
+++ b/posix/JackSocket.cpp
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackConstants.h"
#include "JackTools.h"
#include "JackError.h"
+#include "promiscuous.h"
#include <string.h>
#include <stdio.h>
#include <pthread.h>
@@ -29,18 +30,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{
-static void BuildName(const char* client_name, char* res, const char* dir, int which, int size)
+static void BuildName(const char* client_name, char* res, const char* dir, int which, int size, bool promiscuous)
{
char ext_client_name[SYNC_MAX_NAME_SIZE + 1];
JackTools::RewriteName(client_name, ext_client_name);
- if (getenv("JACK_PROMISCUOUS_SERVER")) {
+ if (promiscuous) {
snprintf(res, size, "%s/jack_%s_%d", dir, ext_client_name, which);
} else {
snprintf(res, size, "%s/jack_%s_%d_%d", dir, ext_client_name, JackTools::GetUID(), which);
}
}
-JackClientSocket::JackClientSocket(int socket): JackClientRequestInterface(), fSocket(socket),fTimeOut(0)
+JackClientSocket::JackClientSocket(): JackClientRequestInterface(), fSocket(-1), fTimeOut(0)
+{
+ const char* promiscuous = getenv("JACK_PROMISCUOUS_SERVER");
+ fPromiscuous = (promiscuous != NULL);
+ fPromiscuousGid = jack_group2gid(promiscuous);
+}
+
+JackClientSocket::JackClientSocket(int socket): JackClientRequestInterface(), fSocket(socket),fTimeOut(0), fPromiscuous(false), fPromiscuousGid(-1)
{}
#if defined(__sun__) || defined(sun)
@@ -123,7 +131,7 @@ int JackClientSocket::Connect(const char* dir, const char* name, int which) // A
}
addr.sun_family = AF_UNIX;
- BuildName(name, addr.sun_path, dir, which, sizeof(addr.sun_path));
+ BuildName(name, addr.sun_path, dir, which, sizeof(addr.sun_path), fPromiscuous);
jack_log("JackClientSocket::Connect : addr.sun_path %s", addr.sun_path);
if (connect(fSocket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
@@ -247,6 +255,13 @@ int JackClientSocket::Write(void* data, int len)
}
}
+JackServerSocket::JackServerSocket(): fSocket( -1)
+{
+ const char* promiscuous = getenv("JACK_PROMISCUOUS_SERVER");
+ fPromiscuous = (promiscuous != NULL);
+ fPromiscuousGid = jack_group2gid(promiscuous);
+}
+
int JackServerSocket::Bind(const char* dir, const char* name, int which) // A revoir : utilisation de "which"
{
struct sockaddr_un addr;
@@ -258,7 +273,7 @@ int JackServerSocket::Bind(const char* dir, const char* name, int which) // A re
addr.sun_family = AF_UNIX;
// Socket name has to be kept in fName to be "unlinked".
- BuildName(name, fName, dir, which, sizeof(addr.sun_path));
+ BuildName(name, fName, dir, which, sizeof(addr.sun_path), fPromiscuous);
strncpy(addr.sun_path, fName, sizeof(addr.sun_path) - 1);
jack_log("JackServerSocket::Bind : addr.sun_path %s", addr.sun_path);
@@ -274,6 +289,9 @@ int JackServerSocket::Bind(const char* dir, const char* name, int which) // A re
goto error;
}
+ if (fPromiscuous && (jack_promiscuous_perms(-1, fName, fPromiscuousGid) < 0))
+ goto error;
+
return 0;
error:
diff --git a/posix/JackSocket.h b/posix/JackSocket.h
index 8568025b..5f0501a1 100644
--- a/posix/JackSocket.h
+++ b/posix/JackSocket.h
@@ -45,11 +45,12 @@ class JackClientSocket : public detail::JackClientRequestInterface
int fSocket;
int fTimeOut;
+ bool fPromiscuous;
+ int fPromiscuousGid;
public:
- JackClientSocket():JackClientRequestInterface(), fSocket(-1), fTimeOut(0)
- {}
+ JackClientSocket();
JackClientSocket(int socket);
int Connect(const char* dir, const char* name, int which);
@@ -80,11 +81,12 @@ class JackServerSocket
int fSocket;
char fName[SOCKET_MAX_NAME_SIZE];
+ bool fPromiscuous;
+ int fPromiscuousGid;
public:
- JackServerSocket(): fSocket( -1)
- {}
+ JackServerSocket();
~JackServerSocket()
{}