also make in FD nonblocking
[enigma2.git] / lib / base / console.cpp
index a12cb5e29bc7f408442e79c2cc303a97c1d2182d..add870666b2af45b0dc65c84d0fa4ec0eef1a63e 100644 (file)
@@ -109,6 +109,7 @@ int eConsoleAppContainer::execute(const char *cmdline, const char * const argv[]
 
 //     eDebug("pipe in = %d, out = %d, err = %d", fd[0], fd[1], fd[2]);
 
+       ::fcntl(fd[0], F_SETFL, O_NONBLOCK);
        ::fcntl(fd[1], F_SETFL, O_NONBLOCK);
        ::fcntl(fd[2], F_SETFL, O_NONBLOCK);
        in = eSocketNotifier::create(eApp, fd[0], eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Hungup );
@@ -476,11 +477,37 @@ eConsolePy_running(eConsolePy* self)
 static PyObject *
 eConsolePy_execute(eConsolePy* self, PyObject *argt)
 {
-       const char *str;
-       if (PyArg_ParseTuple(argt, "s", &str))
-               return PyInt_FromLong(self->cont->execute(str));
-       PyErr_SetString(PyExc_TypeError,
-               "argument is not a string");
+       Py_ssize_t argc = PyTuple_Size(argt);
+       if (argc > 1)
+       {
+               const char *argv[argc + 1];
+               int argpos=0;
+               while(argpos < argc)
+               {
+                       PyObject *arg = PyTuple_GET_ITEM(argt, argpos);
+                       if (!PyString_Check(arg))
+                       {
+                               char err[255];
+                               if (argpos)
+                                       snprintf(err, 255, "arg %d is not a string", argpos);
+                               else
+                                       snprintf(err, 255, "cmd is not a string!");
+                               PyErr_SetString(PyExc_TypeError, err);
+                               return NULL;
+                       }
+                       argv[argpos++] = PyString_AsString(arg);
+               }
+               argv[argpos] = 0;
+               return PyInt_FromLong(self->cont->execute(argv[0], argv+1));
+       }
+       else
+       {
+               const char *str;
+               if (PyArg_ParseTuple(argt, "s", &str))
+                       return PyInt_FromLong(self->cont->execute(str));
+               PyErr_SetString(PyExc_TypeError,
+                       "cmd is not a string!");
+       }
        return NULL;
 }