summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console
Unidiff
Diffstat (limited to 'noncore/apps/opie-console') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/procctl.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/procctl.cpp b/noncore/apps/opie-console/procctl.cpp
index a44529b..5239e26 100644
--- a/noncore/apps/opie-console/procctl.cpp
+++ b/noncore/apps/opie-console/procctl.cpp
@@ -4,94 +4,97 @@
4#include <unistd.h> 4#include <unistd.h>
5 5
6#include "procctl.h" 6#include "procctl.h"
7 7
8ProcContainer *ProcCtl::m_last = 0; 8ProcContainer *ProcCtl::m_last = 0;
9ProcCtl* ProcCtl::m_self = 0; 9ProcCtl* ProcCtl::m_self = 0;
10 10
11ProcCtl::ProcCtl() { 11ProcCtl::ProcCtl() {
12 signal( SIGCHLD, signal_handler ); 12 signal( SIGCHLD, signal_handler );
13} 13}
14ProcCtl::~ProcCtl() { 14ProcCtl::~ProcCtl() {
15} 15}
16ProcCtl* ProcCtl::self() { 16ProcCtl* ProcCtl::self() {
17 if (!m_self ) { 17 if (!m_self ) {
18 m_self = new ProcCtl; 18 m_self = new ProcCtl;
19 } 19 }
20 return m_self; 20 return m_self;
21} 21}
22void ProcCtl::add(pid_t pi, int fd ) { 22void ProcCtl::add(pid_t pi, int fd ) {
23 ProcContainer * con = new ProcContainer; 23 ProcContainer * con = new ProcContainer;
24 //memset(con, 0, sizeof(con) ); 24 //memset(con, 0, sizeof(con) );
25 con->pid = pi; 25 con->pid = pi;
26 con->fd = fd; 26 con->fd = fd;
27 con->status = 0; 27 con->status = 0;
28 con->prev = m_last; 28 con->prev = m_last;
29 29
30 m_last = con; 30 m_last = con;
31 31
32} 32}
33void ProcCtl::remove( pid_t pi ) { 33void ProcCtl::remove( pid_t pi ) {
34 /* 34 /*
35 * We first check if the last item 35 * We first check if the last item
36 * is equal to pi the we 36 * is equal to pi the we
37 * 37 *
38 */ 38 */
39 ProcContainer* con; 39 ProcContainer* con;
40 if (m_last->pid == pi ) { 40 if (m_last->pid == pi ) {
41 con = m_last; 41 con = m_last;
42 m_last = con->prev; 42 m_last = con->prev;
43 delete con; 43 delete con;
44 return; 44 return;
45 } 45 }
46 46
47 con = m_last; 47 con = m_last;
48 ProcContainer* forw = 0l; 48 ProcContainer* forw = 0l;
49 while (con ) { 49 while (con ) {
50 /* remove it */ 50 /* remove it */
51 if ( pi == con->pid ) { 51 if ( pi == con->pid ) {
52 forw->prev = con->prev; 52 if (forw)
53 forw->prev = con->prev;
54 else
55 forw = con->prev;
53 delete con; 56 delete con;
54 return; 57 return;
55 } 58 }
56 59
57 forw = con; 60 forw = con;
58 con = con->prev; 61 con = con->prev;
59 } 62 }
60 63
61} 64}
62void ProcCtl::remove( ProcContainer con ) { 65void ProcCtl::remove( ProcContainer con ) {
63 remove( con.pid ); 66 remove( con.pid );
64} 67}
65int ProcCtl::status(pid_t pid )const{ 68int ProcCtl::status(pid_t pid )const{
66 ProcContainer *con = m_last; 69 ProcContainer *con = m_last;
67 while (con) { 70 while (con) {
68 if (con->pid == pid ) 71 if (con->pid == pid )
69 return con->status; 72 return con->status;
70 con = con->prev; 73 con = con->prev;
71 } 74 }
72 return -1; 75 return -1;
73} 76}
74void ProcCtl::signal_handler(int) { 77void ProcCtl::signal_handler(int) {
75 int status; 78 int status;
76 signal( SIGCHLD, signal_handler ); 79 signal( SIGCHLD, signal_handler );
77 pid_t pi = waitpid( -1, &status, WNOHANG ); 80 pid_t pi = waitpid( -1, &status, WNOHANG );
78 81
79 /* 82 /*
80 * find the container for pid 83 * find the container for pid
81 * 84 *
82 */ 85 */
83 if ( pi < 0 ) { 86 if ( pi < 0 ) {
84 return; 87 return;
85 } 88 }
86 89
87 ProcContainer* con = m_last; 90 ProcContainer* con = m_last;
88 while (con) { 91 while (con) {
89 if ( con->pid == pi ) { 92 if ( con->pid == pi ) {
90 con->status = status; 93 con->status = status;
91 char result = 1; 94 char result = 1;
92 /* give a 'signal' */ 95 /* give a 'signal' */
93 ::write(con->fd, &result, 1 ); 96 ::write(con->fd, &result, 1 );
94 } 97 }
95 con = con->prev; 98 con = con->prev;
96 } 99 }
97} 100}