@@ -101,6 +101,8 @@ extern struct _children children;
101
101
sighandler_t
102
102
sw_signal (int signum , sighandler_t handler ) {
103
103
sighandler_t prev ;
104
+
105
+ debug2 ("signal() sig:%d, handler:%p" , signum , handler );
104
106
if (signum >= W32_SIGMAX ) {
105
107
errno = EINVAL ;
106
108
return W32_SIG_ERR ;
@@ -115,13 +117,15 @@ int
115
117
sw_sigprocmask (int how , const sigset_t * set , sigset_t * oldset ) {
116
118
/* this is only used by sshd to block SIGCHLD while doing waitpid() */
117
119
/* our implementation of waidpid() is never interrupted, so no need to implement this for now*/
120
+ debug3 ("sigprocmask() how:%d" );
118
121
return 0 ;
119
122
}
120
123
121
124
122
125
123
126
int
124
127
sw_raise (int sig ) {
128
+ debug ("raise sig:%d" , sig );
125
129
if (sig == W32_SIGSEGV )
126
130
return raise (SIGSEGV ); /* raise native exception handler*/
127
131
@@ -145,11 +149,8 @@ sw_raise(int sig) {
145
149
case W32_SIGCHLD :
146
150
sw_cleanup_child_zombies ();
147
151
break ;
148
- case W32_SIGINT :
149
- /* TODO - execute sigint default handler */
150
- break ;
151
152
default :
152
- break ;
153
+ ExitThread ( 1 ) ;
153
154
}
154
155
155
156
return 0 ;
@@ -173,13 +174,15 @@ sw_process_pending_signals() {
173
174
sigset_t pending_tmp = pending_signals ;
174
175
BOOL sig_int = FALSE; /* has any signal actually interrupted */
175
176
177
+ debug3 ("process_signals()" );
176
178
int i , exp [] = { W32_SIGCHLD , W32_SIGINT , W32_SIGALRM };
177
179
178
180
/* check for expected signals*/
179
181
for (i = 0 ; i < (sizeof (exp ) / sizeof (exp [0 ])); i ++ )
180
182
sigdelset (& pending_tmp , exp [i ]);
181
183
if (pending_tmp ) {
182
184
/* unexpected signals queued up */
185
+ debug ("process_signals() - ERROR unexpected signals in queue: %d" , pending_tmp );
183
186
errno = ENOTSUP ;
184
187
DebugBreak ();
185
188
return -1 ;
@@ -192,12 +195,10 @@ sw_process_pending_signals() {
192
195
if (sigismember (& pending_tmp , exp [i ])) {
193
196
if (sig_handlers [exp [i ]] != W32_SIG_IGN ) {
194
197
sw_raise (exp [i ]);
195
- sig_int = TRUE;
196
- }
197
- else { /* W32_SIG_IGN */
198
- /* for SIGCHLD process zombies */
199
- if (exp [i ] == W32_SIGCHLD )
200
- sw_cleanup_child_zombies ();
198
+ /* dont error EINTR for SIG_ALRM, */
199
+ /* sftp client is not expecting it */
200
+ if (exp [i ] != W32_SIGALRM )
201
+ sig_int = TRUE;
201
202
}
202
203
203
204
sigdelset (& pending_tmp , exp [i ]);
@@ -210,11 +211,9 @@ sw_process_pending_signals() {
210
211
DebugBreak ();
211
212
212
213
if (sig_int ) {
213
- /* processed a signal that was set not to be ignored */
214
214
debug ("process_queued_signals: WARNING - A signal has interrupted and was processed" );
215
- /* there are parts of code that do not tolerate EINT during IO, so returning 0 here*/
216
- //errno = EINTR;
217
- //return -1;
215
+ errno = EINTR ;
216
+ return -1 ;
218
217
}
219
218
220
219
return 0 ;
@@ -241,6 +240,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
241
240
num_all_events = num_events + live_children ;
242
241
243
242
if (num_all_events > MAXIMUM_WAIT_OBJECTS ) {
243
+ debug ("wait() - ERROR max events reached" );
244
244
errno = ENOTSUP ;
245
245
return -1 ;
246
246
}
@@ -252,15 +252,18 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
252
252
memcpy (all_events , children .handles , live_children * sizeof (HANDLE ));
253
253
memcpy (all_events + live_children , events , num_events * sizeof (HANDLE ));
254
254
255
+ debug3 ("wait() on %d events and %d childres" , num_events , live_children );
255
256
/* TODO - implement signal catching and handling */
256
257
if (num_all_events ) {
257
258
DWORD ret = WaitForMultipleObjectsEx (num_all_events , all_events , FALSE,
258
259
milli_seconds , TRUE);
259
260
if ((ret >= WAIT_OBJECT_0 ) && (ret <= WAIT_OBJECT_0 + num_all_events - 1 )) {
260
261
//woken up by event signalled
261
262
/* is this due to a child process going down*/
262
- if (children .num_children && ((ret - WAIT_OBJECT_0 ) < children .num_children ))
263
+ if (children .num_children && ((ret - WAIT_OBJECT_0 ) < children .num_children )) {
263
264
sigaddset (& pending_signals , W32_SIGCHLD );
265
+ sw_child_to_zombie (ret - WAIT_OBJECT_0 );
266
+ }
264
267
}
265
268
else if (ret == WAIT_IO_COMPLETION ) {
266
269
/* APC processed due to IO or signal*/
0 commit comments