|
a/src/utils/execmd.cpp |
|
b/src/utils/execmd.cpp |
|
... |
|
... |
621 |
if (cd)
|
621 |
if (cd)
|
622 |
m_curdir = cd;
|
622 |
m_curdir = cd;
|
623 |
free(cd);
|
623 |
free(cd);
|
624 |
}
|
624 |
}
|
625 |
|
625 |
|
|
|
626 |
void ReExec::insertArgs(const vector<string>& args, int idx)
|
|
|
627 |
{
|
|
|
628 |
vector<string>::iterator it, cit;
|
|
|
629 |
unsigned int cmpoffset = (unsigned int)-1;
|
|
|
630 |
|
|
|
631 |
if (idx == -1 || string::size_type(idx) >= m_argv.size()) {
|
|
|
632 |
it = m_argv.end();
|
|
|
633 |
if (m_argv.size() >= args.size()) {
|
|
|
634 |
cmpoffset = m_argv.size() - args.size();
|
|
|
635 |
}
|
|
|
636 |
} else {
|
|
|
637 |
it = m_argv.begin() + idx;
|
|
|
638 |
if (idx + args.size() <= m_argv.size()) {
|
|
|
639 |
cmpoffset = idx;
|
|
|
640 |
}
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
// Check that the option is not already there
|
|
|
644 |
if (cmpoffset != (unsigned int)-1) {
|
|
|
645 |
bool allsame = true;
|
|
|
646 |
for (unsigned int i = 0; i < args.size(); i++) {
|
|
|
647 |
if (m_argv[cmpoffset + i] != args[i]) {
|
|
|
648 |
allsame = false;
|
|
|
649 |
break;
|
|
|
650 |
}
|
|
|
651 |
}
|
|
|
652 |
if (allsame)
|
|
|
653 |
return;
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
m_argv.insert(it, args.begin(), args.end());
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
void ReExec::removeArg(const string& arg)
|
|
|
660 |
{
|
|
|
661 |
for (vector<string>::iterator it = m_argv.begin();
|
|
|
662 |
it != m_argv.end(); it++) {
|
|
|
663 |
if (*it == arg)
|
|
|
664 |
it = m_argv.erase(it);
|
|
|
665 |
}
|
|
|
666 |
}
|
|
|
667 |
|
626 |
// Reexecute myself, as close as possible to the initial exec
|
668 |
// Reexecute myself, as close as possible to the initial exec
|
627 |
void ReExec::reexec()
|
669 |
void ReExec::reexec()
|
628 |
{
|
670 |
{
|
629 |
|
671 |
|
630 |
#if 0
|
672 |
#if 0
|
|
... |
|
... |
756 |
ReExec reexec;
|
798 |
ReExec reexec;
|
757 |
|
799 |
|
758 |
int main(int argc, char *argv[])
|
800 |
int main(int argc, char *argv[])
|
759 |
{
|
801 |
{
|
760 |
reexec.init(argc, argv);
|
802 |
reexec.init(argc, argv);
|
|
|
803 |
|
|
|
804 |
if (0) {
|
|
|
805 |
vector<string> newargs;
|
|
|
806 |
newargs.push_back("newarg");
|
|
|
807 |
newargs.push_back("newarg1");
|
|
|
808 |
newargs.push_back("newarg2");
|
|
|
809 |
newargs.push_back("newarg3");
|
|
|
810 |
newargs.push_back("newarg4");
|
|
|
811 |
reexec.insertArgs(newargs, 2);
|
|
|
812 |
}
|
|
|
813 |
|
761 |
thisprog = argv[0];
|
814 |
thisprog = argv[0];
|
762 |
argc--; argv++;
|
815 |
argc--; argv++;
|
763 |
|
816 |
|
764 |
while (argc > 0 && **argv == '-') {
|
817 |
while (argc > 0 && **argv == '-') {
|
765 |
(*argv)++;
|
818 |
(*argv)++;
|