cleanup the plugins to fit the new namespace
[enigma2.git] / lib / base / console.cpp
index b3fbbf7368a917861cf75d5ed281ec0785010356..5165283ab7392ddc6f99bcef5ba41b02e0016196 100644 (file)
@@ -49,7 +49,7 @@ int bidirpipe(int pfd[], char *cmd , char *argv[])
 }
 
 eConsoleAppContainer::eConsoleAppContainer()
-:pid(-1), killstate(0)
+:pid(-1), killstate(0), in(0), out(0), err(0)
 {
        for (int i=0; i < 3; ++i)
                fd[i]=-1;
@@ -154,6 +154,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);
                                argv[cnt] = new char[ tmp.length()+1 ];
 //                             eDebug("idx=%d, arg = %s", idx, tmp.c_str() );
                                strcpy( argv[cnt++], tmp.c_str() );
@@ -171,7 +172,8 @@ int eConsoleAppContainer::execute( const std::string &cmd )
                        cmds.erase(cmds.length()-1, 1);
                }
                // store the last arg
-               argv[cnt] = new char[ cmds.length() ];
+//             eDebug("new argv[%d] %d bytes", cmds.length());
+               argv[cnt] = new char[ cmds.length()+1 ];
                strcpy( argv[cnt], cmds.c_str() );
        }
        else
@@ -244,15 +246,27 @@ void eConsoleAppContainer::sendCtrlC()
 
 void eConsoleAppContainer::closePipes()
 {
-       in->stop();
-       out->stop();
-       err->stop();
-       ::close(fd[0]);
-       fd[0]=-1;
-       ::close(fd[1]);
-       fd[1]=-1;
-       ::close(fd[2]);
-       fd[2]=-1;
+       if (in)
+               in->stop();
+       if (out)
+               out->stop();
+       if (err)
+               err->stop();
+       if (fd[0] != -1)
+       {
+               ::close(fd[0]);
+               fd[0]=-1;
+       }
+       if (fd[1] != -1)
+       {
+               ::close(fd[1]);
+               fd[1]=-1;
+       }
+       if (fd[2] != -1)
+       {
+               ::close(fd[2]);
+               fd[2]=-1;
+       }
        eDebug("pipes closed");
        while( outbuf.size() ) // cleanup out buffer
        {
@@ -337,3 +351,4 @@ void eConsoleAppContainer::readyWrite(int what)
        if ( !outbuf.size() )
                out->stop();
 }
+       
\ No newline at end of file