-rw-r--r-- | libopie/oprocctrl.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/libopie/oprocctrl.cpp b/libopie/oprocctrl.cpp index e7db622..df8da1e 100644 --- a/libopie/oprocctrl.cpp +++ b/libopie/oprocctrl.cpp | |||
@@ -1,138 +1,137 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | 2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | // | 19 | // |
20 | // KPROCESSCONTROLLER -- A helper class for KProcess | 20 | // KPROCESSCONTROLLER -- A helper class for KProcess |
21 | // | 21 | // |
22 | // version 0.3.1, Jan, 8th 1997 | 22 | // version 0.3.1, Jan, 8th 1997 |
23 | // | 23 | // |
24 | // (C) Christian Czezatke | 24 | // (C) Christian Czezatke |
25 | // e9025461@student.tuwien.ac.at | 25 | // e9025461@student.tuwien.ac.at |
26 | // Ported by Holger Freyther | 26 | // Ported by Holger Freyther |
27 | // | 27 | // |
28 | 28 | ||
29 | //#include <config.h> | 29 | //#include <config.h> |
30 | 30 | ||
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <sys/socket.h> | 32 | #include <sys/socket.h> |
33 | 33 | ||
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | #include <fcntl.h> | 35 | #include <fcntl.h> |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | #include <assert.h> | 39 | #include <assert.h> |
40 | 40 | ||
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include "oprocess.h" | ||
43 | #include "oprocctrl.h" | 42 | #include "oprocctrl.h" |
44 | 43 | ||
45 | OProcessController *OProcessController::theOProcessController = 0; | 44 | OProcessController *OProcessController::theOProcessController = 0; |
46 | 45 | ||
47 | struct sigaction OProcessController::oldChildHandlerData; | 46 | struct sigaction OProcessController::oldChildHandlerData; |
48 | bool OProcessController::handlerSet = false; | 47 | bool OProcessController::handlerSet = false; |
49 | 48 | ||
50 | OProcessController::OProcessController() | 49 | OProcessController::OProcessController() |
51 | { | 50 | { |
52 | assert( theOProcessController == 0 ); | 51 | assert( theOProcessController == 0 ); |
53 | 52 | ||
54 | if (0 > pipe(fd)) | 53 | if (0 > pipe(fd)) |
55 | printf(strerror(errno)); | 54 | printf(strerror(errno)); |
56 | 55 | ||
57 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); | 56 | notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); |
58 | notifier->setEnabled(true); | 57 | notifier->setEnabled(true); |
59 | QObject::connect(notifier, SIGNAL(activated(int)), | 58 | QObject::connect(notifier, SIGNAL(activated(int)), |
60 | this, SLOT(slotDoHousekeeping(int))); | 59 | this, SLOT(slotDoHousekeeping(int))); |
61 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), | 60 | connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), |
62 | SLOT( delayedChildrenCleanup())); | 61 | SLOT( delayedChildrenCleanup())); |
63 | 62 | ||
64 | theOProcessController = this; | 63 | theOProcessController = this; |
65 | 64 | ||
66 | setupHandlers(); | 65 | setupHandlers(); |
67 | } | 66 | } |
68 | 67 | ||
69 | 68 | ||
70 | void OProcessController::setupHandlers() | 69 | void OProcessController::setupHandlers() |
71 | { | 70 | { |
72 | if( handlerSet ) | 71 | if( handlerSet ) |
73 | return; | 72 | return; |
74 | struct sigaction act; | 73 | struct sigaction act; |
75 | act.sa_handler=theSigCHLDHandler; | 74 | act.sa_handler=theSigCHLDHandler; |
76 | sigemptyset(&(act.sa_mask)); | 75 | sigemptyset(&(act.sa_mask)); |
77 | sigaddset(&(act.sa_mask), SIGCHLD); | 76 | sigaddset(&(act.sa_mask), SIGCHLD); |
78 | // Make sure we don't block this signal. gdb tends to do that :-( | 77 | // Make sure we don't block this signal. gdb tends to do that :-( |
79 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); | 78 | sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); |
80 | 79 | ||
81 | act.sa_flags = SA_NOCLDSTOP; | 80 | act.sa_flags = SA_NOCLDSTOP; |
82 | 81 | ||
83 | // CC: take care of SunOS which automatically restarts interrupted system | 82 | // CC: take care of SunOS which automatically restarts interrupted system |
84 | // calls (and thus does not have SA_RESTART) | 83 | // calls (and thus does not have SA_RESTART) |
85 | 84 | ||
86 | #ifdef SA_RESTART | 85 | #ifdef SA_RESTART |
87 | act.sa_flags |= SA_RESTART; | 86 | act.sa_flags |= SA_RESTART; |
88 | #endif | 87 | #endif |
89 | 88 | ||
90 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); | 89 | sigaction( SIGCHLD, &act, &oldChildHandlerData ); |
91 | 90 | ||
92 | act.sa_handler=SIG_IGN; | 91 | act.sa_handler=SIG_IGN; |
93 | sigemptyset(&(act.sa_mask)); | 92 | sigemptyset(&(act.sa_mask)); |
94 | sigaddset(&(act.sa_mask), SIGPIPE); | 93 | sigaddset(&(act.sa_mask), SIGPIPE); |
95 | act.sa_flags = 0; | 94 | act.sa_flags = 0; |
96 | sigaction( SIGPIPE, &act, 0L); | 95 | sigaction( SIGPIPE, &act, 0L); |
97 | handlerSet = true; | 96 | handlerSet = true; |
98 | } | 97 | } |
99 | 98 | ||
100 | void OProcessController::resetHandlers() | 99 | void OProcessController::resetHandlers() |
101 | { | 100 | { |
102 | if( !handlerSet ) | 101 | if( !handlerSet ) |
103 | return; | 102 | return; |
104 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); | 103 | sigaction( SIGCHLD, &oldChildHandlerData, 0 ); |
105 | // there should be no problem with SIGPIPE staying SIG_IGN | 104 | // there should be no problem with SIGPIPE staying SIG_IGN |
106 | handlerSet = false; | 105 | handlerSet = false; |
107 | } | 106 | } |
108 | 107 | ||
109 | // block SIGCHLD handler, because it accesses processList | 108 | // block SIGCHLD handler, because it accesses processList |
110 | void OProcessController::addOProcess( OProcess* p ) | 109 | void OProcessController::addOProcess( OProcess* p ) |
111 | { | 110 | { |
112 | sigset_t newset, oldset; | 111 | sigset_t newset, oldset; |
113 | sigemptyset( &newset ); | 112 | sigemptyset( &newset ); |
114 | sigaddset( &newset, SIGCHLD ); | 113 | sigaddset( &newset, SIGCHLD ); |
115 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | 114 | sigprocmask( SIG_BLOCK, &newset, &oldset ); |
116 | processList.append( p ); | 115 | processList.append( p ); |
117 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | 116 | sigprocmask( SIG_SETMASK, &oldset, 0 ); |
118 | } | 117 | } |
119 | 118 | ||
120 | void OProcessController::removeOProcess( OProcess* p ) | 119 | void OProcessController::removeOProcess( OProcess* p ) |
121 | { | 120 | { |
122 | sigset_t newset, oldset; | 121 | sigset_t newset, oldset; |
123 | sigemptyset( &newset ); | 122 | sigemptyset( &newset ); |
124 | sigaddset( &newset, SIGCHLD ); | 123 | sigaddset( &newset, SIGCHLD ); |
125 | sigprocmask( SIG_BLOCK, &newset, &oldset ); | 124 | sigprocmask( SIG_BLOCK, &newset, &oldset ); |
126 | processList.remove( p ); | 125 | processList.remove( p ); |
127 | sigprocmask( SIG_SETMASK, &oldset, 0 ); | 126 | sigprocmask( SIG_SETMASK, &oldset, 0 ); |
128 | } | 127 | } |
129 | 128 | ||
130 | //using a struct which contains both the pid and the status makes it easier to write | 129 | //using a struct which contains both the pid and the status makes it easier to write |
131 | //and read the data into the pipe | 130 | //and read the data into the pipe |
132 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received | 131 | //especially this solves a problem which appeared on my box where slotDoHouseKeeping() received |
133 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) | 132 | //only 4 bytes (with some debug output around the write()'s it received all 8 bytes) |
134 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX | 133 | //don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX |
135 | struct waitdata | 134 | struct waitdata |
136 | { | 135 | { |
137 | pid_t pid; | 136 | pid_t pid; |
138 | int status; | 137 | int status; |