Skip to content

Commit

Permalink
vcap/rtsp: create fallback file in $TMPDIR
Browse files Browse the repository at this point in the history
If running with Firejail, neither /tmp (used by tmpfile()) nor CWD may
be writable so try to create file in $TMPDIR (if defined, otherwise
there a default).

+ modified get_temp_file() opened file mode to be readable
  • Loading branch information
MartinPulec committed Oct 31, 2024
1 parent 351b056 commit 8b33b1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ FILE *get_temp_file(const char **filename) {
static _Thread_local char filename_buf[MAX_PATH_SIZE];
#ifdef _WIN32
char *fname = tmpnam(filename_buf);
FILE *ret = fopen(fname, "wbx");
FILE *ret = fopen(fname, "w+bx");
if (ret == NULL) {
return NULL;
}
Expand All @@ -166,7 +166,7 @@ FILE *get_temp_file(const char **filename) {
if (fd == -1) {
return NULL;
};
FILE *ret = fdopen(fd, "wb");
FILE *ret = fdopen(fd, "w+b");
if (ret == NULL) {
return NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion src/video_capture/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "rtp/rtpdec_state.h"
#include "rtsp/rtsp_utils.h"
#include "utils/color_out.h" // for color_printf, TBOLD
#include "utils/fs.h" // for get_temp_file
#include "utils/macros.h" // for MIN, STR_LEN
#include "utils/sdp.h" // for get_video_codec_from_pt_rtpmap
#include "utils/text.h" // base64_decode
Expand Down Expand Up @@ -845,7 +846,7 @@ init_rtsp(struct rtsp_state *s) {
int port = s->vrtsp_state.port;
FILE *sdp_file = tmpfile();
if (sdp_file == NULL) {
sdp_file = fopen("rtsp.sdp", "w+");
sdp_file = get_temp_file(NULL);
if (sdp_file == NULL) {
perror("Creating SDP file");
goto error;
Expand Down

0 comments on commit 8b33b1e

Please sign in to comment.