dont kill pid -1
[enigma2.git] / lib / base / console.cpp
index 5165283ab7392ddc6f99bcef5ba41b02e0016196..f6e8763f59c153185e0e55e6724a23fe2f8d15e7 100644 (file)
@@ -124,7 +124,9 @@ int eConsoleAppContainer::execute( const std::string &cmd )
 
 //     eDebug("%d args", cnt-2);
        char **argv = new char*[cnt];  // min two args... path and terminating 0
-       argv[0] = new char[ plen ];
+//     eDebug("%d args", cnt);
+       argv[0] = new char[ plen+1 ];
+//     eDebug("new argv[0] %d bytes (%s)", plen+1, path.c_str());
        strcpy( argv[0], path.c_str() );
        argv[cnt-1] = 0;               // set terminating null
 
@@ -154,7 +156,7 @@ int eConsoleAppContainer::execute( const std::string &cmd )
                                        tmp.erase(tmp.length()-1, 1);
                                        bracketClosed=false;
                                }
-//                             eDebug("new argv[%d] %d bytes", tmp.length()+1);
+//                             eDebug("new argv[%d] %d bytes (%s)", cnt, tmp.length()+1, tmp.c_str());
                                argv[cnt] = new char[ tmp.length()+1 ];
 //                             eDebug("idx=%d, arg = %s", idx, tmp.c_str() );
                                strcpy( argv[cnt++], tmp.c_str() );
@@ -172,7 +174,7 @@ int eConsoleAppContainer::execute( const std::string &cmd )
                        cmds.erase(cmds.length()-1, 1);
                }
                // store the last arg
-//             eDebug("new argv[%d] %d bytes", cmds.length());
+//             eDebug("new argv[%d] %d bytes (%s)", cnt, cmds.length()+1, cmds.c_str());
                argv[cnt] = new char[ cmds.length()+1 ];
                strcpy( argv[cnt], cmds.c_str() );
        }
@@ -198,7 +200,7 @@ int eConsoleAppContainer::execute( const std::string &cmd )
        if ( pid == -1 )
                return -3;
 
-       eDebug("pipe in = %d, out = %d, err = %d", fd[0], fd[1], fd[2]);
+//     eDebug("pipe in = %d, out = %d, err = %d", fd[0], fd[1], fd[2]);
 
        in = new eSocketNotifier(eApp, fd[0], POLLIN|POLLPRI|POLLHUP );
        out = new eSocketNotifier(eApp, fd[1], POLLOUT, false);  
@@ -216,7 +218,7 @@ eConsoleAppContainer::~eConsoleAppContainer()
 
 void eConsoleAppContainer::kill()
 {
-       if ( killstate != -1 )
+       if ( killstate != -1 && pid != -1 )
        {
                eDebug("user kill(SIGKILL) console App");
                killstate=-1;
@@ -237,7 +239,7 @@ void eConsoleAppContainer::kill()
 
 void eConsoleAppContainer::sendCtrlC()
 {
-       if ( killstate != -1 )
+       if ( killstate != -1 && pid != -1 )
        {
                eDebug("user send SIGINT(Ctrl-C) to console App");
                ::kill(pid, SIGINT);
@@ -274,6 +276,7 @@ void eConsoleAppContainer::closePipes()
                outbuf.pop();
                delete [] d.data;
        }
+       pid = -1;
 }
 
 void eConsoleAppContainer::readyRead(int what)