Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
muxer/makedirs: fix mode (ulimit) - fixes #2969
  • Loading branch information
perexg committed Jun 24, 2015
1 parent 8cc9b71 commit d2cf4dd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/muxer/muxer_libav.c
Expand Up @@ -18,6 +18,7 @@

#include <assert.h>
#include <unistd.h>
#include <sys/stat.h>
#include <libavformat/avformat.h>
#include <libavutil/mathematics.h>

Expand Down Expand Up @@ -354,16 +355,24 @@ lav_muxer_open_file(muxer_t *m, const char *filename)
{
AVFormatContext *oc;
lav_muxer_t *lm = (lav_muxer_t*)m;
char buf[256];
int r;

oc = lm->lm_oc;
snprintf(oc->filename, sizeof(oc->filename), "%s", filename);

if(avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) {
tvhlog(LOG_ERR, "libav", "Could not open %s", filename);
if((r = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
av_strerror(r, buf, sizeof(buf));
tvhlog(LOG_ERR, "libav", "%s: Could not open -- %s", filename, buf);
lm->m_errors++;
return -1;
}

/* bypass umask settings */
if (chmod(filename, lm->m_config.m_file_permissions))
tvhlog(LOG_ERR, "libav", "%s: Unable to change permissions -- %s",
filename, strerror(errno));

return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/muxer/muxer_pass.c
Expand Up @@ -20,6 +20,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/stat.h>

#include "tvheadend.h"
#include "streaming.h"
Expand Down Expand Up @@ -364,6 +365,11 @@ pass_muxer_open_file(muxer_t *m, const char *filename)
return -1;
}

/* bypass umask settings */
if (fchmod(fd, pm->m_config.m_file_permissions))
tvhlog(LOG_ERR, "pass", "%s: Unable to change permissions -- %s",
filename, strerror(errno));

pm->pm_off = 0;
pm->pm_seekable = 1;
pm->pm_fd = fd;
Expand Down
6 changes: 6 additions & 0 deletions src/muxer/tvh/mkmux.c
Expand Up @@ -1128,6 +1128,12 @@ mk_mux_open_file(mk_mux_t *mkm, const char *filename, int permissions)
return mkm->error;
}

/* bypass umask settings */
if (fchmod(fd, permissions))
tvhlog(LOG_ERR, "mkv", "%s: Unable to change permissions -- %s",
filename, strerror(errno));


mkm->filename = strdup(filename);
mkm->fd = fd;
mkm->cluster_maxsize = 2000000/4;
Expand Down
2 changes: 2 additions & 0 deletions src/utils.c
Expand Up @@ -499,6 +499,8 @@ makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
err = mkdir(path, mode);
if (!err && gid != -1 && uid != -1)
err = chown(path, uid, gid);
if (!err)
err = chmod(path, mode); /* override umode */
tvhtrace("settings", "Creating directory \"%s\" with octal permissions "
"\"%o\" gid %d uid %d", path, mode, gid, uid);
} else {
Expand Down

0 comments on commit d2cf4dd

Please sign in to comment.