merged the w and u versions of the execmd exerciser
This commit is contained in:
parent
3956d0a867
commit
fcd4a6a3ac
2 changed files with 65 additions and 32 deletions
|
@ -109,8 +109,8 @@ trfileudi.o : fileudi.cpp fileudi.h
|
||||||
EXECMD_OBJS= trexecmd.o
|
EXECMD_OBJS= trexecmd.o
|
||||||
trexecmd : $(EXECMD_OBJS)
|
trexecmd : $(EXECMD_OBJS)
|
||||||
$(CXX) $(ALL_CXXFLAGS) -o trexecmd $(EXECMD_OBJS) $(LIBRECOLL)
|
$(CXX) $(ALL_CXXFLAGS) -o trexecmd $(EXECMD_OBJS) $(LIBRECOLL)
|
||||||
trexecmd.o : execmd.cpp execmd.h
|
trexecmd.o : trexecmd.cpp execmd.h
|
||||||
$(CXX) -o trexecmd.o -c $(ALL_CXXFLAGS) -DTEST_EXECMD execmd.cpp
|
$(CXX) -o trexecmd.o -c $(ALL_CXXFLAGS) -I../xaposix trexecmd.cpp
|
||||||
|
|
||||||
TRANSCODE_OBJS= trtranscode.o
|
TRANSCODE_OBJS= trtranscode.o
|
||||||
transcode : $(TRANSCODE_OBJS)
|
transcode : $(TRANSCODE_OBJS)
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "safeunistd.h"
|
#include "safeunistd.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -27,14 +30,17 @@ using namespace std;
|
||||||
bool exercise_mhexecm(const string& cmdstr, const string& mimetype,
|
bool exercise_mhexecm(const string& cmdstr, const string& mimetype,
|
||||||
vector<string>& files)
|
vector<string>& files)
|
||||||
{
|
{
|
||||||
if (files.empty())
|
if (files.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ExecCmd cmd;
|
ExecCmd cmd;
|
||||||
vector<string> myparams;
|
vector<string> myparams;
|
||||||
// Hack for windows: the command is always "Python somescript"
|
|
||||||
myparams.push_back(files[0]);
|
#ifdef _WIN32
|
||||||
files.erase(files.begin());
|
// Hack for windows: the command is always "Python somescript"
|
||||||
|
myparams.push_back(files[0]);
|
||||||
|
files.erase(files.begin());
|
||||||
|
#endif
|
||||||
|
|
||||||
if (cmd.startExec(cmdstr, myparams, 1, 1) < 0) {
|
if (cmd.startExec(cmdstr, myparams, 1, 1) < 0) {
|
||||||
cerr << "startExec " << cmdstr << " failed. Missing command?\n";
|
cerr << "startExec " << cmdstr << " failed. Missing command?\n";
|
||||||
|
@ -121,17 +127,18 @@ bool exercise_mhexecm(const string& cmdstr, const string& mimetype,
|
||||||
|
|
||||||
static char *thisprog;
|
static char *thisprog;
|
||||||
static char usage [] =
|
static char usage [] =
|
||||||
"trexecmd [-c -r -i -o] cmd [arg1 arg2 ...]\n"
|
"trexecmd [-c -r -i -o] [-e <fn>] cmd [arg1 arg2 ...]\n"
|
||||||
" -c : test cancellation (ie: trexecmd -c sleep 1000)\n"
|
" -c : test cancellation (ie: trexecmd -c sleep 1000)\n"
|
||||||
" -r : run reexec. Must be separate option.\n"
|
" -r : run reexec. Must be separate option.\n"
|
||||||
" -i : command takes input\n"
|
" -i : command takes input\n"
|
||||||
" -o : command produces output\n"
|
" -o : command produces output\n"
|
||||||
" If -i is set, we send /etc/group contents to whatever command is run\n"
|
" -e <fn> : send stderr to file named fn (will truncate it)\n"
|
||||||
" If -o is set, we print whatever comes out\n"
|
" If -i is set, we send /etc/group contents to whatever command is run\n"
|
||||||
"trexecmd -m <filter> <mimetype> <file> [file ...]: test execm:\n"
|
" If -o is set, we print whatever comes out\n"
|
||||||
" <filter> should be the path to an execm filter\n"
|
"trexecmd -m <filter> <mimetype> <file> [file ...]: test execm:\n"
|
||||||
" <mimetype> the type of the file parameters\n"
|
" <filter> should be the path to an execm filter\n"
|
||||||
"trexecmd -w cmd : do the 'which' thing\n"
|
" <mimetype> the type of the file parameters\n"
|
||||||
|
"trexecmd -w cmd : do the 'which' thing\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
static void Usage(FILE *fp = stderr)
|
static void Usage(FILE *fp = stderr)
|
||||||
|
@ -148,6 +155,7 @@ static int op_flags;
|
||||||
#define OPT_r 0x20
|
#define OPT_r 0x20
|
||||||
#define OPT_m 0x40
|
#define OPT_m 0x40
|
||||||
#define OPT_o 0x80
|
#define OPT_o 0x80
|
||||||
|
#define OPT_e 0x100
|
||||||
|
|
||||||
// Data sink for data coming out of the command. We also use it to set
|
// Data sink for data coming out of the command. We also use it to set
|
||||||
// a cancellation after a moment.
|
// a cancellation after a moment.
|
||||||
|
@ -161,7 +169,7 @@ public:
|
||||||
CancelCheck::instance().setCancel();
|
CancelCheck::instance().setCancel();
|
||||||
// Would be called from somewhere else and throws an
|
// Would be called from somewhere else and throws an
|
||||||
// exception. We call it here for simplicity
|
// exception. We call it here for simplicity
|
||||||
cerr << "newData: should throw !\n";
|
cerr << "newData: should throw !\n";
|
||||||
CancelCheck::instance().checkCancel();
|
CancelCheck::instance().checkCancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +183,7 @@ public:
|
||||||
string *m_input;
|
string *m_input;
|
||||||
int m_cnt;
|
int m_cnt;
|
||||||
MEPv(string *i)
|
MEPv(string *i)
|
||||||
: m_input(i), m_cnt(0) {
|
: m_input(i), m_cnt(0) {
|
||||||
}
|
}
|
||||||
~MEPv() {
|
~MEPv() {
|
||||||
}
|
}
|
||||||
|
@ -199,7 +207,7 @@ public:
|
||||||
ReExec reexec;
|
ReExec reexec;
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if 0
|
#ifndef _WIN32
|
||||||
reexec.init(argc, argv);
|
reexec.init(argc, argv);
|
||||||
|
|
||||||
if (0) {
|
if (0) {
|
||||||
|
@ -214,6 +222,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
string stderrFile;
|
||||||
thisprog = argv[0];
|
thisprog = argv[0];
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
|
||||||
|
@ -225,18 +234,26 @@ int main(int argc, char *argv[])
|
||||||
while (**argv)
|
while (**argv)
|
||||||
switch (*(*argv)++) {
|
switch (*(*argv)++) {
|
||||||
case 'c': op_flags |= OPT_c; break;
|
case 'c': op_flags |= OPT_c; break;
|
||||||
case 'r': op_flags |= OPT_r; break;
|
case 'e':
|
||||||
case 'w': op_flags |= OPT_w; break;
|
op_flags |= OPT_e;
|
||||||
case 'm': op_flags |= OPT_m; break;
|
if (argc < 2) {
|
||||||
case 'i': op_flags |= OPT_i; break;
|
Usage();
|
||||||
case 'o': op_flags |= OPT_o; break;
|
}
|
||||||
case'h':
|
stderrFile = *(++argv); argc--;
|
||||||
|
goto b1;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
cout << "MESSAGE " << i << " FROM TREXECMD\n";
|
cout << "MESSAGE " << i << " FROM TREXECMD\n";
|
||||||
cout.flush();
|
cout.flush();
|
||||||
//sleep(1);
|
//sleep(1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
case 'i': op_flags |= OPT_i; break;
|
||||||
|
case 'o': op_flags |= OPT_o; break;
|
||||||
|
case 'm': op_flags |= OPT_m; break;
|
||||||
|
case 'r': op_flags |= OPT_r; break;
|
||||||
|
case 'w': op_flags |= OPT_w; break;
|
||||||
default: Usage(); break;
|
default: Usage(); break;
|
||||||
}
|
}
|
||||||
b1: argc--; argv++;
|
b1: argc--; argv++;
|
||||||
|
@ -253,10 +270,26 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
DebugLog::getdbl()->setloglevel(DEBDEB1);
|
||||||
DebugLog::setfilename("stderr");
|
DebugLog::setfilename("stderr");
|
||||||
#if 0
|
#ifndef _WIN32
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
if (op_flags & OPT_r) {
|
||||||
|
// Test reexec. Normally only once, next time we fall through
|
||||||
|
// because we remove the -r option (only works if it was
|
||||||
|
// isolated, not like -rc
|
||||||
|
chdir("/");
|
||||||
|
argv[0] = strdup("");
|
||||||
|
sleep(1);
|
||||||
|
cerr << "Calling reexec\n";
|
||||||
|
// We remove the -r arg from list, otherwise we are going to
|
||||||
|
// loop (which you can try by commenting out the following
|
||||||
|
// line)
|
||||||
|
reexec.removeArg("-r");
|
||||||
|
reexec.reexec();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (op_flags & OPT_w) {
|
if (op_flags & OPT_w) {
|
||||||
// Test "which" method
|
// Test "which" method
|
||||||
string path;
|
string path;
|
||||||
|
@ -281,10 +314,10 @@ int main(int argc, char *argv[])
|
||||||
MEAdv adv;
|
MEAdv adv;
|
||||||
mexec.setAdvise(&adv);
|
mexec.setAdvise(&adv);
|
||||||
//mexec.setTimeout(5);
|
//mexec.setTimeout(5);
|
||||||
#ifdef LATER
|
|
||||||
// Stderr output goes there
|
// Stderr output goes there
|
||||||
mexec.setStderr("/tmp/trexecStderr");
|
if (!stderrFile.empty())
|
||||||
#endif
|
mexec.setStderr(stderrFile);
|
||||||
|
|
||||||
// A few environment variables. Check with trexecmd env
|
// A few environment variables. Check with trexecmd env
|
||||||
mexec.putenv("TESTVARIABLE1=TESTVALUE1");
|
mexec.putenv("TESTVARIABLE1=TESTVALUE1");
|
||||||
mexec.putenv("TESTVARIABLE2=TESTVALUE2");
|
mexec.putenv("TESTVARIABLE2=TESTVALUE2");
|
Loading…
Add table
Add a link
Reference in a new issue