Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell expansion and parameters with spaces in ts-exec:, mkv-exec, JPEG, etc. #172

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/procs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ std::string Util::Procs::getOutputOf(std::deque<std::string> &argDeq, uint64_t m
return ret;
}

pid_t Util::Procs::StartPipedShell(const char *cmd, int *fdin, int *fdout, int *fderr){
const char *argv[] = {
#if defined(__CYGWIN__) || defined(_WIN32)
"cmd",
"/C",
#else
"/usr/bin/sh",
"-c",
#endif
cmd,
NULL
};
pid_t ret = Util::Procs::StartPiped(argv, fdin, fdout, fderr);
return ret;
}

pid_t Util::Procs::StartPiped(std::deque<std::string> &argDeq, int *fdin, int *fdout, int *fderr){
pid_t ret;
char *const *argv = dequeToArgv(argDeq); // Note: Do not edit deque before executing command
Expand Down
1 change: 1 addition & 0 deletions lib/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Util{
static std::string getLimitedOutputOf(char *const *argv, uint64_t maxWait, uint32_t maxValBytes);
static pid_t StartPiped(const char *const *argv, int *fdin, int *fdout, int *fderr);
static pid_t StartPiped(std::deque<std::string> &argDeq, int *fdin, int *fdout, int *fderr);
static pid_t StartPipedShell(const char *cmd, int *fdin, int *fdout, int *fderr);
static void Stop(pid_t name);
static void Murder(pid_t name);
static void StopAll();
Expand Down
22 changes: 1 addition & 21 deletions src/input/input_ebml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,8 @@ namespace Mist{
if (config->getString("input").substr(0, 9) == "mkv-exec:"){
standAlone = false;
std::string input = config->getString("input").substr(9);
char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = (char *)input.c_str(); i <= input.data() + input.size(); ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

int fin = -1, fout = -1;
Util::Procs::StartPiped(args, &fin, &fout, 0);
Util::Procs::StartPipedShell(input.c_str(), &fin, &fout, 0);
if (fout == -1){return false;}
dup2(fout, 0);
inFile.open(0);
Expand Down
23 changes: 1 addition & 22 deletions src/input/input_h264.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,8 @@ namespace Mist{
if (config->getString("input") != "-"){
std::string input = config->getString("input");
input = input.substr(10);

char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = (char *)input.c_str(); i <= input.data() + input.size(); ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

int fin = -1, fout = -1;
inputProcess = Util::Procs::StartPiped(args, &fin, &fout, 0);
inputProcess = Util::Procs::StartPipedShell(input.c_str(), &fin, &fout, 0);
myConn.open(-1, fout);
}else{
myConn.open(fileno(stdout), fileno(stdin));
Expand Down
21 changes: 1 addition & 20 deletions src/input/input_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,28 +322,9 @@ namespace Mist{
standAlone = false;
if (skipPipes){return true;}
std::string input = inCfg.substr(8);
char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = (char *)input.c_str(); i <= input.data() + input.size(); ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

int fin = -1, fout = -1;
inputProcess = Util::Procs::StartPiped(args, &fin, &fout, 0);
inputProcess = Util::Procs::StartPipedShell(input.c_str(), &fin, &fout, 0);
reader.open(fout);
return reader;
}
Expand Down
22 changes: 1 addition & 21 deletions src/output/output_ebml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,8 @@ namespace Mist{
if (config->getString("target").size()){
if (config->getString("target").substr(0, 9) == "mkv-exec:"){
std::string input = config->getString("target").substr(9);
char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = (char *)input.c_str(); i <= input.data() + input.size(); ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

int fin = -1;
Util::Procs::StartPiped(args, &fin, 0, 0);
Util::Procs::StartPipedShell(input.c_str(), &fin, 0, 0);
myConn.open(fin, -1);

wantRequest = false;
Expand Down
22 changes: 1 addition & 21 deletions src/output/output_httpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,8 @@ namespace Mist{
}
if (config->getString("target").substr(0, 8) == "ts-exec:"){
std::string input = config->getString("target").substr(8);
char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = (char *)input.c_str(); i <= input.data() + input.size(); ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

int fin = -1;
Util::Procs::StartPiped(args, &fin, 0, 0);
Util::Procs::StartPipedShell(input.c_str(), &fin, 0, 0);
myConn.open(fin, -1);

wantRequest = false;
Expand Down
24 changes: 2 additions & 22 deletions src/output/output_jpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,8 @@ namespace Mist{
(Util::printDebugLevel >= DLVL_MEDIUM ? "" : "-v quiet"),
config->getString("ffopts").c_str());

HIGH_MSG("Starting JPG command: %s", ffcmd);
char *args[128];
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = ffcmd; i - ffcmd < 256; ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

ffmpeg = Util::Procs::StartPiped(args, &fin, &fout, &ferr);
HIGH_MSG("Starting JPG command: %s", ffcmd);
ffmpeg = Util::Procs::StartPipedShell(ffcmd, &fin, &fout, &ferr);
if (ffmpeg < 2){
Socket::Connection failure(fin, fout);
failure.close();
Expand Down
22 changes: 1 addition & 21 deletions src/process/process_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,7 @@ namespace Mist{
char exec_cmd[10240];
strncpy(exec_cmd, tmpCmd.c_str(), 10240);
INFO_MSG("Executing command: %s", exec_cmd);
uint8_t argCnt = 0;
char *startCh = 0;
char *args[1280];
for (char *i = exec_cmd; i - exec_cmd < 10240; ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;

execd_proc = Util::Procs::StartPiped(args, &pipein[0], &pipeout[1], &ffer);
execd_proc = Util::Procs::StartPipedShell(exec_cmd, &pipein[0], &pipeout[1], &ffer);

uint64_t lastProcUpdate = Util::bootSecs();
{
Expand Down
28 changes: 2 additions & 26 deletions src/process/process_ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,30 +835,6 @@ namespace Mist{
return false;
}

/// prepare ffmpeg command by splitting the arguments before running
void OutENC::prepareCommand(){
// ffmpeg command
MEDIUM_MSG("ffmpeg command: %s", ffcmd);
uint8_t argCnt = 0;
char *startCh = 0;
for (char *i = ffcmd; i - ffcmd < 10240; ++i){
if (!*i){
if (startCh){args[argCnt++] = startCh;}
break;
}
if (*i == ' '){
if (startCh){
args[argCnt++] = startCh;
startCh = 0;
*i = 0;
}
}else{
if (!startCh){startCh = i;}
}
}
args[argCnt] = 0;
}

void OutENC::setResolution(uint32_t x, uint32_t y){
res_x = x;
res_y = y;
Expand All @@ -885,8 +861,8 @@ namespace Mist{
}
}

prepareCommand();
ffout = p.StartPiped(args, &pipein[0], &pipeout[1], &ffer);
MEDIUM_MSG("ffmpeg command: %s", ffcmd);
ffout = p.StartPipedShell(ffcmd, &pipein[0], &pipeout[1], &ffer);

while (conf.is_active && p.isRunning(ffout)){Util::sleep(200);}

Expand Down
1 change: 0 additions & 1 deletion src/process/process_ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace Mist{
bool checkAudioConfig();
bool buildVideoCommand();
bool buildAudioCommand();
void prepareCommand();
std::set<std::string> supportedVideoCodecs;
std::set<std::string> supportedAudioCodecs;
};
Expand Down