Index: libs/libmyth/lirc.cpp =================================================================== RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/lirc.cpp,v retrieving revision 1.8 diff -u -p -r1.8 lirc.cpp --- libs/libmyth/lirc.cpp 7 Apr 2004 06:48:40 -0000 1.8 +++ libs/libmyth/lirc.cpp 21 Oct 2004 04:31:06 -0000 @@ -105,29 +105,15 @@ void LircClient::SpawnApp(void) { // Spawn app to thwap led (or what ever the user has picked if // anything) to give positive feedback that a key was received - if (external_app != " &") + if (external_app == " &") + return; + + int status = myth_system(external_app); + + if (status > 0) { - pid_t child = fork(); - if (child < 0) - perror("fork"); - else if (child == 0) - { - for (int i = 3; i < sysconf(_SC_OPEN_MAX) - 1; ++i) - close(i); - execl("/bin/sh", "sh", "-c", external_app.ascii(), NULL); - _exit(1); - } - else - { - int status; - if (waitpid(child, &status, 0) < 0) - perror("waitpid"); - else if (status != 0) - { - cerr << "External key pressed command exited with status " - << status << endl; - } - } + cerr << "External key pressed command exited with status " + << status << endl; } } Index: libs/libmyth/util.cpp =================================================================== RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/util.cpp,v retrieving revision 1.39 diff -u -p -r1.39 util.cpp --- libs/libmyth/util.cpp 14 Oct 2004 04:30:59 -0000 1.39 +++ libs/libmyth/util.cpp 21 Oct 2004 04:31:14 -0000 @@ -1,6 +1,9 @@ #include +#include +#include #include +#include #include using namespace std; @@ -656,7 +659,46 @@ int myth_system(const QString &command, (void)flags; #endif - return system(command); + pid_t child = fork(); + + if (child < 0) + { + /* Fork failed */ + perror("fork"); + return -1; + } + else if (child == 0) + { + /* Child */ + /* Close all open file descriptors except stdout/stderr */ + for (int i = sysconf(_SC_OPEN_MAX) - 1; i > 2; i--) + close(i); + + /* Attach stdin to /dev/null */ + close(0); + int fd = open("/dev/null", O_RDONLY); + dup2(fd, 0); + if (fd != 0) + close(fd); + + /* Run command */ + execl("/bin/sh", "sh", "-c", command.ascii(), NULL); + perror("execl"); + + /* Failed to exec */ + _exit(127); + } + else + { + /* Parent */ + int status; + + if (waitpid(child, &status, 0) < 0) { + perror("waitpid"); + return -1; + } + return WEXITSTATUS(status); + } } QString cutDownString(QString text, QFont *testFont, int maxwidth)