]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Maik Broemme <mbroemme@plusserver.de>
authorJaroslav Kysela <perex@perex.cz>
Sun, 7 Dec 2003 09:30:47 +0000 (09:30 +0000)
committerJaroslav Kysela <perex@perex.cz>
Sun, 7 Dec 2003 09:30:47 +0000 (09:30 +0000)
- added ipc_perm for dmix plugin
Jaroslav Kysela <perex@suse.cz>
- added ipc_perm for dsnoop and dshare plugins
- added ipc_perm to doc/asoundrc.txt

doc/asoundrc.txt
src/pcm/pcm_direct.c
src/pcm/pcm_direct.h
src/pcm/pcm_dmix.c
src/pcm/pcm_dshare.c
src/pcm/pcm_dsnoop.c

index 41e41959ccc9fb3347405045090b8ed9f90ea6cc..8c762da3581ba00a21bf0c73aa38b820eb35f98d 100644 (file)
@@ -317,6 +317,7 @@ pcm.NAME {
   type dmix            # Direct mixing plugin
   slave STR            # Slave name (see pcm_slave)
   ipc_key INT          # Unique ipc key
+  ipc_perm INT         # ipc permissions (default 0600)
   ipc_key_add_uid BOOL  # Add current uid to ipc_key
   bindings {           # Bindings table
     N INT              # Slave channel for client channel N
@@ -325,6 +326,7 @@ pcm.NAME {
   type dsnoop          # Direct snoop (split one capture stream to more)
   slave STR            # Slave name (see pcm_slave)
   ipc_key INT          # Unique ipc key
+  ipc_perm INT         # ipc permissions (default 0600)
   ipc_key_add_uid BOOL  # Add current uid to ipc_key
   bindings {           # Bindings table
     N INT              # Slave channel for client channel N
@@ -333,6 +335,7 @@ pcm.NAME {
   type dshare          # Share channels from one stream
   slave STR            # Slave name (see pcm_slave)
   ipc_key INT          # Unique ipc key
+  ipc_perm INT         # ipc permissions (default 0600)
   ipc_key_add_uid BOOL  # Add current uid to ipc_key
   bindings {           # Bindings table
     N INT              # Slave channel for client channel N
index 32ede1bb29955b6534d928a7f1e611a19405f6ad..e052476b6569ddfb5457eacb98b03eaa65239bb6 100644 (file)
@@ -39,6 +39,7 @@
 #include <sys/sem.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/un.h>
 #include <sys/mman.h>
 #include "pcm_direct.h"
@@ -157,7 +158,7 @@ static int get_tmp_name(char *filename, size_t size)
        return 0;
 }
 
-static int make_local_socket(const char *filename, int server)
+static int make_local_socket(const char *filename, int server, mode_t ipc_perm)
 {
        size_t l = strlen(filename);
        size_t size = offsetof(struct sockaddr_un, sun_path) + l;
@@ -181,6 +182,12 @@ static int make_local_socket(const char *filename, int server)
                        int result = -errno;
                        SYSERR("bind failed");
                        return result;
+               } else {
+                       if (chmod(filename, ipc_perm) < 0) {
+                               int result = -errno;
+                               SYSERR("chmod failed");
+                               return result;
+                       }
                }
        } else {
                if (connect(sock, (struct sockaddr *) addr, size) < 0) {
@@ -297,7 +304,7 @@ int snd_pcm_direct_server_create(snd_pcm_direct_t *dmix)
        if (ret < 0)
                return ret;
        
-       ret = make_local_socket(dmix->shmptr->socket_name, 1);
+       ret = make_local_socket(dmix->shmptr->socket_name, 1, dmix->ipc_perm);
        if (ret < 0)
                return ret;
        dmix->server_fd = ret;
@@ -349,7 +356,7 @@ int snd_pcm_direct_client_connect(snd_pcm_direct_t *dmix)
        int ret;
        unsigned char buf;
 
-       ret = make_local_socket(dmix->shmptr->socket_name, 0);
+       ret = make_local_socket(dmix->shmptr->socket_name, 0, dmix->ipc_perm);
        if (ret < 0)
                return ret;
        dmix->comm_fd = ret;
index 39c4349df7558156fe9cc23bfd3f868f64a53f26..412d793a6c7098ccceec99abb393d6922b464c9f 100644 (file)
@@ -79,6 +79,7 @@ typedef struct snd_pcm_direct snd_pcm_direct_t;
 struct snd_pcm_direct {
        snd_pcm_type_t type;            /* type (dmix, dsnoop, dshare) */
        key_t ipc_key;                  /* IPC key for semaphore and memory */
+       mode_t ipc_perm;                /* IPC socket permissions */
        int semid;                      /* IPC global semaphore identification */
        int shmid;                      /* IPC global shared memory identification */
        snd_pcm_direct_share_t *shmptr; /* pointer to shared memory area */
index b6d76c8dce30f885ef8c1cb56344b81019c7d735..e27e7b1915ba590b0b445b4f52d22b3d91823a8b 100644 (file)
@@ -33,6 +33,7 @@
 #include <signal.h>
 #include <string.h>
 #include <fcntl.h>
+#include <ctype.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/shm.h>
@@ -732,6 +733,7 @@ static snd_pcm_fast_ops_t snd_pcm_dmix_fast_ops = {
  * \param pcmp Returns created PCM handle
  * \param name Name of PCM
  * \param ipc_key IPC key for semaphore and shared memory
+ * \param ipc_perm IPC permissions for semaphore and shared memory
  * \param params Parameters for slave
  * \param root Configuration root
  * \param sconf Slave configuration
@@ -743,7 +745,8 @@ static snd_pcm_fast_ops_t snd_pcm_dmix_fast_ops = {
  *          changed in future.
  */
 int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
-                     key_t ipc_key, struct slave_params *params,
+                     key_t ipc_key, mode_t ipc_perm,
+                     struct slave_params *params,
                      snd_config_t *bindings,
                      snd_config_t *root, snd_config_t *sconf,
                      snd_pcm_stream_t stream, int mode)
@@ -771,6 +774,7 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
                goto _err;
        
        dmix->ipc_key = ipc_key;
+       dmix->ipc_perm = ipc_perm;
        dmix->semid = -1;
        dmix->shmid = -1;
 
@@ -1056,6 +1060,7 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
        struct slave_params params;
        int bsize, psize, ipc_key_add_uid = 0;
        key_t ipc_key = 0;
+       mode_t ipc_perm = 0600;
        int err;
        snd_config_for_each(i, next, conf) {
                snd_config_t *n = snd_config_iterator_entry(i);
@@ -1074,6 +1079,21 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
                        ipc_key = key;
                        continue;
                }
+               if (strcmp(id, "ipc_perm") == 0) {
+                       char *perm;
+                       char *endp;
+                       err = snd_config_get_ascii(n, &perm);
+                       if (err < 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return err;
+                       }
+                       if (isdigit(*perm) == 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return -EINVAL;
+                       }
+                       ipc_perm = strtol(perm, &endp, 8);
+                       continue;
+               }
                if (strcmp(id, "ipc_key_add_uid") == 0) {
                        char *tmp;
                        err = snd_config_get_ascii(n, &tmp);
@@ -1135,7 +1155,7 @@ int _snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
        params.period_size = psize;
        params.buffer_size = bsize;
 
-       err = snd_pcm_dmix_open(pcmp, name, ipc_key, &params, bindings, root, sconf, stream, mode);
+       err = snd_pcm_dmix_open(pcmp, name, ipc_key, ipc_perm, &params, bindings, root, sconf, stream, mode);
        if (err < 0)
                snd_config_delete(sconf);
        return err;
index f49a6a2ae5bffb321aed0d87d5d66d5cb2d49315..c4ac12057179392aaf7d6e42bd4797cd914b88ef 100644 (file)
@@ -33,6 +33,7 @@
 #include <signal.h>
 #include <string.h>
 #include <fcntl.h>
+#include <ctype.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/shm.h>
@@ -482,6 +483,7 @@ static snd_pcm_fast_ops_t snd_pcm_dshare_fast_ops = {
  * \param pcmp Returns created PCM handle
  * \param name Name of PCM
  * \param ipc_key IPC key for semaphore and shared memory
+ * \param ipc_mode IPC permissions for semaphore and shared memory
  * \param params Parameters for slave
  * \param root Configuration root
  * \param sconf Slave configuration
@@ -493,10 +495,11 @@ static snd_pcm_fast_ops_t snd_pcm_dshare_fast_ops = {
  *          changed in future.
  */
 int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
-                     key_t ipc_key, struct slave_params *params,
-                     snd_config_t *bindings,
-                     snd_config_t *root, snd_config_t *sconf,
-                     snd_pcm_stream_t stream, int mode)
+                       key_t ipc_key, mode_t ipc_perm,
+                       struct slave_params *params,
+                       snd_config_t *bindings,
+                       snd_config_t *root, snd_config_t *sconf,
+                       snd_pcm_stream_t stream, int mode)
 {
        snd_pcm_t *pcm = NULL, *spcm = NULL;
        snd_pcm_direct_t *dshare = NULL;
@@ -528,6 +531,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
        }
        
        dshare->ipc_key = ipc_key;
+       dshare->ipc_perm = ipc_perm;
        dshare->semid = -1;
        dshare->shmid = -1;
 
@@ -745,6 +749,8 @@ int _snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
        struct slave_params params;
        int bsize, psize, ipc_key_add_uid = 0;
        key_t ipc_key = 0;
+       mode_t ipc_perm = 0600;
+       
        int err;
        snd_config_for_each(i, next, conf) {
                snd_config_t *n = snd_config_iterator_entry(i);
@@ -763,6 +769,21 @@ int _snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
                        ipc_key = key;
                        continue;
                }
+               if (strcmp(id, "ipc_perm") == 0) {
+                       char *perm;
+                       char *endp;
+                       err = snd_config_get_ascii(n, &perm);
+                       if (err < 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return err;
+                       }
+                       if (isdigit(*perm) == 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return -EINVAL;
+                       }
+                       ipc_perm = strtol(perm, &endp, 8);
+                       continue;
+               }
                if (strcmp(id, "ipc_key_add_uid") == 0) {
                        char *tmp;
                        err = snd_config_get_ascii(n, &tmp);
@@ -822,7 +843,7 @@ int _snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
 
        params.period_size = psize;
        params.buffer_size = bsize;
-       err = snd_pcm_dshare_open(pcmp, name, ipc_key, &params, bindings, root, sconf, stream, mode);
+       err = snd_pcm_dshare_open(pcmp, name, ipc_key, ipc_perm, &params, bindings, root, sconf, stream, mode);
        if (err < 0)
                snd_config_delete(sconf);
        return err;
index 6571f6021abcb8d7a4987d8977dfe9c97d7b3d07..df428154d4d938c534fe633c88fce931643aa3cc 100644 (file)
@@ -33,6 +33,7 @@
 #include <signal.h>
 #include <string.h>
 #include <fcntl.h>
+#include <ctype.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/shm.h>
@@ -450,6 +451,7 @@ static snd_pcm_fast_ops_t snd_pcm_dsnoop_fast_ops = {
  * \param pcmp Returns created PCM handle
  * \param name Name of PCM
  * \param ipc_key IPC key for semaphore and shared memory
+ * \param ipc_perm IPC permissions for semaphore and shared memory
  * \param params Parameters for slave
  * \param root Configuration root
  * \param sconf Slave configuration
@@ -461,10 +463,11 @@ static snd_pcm_fast_ops_t snd_pcm_dsnoop_fast_ops = {
  *          changed in future.
  */
 int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
-                     key_t ipc_key, struct slave_params *params,
-                     snd_config_t *bindings,
-                     snd_config_t *root, snd_config_t *sconf,
-                     snd_pcm_stream_t stream, int mode)
+                       key_t ipc_key, mode_t ipc_perm,
+                       struct slave_params *params,
+                       snd_config_t *bindings,
+                       snd_config_t *root, snd_config_t *sconf,
+                       snd_pcm_stream_t stream, int mode)
 {
        snd_pcm_t *pcm = NULL, *spcm = NULL;
        snd_pcm_direct_t *dsnoop = NULL;
@@ -488,6 +491,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
                goto _err;
        
        dsnoop->ipc_key = ipc_key;
+       dsnoop->ipc_perm = ipc_perm;
        dsnoop->semid = -1;
        dsnoop->shmid = -1;
 
@@ -695,7 +699,9 @@ int _snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
        struct slave_params params;
        int bsize, psize, ipc_key_add_uid = 0;
        key_t ipc_key = 0;
+       mode_t ipc_perm = 0600;
        int err;
+
        snd_config_for_each(i, next, conf) {
                snd_config_t *n = snd_config_iterator_entry(i);
                const char *id;
@@ -713,6 +719,21 @@ int _snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
                        ipc_key = key;
                        continue;
                }
+               if (strcmp(id, "ipc_perm") == 0) {
+                       char *perm;
+                       char *endp;
+                       err = snd_config_get_ascii(n, &perm);
+                       if (err < 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return err;
+                       }
+                       if (isdigit(*perm) == 0) {
+                               SNDERR("The field ipc_perm must be a valid file permission");
+                               return -EINVAL;
+                       }
+                       ipc_perm = strtol(perm, &endp, 8);
+                       continue;
+               }
                if (strcmp(id, "ipc_key_add_uid") == 0) {
                        char *tmp;
                        err = snd_config_get_ascii(n, &tmp);
@@ -780,7 +801,7 @@ int _snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
 
        params.period_size = psize;
        params.buffer_size = bsize;
-       err = snd_pcm_dsnoop_open(pcmp, name, ipc_key, &params, bindings, root, sconf, stream, mode);
+       err = snd_pcm_dsnoop_open(pcmp, name, ipc_key, ipc_perm, &params, bindings, root, sconf, stream, mode);
        if (err < 0)
                snd_config_delete(sconf);
        return err;