-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,38 +1,44 @@ | |||
1 | #include <sys/wait.h> | 1 | #include <sys/wait.h> |
2 | 2 | ||
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | 5 | ||
6 | #include "procctl.h" | 6 | #include "procctl.h" |
7 | 7 | ||
8 | ProcContainer *ProcCtl::m_last = 0; | 8 | ProcContainer *ProcCtl::m_last = 0; |
9 | ProcCtl* ProcCtl::m_self = 0; | ||
9 | 10 | ||
10 | ProcCtl::ProcCtl() { | 11 | ProcCtl::ProcCtl() { |
11 | signal( SIGCHLD, signal_handler ); | 12 | signal( SIGCHLD, signal_handler ); |
12 | } | 13 | } |
13 | ProcCtl::~ProcCtl() { | 14 | ProcCtl::~ProcCtl() { |
14 | } | 15 | } |
16 | ProcCtl* ProcCtl::self() { | ||
17 | if (!m_self ) { | ||
18 | m_self = new ProcCtl; | ||
19 | } | ||
20 | } | ||
15 | void ProcCtl::add(pid_t pi, int fd ) { | 21 | void ProcCtl::add(pid_t pi, int fd ) { |
16 | ProcContainer * con = new ProcContainer; | 22 | ProcContainer * con = new ProcContainer; |
17 | //memset(con, 0, sizeof(con) ); | 23 | //memset(con, 0, sizeof(con) ); |
18 | con->pid = pi; | 24 | con->pid = pi; |
19 | con->fd = fd; | 25 | con->fd = fd; |
20 | con->status = 0; | 26 | con->status = 0; |
21 | con->prev = m_last; | 27 | con->prev = m_last; |
22 | 28 | ||
23 | m_last = con; | 29 | m_last = con; |
24 | 30 | ||
25 | } | 31 | } |
26 | void ProcCtl::remove( pid_t pi ) { | 32 | void ProcCtl::remove( pid_t pi ) { |
27 | /* | 33 | /* |
28 | * We first check if the last item | 34 | * We first check if the last item |
29 | * is equal to pi the we | 35 | * is equal to pi the we |
30 | * | 36 | * |
31 | */ | 37 | */ |
32 | ProcContainer* con; | 38 | ProcContainer* con; |
33 | if (m_last->pid == pi ) { | 39 | if (m_last->pid == pi ) { |
34 | con = m_last; | 40 | con = m_last; |
35 | m_last = con->prev; | 41 | m_last = con->prev; |
36 | delete con; | 42 | delete con; |
37 | return; | 43 | return; |
38 | } | 44 | } |
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 @@ | |||
1 | #ifndef OPIE_PROC_CTL_H | 1 | #ifndef OPIE_PROC_CTL_H |
2 | #define OPIE_PROC_CTL_H | 2 | #define OPIE_PROC_CTL_H |
3 | 3 | ||
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include <fcntl.h> | 6 | #include <fcntl.h> |
7 | #include <signal.h> | 7 | #include <signal.h> |
8 | 8 | ||
9 | #include <qmap.h> | 9 | #include <qmap.h> |
10 | 10 | ||
11 | 11 | ||
12 | struct ProcContainer { | 12 | struct ProcContainer { |
13 | pid_t pid; | 13 | pid_t pid; |
14 | int fd; | 14 | int fd; |
15 | int status; | 15 | int status; |
16 | ProcContainer* prev; | 16 | ProcContainer* prev; |
17 | }; | 17 | }; |
18 | 18 | ||
19 | class ProcCtl { | 19 | class ProcCtl { |
20 | public: | 20 | private: |
21 | ProcCtl(); | 21 | ProcCtl(); |
22 | public: | ||
22 | ~ProcCtl(); | 23 | ~ProcCtl(); |
23 | 24 | ||
25 | ProcCtl* self(); | ||
24 | int status(pid_t)const; | 26 | int status(pid_t)const; |
25 | void add( pid_t, int fd ); | 27 | void add( pid_t, int fd ); |
26 | void remove( pid_t ); | 28 | void remove( pid_t ); |
27 | void remove( ProcContainer ); | 29 | void remove( ProcContainer ); |
28 | private: | 30 | private: |
29 | static void signal_handler(int); | 31 | static void signal_handler(int); |
30 | static ProcContainer* m_last; | 32 | static ProcContainer* m_last; |
33 | static ProcCtl* m_self; | ||
31 | }; | 34 | }; |
32 | 35 | ||
33 | #endif | 36 | #endif |