From 8b921ac043a099e5037aafec79c4f99a4dbe236e Mon Sep 17 00:00:00 2001 From: FlatTV Date: Thu, 30 Aug 2012 07:19:52 +0200 Subject: [PATCH] Add global helpers my_system() and my_popen() Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/b92660259c59af1daec4ee936fa59750d01fa4ac Author: FlatTV Date: 2012-08-30 (Thu, 30 Aug 2012) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/plugins.cpp | 7 +- src/system/Makefile.am | 15 ++-- src/system/configure_network.cpp | 26 ------- src/system/helpers.cpp | 115 +++++++++++++++++++++++++++++++ src/system/helpers.h | 39 +++++++++++ 5 files changed, 169 insertions(+), 33 deletions(-) create mode 100644 src/system/helpers.cpp create mode 100644 src/system/helpers.h diff --git a/src/gui/plugins.cpp b/src/gui/plugins.cpp index 0cfb0287b..8a0e1c7e9 100644 --- a/src/gui/plugins.cpp +++ b/src/gui/plugins.cpp @@ -54,6 +54,8 @@ #include #include +#include + #include #include "plugins.h" @@ -375,7 +377,7 @@ void CPlugins::startScriptPlugin(int number) return; } pid_t pid = 0; - FILE *f = popen2(pid,script,"r"); + FILE *f = my_popen(pid,script,"r"); if (f != NULL) { char *output=NULL; @@ -396,7 +398,6 @@ void CPlugins::startScriptPlugin(int number) } } -int mysystem(const char * cmd,const char * arg1,const char * arg2); void CPlugins::startPlugin(int number,int /*param*/) { // always delete old output @@ -643,7 +644,7 @@ void CPlugins::startPlugin(int number,int /*param*/) g_RCInput->stopInput(); //frameBuffer->setMode(720, 576, 8 * sizeof(fb_pixel_t)); printf("Starting %s\n", plugin_list[number].pluginfile.c_str()); - mysystem(plugin_list[number].pluginfile.c_str(), NULL, NULL); + my_system(plugin_list[number].pluginfile.c_str(), NULL, NULL); //frameBuffer->setMode(720, 576, 8 * sizeof(fb_pixel_t)); frameBuffer->paintBackground(); g_RCInput->restartInput(); diff --git a/src/system/Makefile.am b/src/system/Makefile.am index 32b13667e..1e42f4a63 100644 --- a/src/system/Makefile.am +++ b/src/system/Makefile.am @@ -24,7 +24,14 @@ endif noinst_LIBRARIES = libneutrino_system.a libneutrino_system_a_SOURCES = \ - localize.cpp setting_helpers.cpp debug.cpp \ - ping.c flashtool.cpp httptool.cpp \ - settings.cpp lastchannel.cpp \ - configure_network.cpp fsmounter.cpp + configure_network.cpp \ + debug.cpp \ + flashtool.cpp \ + fsmounter.cpp \ + httptool.cpp \ + lastchannel.cpp \ + localize.cpp \ + helpers.cpp \ + ping.c \ + settings.cpp \ + setting_helpers.cpp diff --git a/src/system/configure_network.cpp b/src/system/configure_network.cpp index 06f144b38..ead2b3227 100644 --- a/src/system/configure_network.cpp +++ b/src/system/configure_network.cpp @@ -216,32 +216,6 @@ void CNetworkConfig::commitConfig(void) } } -int mysystem(const char * cmd, const char * arg1, const char * arg2) -{ - int i; - pid_t pid; - int maxfd = getdtablesize();// sysconf(_SC_OPEN_MAX); - switch (pid = vfork()) - { - case -1: /* can't fork */ - perror("vfork"); - return -1; - - case 0: /* child process */ - for(i = 3; i < maxfd; i++) - close(i); - if(execlp(cmd, cmd, arg1, arg2, NULL)) - { - perror("exec"); - } - exit(0); - default: /* parent returns to calling process */ - break; - } - waitpid(pid, 0, 0); - return 0; -} - void CNetworkConfig::startNetwork(void) { std::string cmd = "/sbin/ifup " + ifname; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp new file mode 100644 index 000000000..410dd1294 --- /dev/null +++ b/src/system/helpers.cpp @@ -0,0 +1,115 @@ +/* + Neutrino-GUI - DBoxII-Project + + Copyright (C) 2001 Steffen Hehn 'McClean' + Homepage: http://dbox.cyberphoria.org/ + + Kommentar: + + Diese GUI wurde von Grund auf neu programmiert und sollte nun vom + Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert + auf der Client-Server Idee, diese GUI ist also von der direkten DBox- + Steuerung getrennt. Diese wird dann von Daemons uebernommen. + + + License: GPL + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include + +int my_system(const char * cmd, const char * arg1, const char * arg2) +{ + int i; + pid_t pid; + int maxfd = getdtablesize();// sysconf(_SC_OPEN_MAX); + switch (pid = vfork()) + { + case -1: /* can't vfork */ + perror("vfork"); + return -1; + case 0: /* child process */ + for(i = 3; i < maxfd; i++) + close(i); + if(execlp(cmd, cmd, arg1, arg2, NULL)) + { + perror("exec"); + } + exit(0); + default: /* parent returns to calling process */ + break; + } + waitpid(pid, 0, 0); + return 0; +} + +FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type) +{ + int pfd[2] ={-1,-1}; + FILE *fp = NULL; + + /* only allow "r" or "w" */ + if ((type[0] != 'r' && type[0] != 'w') || type[1] != 0) { + errno = EINVAL; /* required by POSIX */ + return(NULL); + } + + if (pipe(pfd) < 0) + return(NULL); /* errno set by pipe() */ + + if ((pid = vfork()) < 0) { + return(NULL); /* errno set by vfork() */ + } else if (pid == 0) { /* child */ + if (*type == 'r') { + close(pfd[0]); + if (pfd[1] != STDOUT_FILENO) { + dup2(pfd[1], STDOUT_FILENO); + close(pfd[1]); + } + } else { + close(pfd[1]); + if (pfd[0] != STDIN_FILENO) { + dup2(pfd[0], STDIN_FILENO); + close(pfd[0]); + } + } + execl("/bin/sh", "sh", "-c", cmdstring, (char *)0); + exit(0); + } + + /* parent continues... */ + if (*type == 'r') { + close(pfd[1]); + if ((fp = fdopen(pfd[0], type)) == NULL) + return(NULL); + } else { + close(pfd[0]); + if ((fp = fdopen(pfd[1], type)) == NULL) + return(NULL); + } + return(fp); +} diff --git a/src/system/helpers.h b/src/system/helpers.h new file mode 100644 index 000000000..d041cdcae --- /dev/null +++ b/src/system/helpers.h @@ -0,0 +1,39 @@ + +#ifndef __system_helpers__ +#define __system_helpers__ + +/* + Neutrino-GUI - DBoxII-Project + + Copyright (C) 2001 Steffen Hehn 'McClean' + Homepage: http://dbox.cyberphoria.org/ + + Kommentar: + + Diese GUI wurde von Grund auf neu programmiert und sollte nun vom + Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert + auf der Client-Server Idee, diese GUI ist also von der direkten DBox- + Steuerung getrennt. Diese wird dann von Daemons uebernommen. + + + License: GPL + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +int my_system(const char * cmd, const char * arg1, const char * arg2); +FILE* my_popen( pid_t& pid, const char *cmdstring, const char *type); + +#endif