author | zecke <zecke> | 2002-10-12 00:40:14 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-12 00:40:14 (UTC) |
commit | 39b88e5809e50a4951869434b8015c55265fc495 (patch) (side-by-side diff) | |
tree | ad444833b2c9fd0c672c7dfdcc99b3a33ace8b8d | |
parent | 0a3ffe7e5657bed4cb77d9bc23457755e2d02591 (diff) | |
download | opie-39b88e5809e50a4951869434b8015c55265fc495.zip opie-39b88e5809e50a4951869434b8015c55265fc495.tar.gz opie-39b88e5809e50a4951869434b8015c55265fc495.tar.bz2 |
No does not have any public c'tor
-rw-r--r-- | noncore/apps/opie-console/procctl.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/procctl.h | 5 |
2 files changed, 10 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/procctl.cpp b/noncore/apps/opie-console/procctl.cpp index 6839a84..ff6bea8 100644 --- a/noncore/apps/opie-console/procctl.cpp +++ b/noncore/apps/opie-console/procctl.cpp @@ -1,90 +1,96 @@ #include <sys/wait.h> #include <fcntl.h> #include <unistd.h> #include "procctl.h" ProcContainer *ProcCtl::m_last = 0; +ProcCtl* ProcCtl::m_self = 0; ProcCtl::ProcCtl() { signal( SIGCHLD, signal_handler ); } ProcCtl::~ProcCtl() { } +ProcCtl* ProcCtl::self() { + if (!m_self ) { + m_self = new ProcCtl; + } +} void ProcCtl::add(pid_t pi, int fd ) { ProcContainer * con = new ProcContainer; //memset(con, 0, sizeof(con) ); con->pid = pi; con->fd = fd; con->status = 0; con->prev = m_last; m_last = con; } void ProcCtl::remove( pid_t pi ) { /* * We first check if the last item * is equal to pi the we * */ ProcContainer* con; if (m_last->pid == pi ) { con = m_last; m_last = con->prev; delete con; return; } con = m_last; ProcContainer* forw = 0l; while (con ) { /* remove it */ if ( pi == con->pid ) { forw->prev = con->prev; delete con; return; } forw = con; con = con->prev; } } void ProcCtl::remove( ProcContainer con ) { remove( con.pid ); } int ProcCtl::status(pid_t pid )const{ ProcContainer *con = m_last; while (con) { if (con->pid == pid ) return con->status; con = con->prev; } return -1; } void ProcCtl::signal_handler(int) { int status; signal( SIGCHLD, signal_handler ); pid_t pi = waitpid( -1, &status, WNOHANG ); /* * find the container for pid * */ if ( pi < 0 ) { return; } ProcContainer* con = m_last; while (con) { if ( con->pid == pi ) { con->status = status; char result = 1; /* give a 'signal' */ ::write(con->fd, &result, 1 ); } con = con->prev; } } diff --git a/noncore/apps/opie-console/procctl.h b/noncore/apps/opie-console/procctl.h index e2161f3..5e96423 100644 --- a/noncore/apps/opie-console/procctl.h +++ b/noncore/apps/opie-console/procctl.h @@ -1,33 +1,36 @@ #ifndef OPIE_PROC_CTL_H #define OPIE_PROC_CTL_H #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> #include <qmap.h> struct ProcContainer { pid_t pid; int fd; int status; ProcContainer* prev; }; class ProcCtl { -public: +private: ProcCtl(); +public: ~ProcCtl(); + ProcCtl* self(); int status(pid_t)const; void add( pid_t, int fd ); void remove( pid_t ); void remove( ProcContainer ); private: static void signal_handler(int); static ProcContainer* m_last; + static ProcCtl* m_self; }; #endif |