CShellWindow: use my_popen() to avoid leaking fds etc.

This commit is contained in:
Stefan Seyfried
2015-02-01 20:01:09 +01:00
committed by Jacek Jendrzej
parent a85878db2f
commit e02972c81c

View File

@@ -7,6 +7,7 @@
Implementation: Implementation:
Copyright (C) 2013 martii Copyright (C) 2013 martii
gitorious.org/neutrino-mp/martiis-neutrino-mp gitorious.org/neutrino-mp/martiis-neutrino-mp
Copyright (C) 2015 Stefan Seyfried
License: GPL License: GPL
@@ -33,13 +34,18 @@
#include <global.h> #include <global.h>
#include <neutrino.h> #include <neutrino.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <driver/framebuffer.h> #include <driver/framebuffer.h>
#include <gui/widget/textbox.h> #include <gui/widget/textbox.h>
#include <stdio.h> #include <stdio.h>
#include <poll.h> #include <poll.h>
#include <fcntl.h> #include <fcntl.h>
#include <system/helpers.h>
#include <errno.h>
CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res) { CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res) {
pid_t pid;
textBox = NULL; textBox = NULL;
std::string cmd; std::string cmd;
mode = _mode; mode = _mode;
@@ -56,7 +62,7 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res
} }
cmd = command + " 2>&1"; cmd = command + " 2>&1";
FILE *f = popen(cmd.c_str(), "r"); FILE *f = my_popen(pid, cmd.c_str(), "r");
if (!f) { if (!f) {
if (res) if (res)
*res = -1; *res = -1;
@@ -163,13 +169,16 @@ CShellWindow::CShellWindow(const std::string &command, const int _mode, int *res
} }
} while(ok); } while(ok);
int r = pclose(f); fclose(f);
int s;
errno = 0;
int r = waitpid(pid, &s, 0);
if (res) { if (res) {
if (r == -1) if (r == -1)
*res = r; *res = errno;
else else
*res = WEXITSTATUS(r); *res = WEXITSTATUS(s);
} }
} }