MCPcopy Create free account
hub / github.com/MaartenBaert/ssr / Init

Method Init

glinject/SSRVideoStreamWriter.cpp:67–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void SSRVideoStreamWriter::Init() {
68
69 GLINJECT_PRINT("[" << m_filename_main << "] Created video stream.");
70
71 bool relax_permissions = false;
72 {
73 char *ssr_stream_relax_permissions = getenv("SSR_STREAM_RELAX_PERMISSIONS");
74 if(ssr_stream_relax_permissions != NULL && atoi(ssr_stream_relax_permissions) > 0) {
75 GLINJECT_PRINT("Warning: Using relaxed file permissions, any user on this machine will be able to read or manipulate the stream!");
76 relax_permissions = true;
77 }
78 }
79
80 // create channel directory (permissions may be wrong because of umask, fix this later)
81 if(mkdir(m_channel_directory.c_str(), (relax_permissions)? 0777 : 0700) == -1) {
82 if(errno != EEXIST) { // does the directory already exist?
83 GLINJECT_PRINT("Error: Can't create channel directory!");
84 throw SSRStreamException();
85 }
86 }
87
88 // check ownership and permissions
89 struct stat statinfo;
90 if(lstat(m_channel_directory.c_str(), &statinfo) == -1) {
91 GLINJECT_PRINT("Error: Can't stat channel directory!");
92 throw SSRStreamException();
93 }
94 if(!S_ISDIR(statinfo.st_mode) || S_ISLNK(statinfo.st_mode)) {
95 GLINJECT_PRINT("Error: Channel directory is not a regular directory!");
96 throw SSRStreamException();
97 }
98 if(statinfo.st_uid == geteuid()) {
99 if(chmod(m_channel_directory.c_str(), (relax_permissions)? 0777 : 0700) == -1) {
100 GLINJECT_PRINT("Error: Can't set channel directory mode!");
101 throw SSRStreamException();
102 }
103 } else {
104 if(!relax_permissions) {
105 GLINJECT_PRINT("Error: Channel directory is owned by a different user! "
106 "Choose a different channel name, or enable relaxed file permissions to use it anyway.");
107 throw SSRStreamException();
108 }
109 }
110
111 // open frame files
112 for(unsigned int i = 0; i < GLINJECT_RING_BUFFER_SIZE; ++i) {
113 FrameData &fd = m_frame_data[i];
114 fd.m_fd_frame = open(fd.m_filename_frame.c_str(), O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, (relax_permissions)? 0666 : 0600);
115 if(fd.m_fd_frame == -1) {
116 GLINJECT_PRINT("Error: Can't open video frame file!");
117 throw SSRStreamException();
118 }
119 if(fchmod(fd.m_fd_frame, (relax_permissions)? 0666 : 0600) == -1) {
120 GLINJECT_PRINT("Error: Can't set video frame file mode!");
121 throw SSRStreamException();
122 }
123 }
124

Callers

nothing calls this directly

Calls 1

SSRStreamExceptionClass · 0.70

Tested by

no test coverage detected