Add perm option

Added "perm" option to file plugin to specify the file permission.
Changed the default permission to 0600.
This commit is contained in:
Takashi Iwai 2005-05-19 13:59:43 +00:00
parent d5b9823447
commit 1cd04dba82

View file

@ -394,7 +394,7 @@ static snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
* changed in future. * changed in future.
*/ */
int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name, int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
const char *fname, int fd, const char *fmt, const char *fname, int fd, const char *fmt, int perm,
snd_pcm_t *slave, int close_slave) snd_pcm_t *slave, int close_slave)
{ {
snd_pcm_t *pcm; snd_pcm_t *pcm;
@ -410,7 +410,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
return -EINVAL; return -EINVAL;
} }
if (fname) { if (fname) {
fd = open(fname, O_WRONLY|O_CREAT, 0666); fd = open(fname, O_WRONLY|O_CREAT, perm);
if (fd < 0) { if (fd < 0) {
SYSERR("open %s failed", fname); SYSERR("open %s failed", fname);
return -errno; return -errno;
@ -470,6 +470,7 @@ pcm.name {
or or
file INT # File descriptor number file INT # File descriptor number
[format STR] # File format (only "raw" at the moment) [format STR] # File format (only "raw" at the moment)
[perm INT] # File permission (octal, default 0600)
} }
\endcode \endcode
@ -506,6 +507,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
const char *fname = NULL; const char *fname = NULL;
const char *format = NULL; const char *format = NULL;
long fd = -1; long fd = -1;
int perm = 0600;
snd_config_for_each(i, next, conf) { snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
const char *id; const char *id;
@ -536,6 +538,21 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
} }
continue; continue;
} }
if (strcmp(id, "perm") == 0) {
char *perm;
char *endp;
err = snd_config_get_ascii(n, &perm);
if (err < 0) {
SNDERR("The field perm must be a valid file permission");
return err;
}
if (isdigit(*perm) == 0) {
SNDERR("The field perm must be a valid file permission");
return -EINVAL;
}
perm = strtol(perm, &endp, 8);
continue;
}
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
return -EINVAL; return -EINVAL;
} }
@ -555,7 +572,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
snd_config_delete(sconf); snd_config_delete(sconf);
if (err < 0) if (err < 0)
return err; return err;
err = snd_pcm_file_open(pcmp, name, fname, fd, format, spcm, 1); err = snd_pcm_file_open(pcmp, name, fname, fd, format, perm, spcm, 1);
if (err < 0) if (err < 0)
snd_pcm_close(spcm); snd_pcm_close(spcm);
return err; return err;