Skip to content

Commit e3b1997

Browse files
committed
update signal code
1 parent 56ad915 commit e3b1997

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

contrib/win32/win32compat/signal.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ extern struct _children children;
101101
sighandler_t
102102
sw_signal(int signum, sighandler_t handler) {
103103
sighandler_t prev;
104+
105+
debug2("signal() sig:%d, handler:%p", signum, handler);
104106
if (signum >= W32_SIGMAX) {
105107
errno = EINVAL;
106108
return W32_SIG_ERR;
@@ -115,13 +117,15 @@ int
115117
sw_sigprocmask(int how, const sigset_t *set, sigset_t *oldset) {
116118
/* this is only used by sshd to block SIGCHLD while doing waitpid() */
117119
/* our implementation of waidpid() is never interrupted, so no need to implement this for now*/
120+
debug3("sigprocmask() how:%d");
118121
return 0;
119122
}
120123

121124

122125

123126
int
124127
sw_raise(int sig) {
128+
debug("raise sig:%d", sig);
125129
if (sig == W32_SIGSEGV)
126130
return raise(SIGSEGV); /* raise native exception handler*/
127131

@@ -145,11 +149,8 @@ sw_raise(int sig) {
145149
case W32_SIGCHLD:
146150
sw_cleanup_child_zombies();
147151
break;
148-
case W32_SIGINT:
149-
/* TODO - execute sigint default handler */
150-
break;
151152
default:
152-
break;
153+
ExitThread(1);
153154
}
154155

155156
return 0;
@@ -173,13 +174,15 @@ sw_process_pending_signals() {
173174
sigset_t pending_tmp = pending_signals;
174175
BOOL sig_int = FALSE; /* has any signal actually interrupted */
175176

177+
debug3("process_signals()");
176178
int i, exp[] = { W32_SIGCHLD , W32_SIGINT , W32_SIGALRM };
177179

178180
/* check for expected signals*/
179181
for (i = 0; i < (sizeof(exp) / sizeof(exp[0])); i++)
180182
sigdelset(&pending_tmp, exp[i]);
181183
if (pending_tmp) {
182184
/* unexpected signals queued up */
185+
debug("process_signals() - ERROR unexpected signals in queue: %d", pending_tmp);
183186
errno = ENOTSUP;
184187
DebugBreak();
185188
return -1;
@@ -192,12 +195,10 @@ sw_process_pending_signals() {
192195
if (sigismember(&pending_tmp, exp[i])) {
193196
if (sig_handlers[exp[i]] != W32_SIG_IGN) {
194197
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;
201202
}
202203

203204
sigdelset(&pending_tmp, exp[i]);
@@ -210,11 +211,9 @@ sw_process_pending_signals() {
210211
DebugBreak();
211212

212213
if (sig_int) {
213-
/* processed a signal that was set not to be ignored */
214214
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;
218217
}
219218

220219
return 0;
@@ -241,6 +240,7 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
241240
num_all_events = num_events + live_children;
242241

243242
if (num_all_events > MAXIMUM_WAIT_OBJECTS) {
243+
debug("wait() - ERROR max events reached");
244244
errno = ENOTSUP;
245245
return -1;
246246
}
@@ -252,15 +252,18 @@ wait_for_any_event(HANDLE* events, int num_events, DWORD milli_seconds)
252252
memcpy(all_events, children.handles, live_children * sizeof(HANDLE));
253253
memcpy(all_events + live_children, events, num_events * sizeof(HANDLE));
254254

255+
debug3("wait() on %d events and %d childres", num_events, live_children);
255256
/* TODO - implement signal catching and handling */
256257
if (num_all_events) {
257258
DWORD ret = WaitForMultipleObjectsEx(num_all_events, all_events, FALSE,
258259
milli_seconds, TRUE);
259260
if ((ret >= WAIT_OBJECT_0) && (ret <= WAIT_OBJECT_0 + num_all_events - 1)) {
260261
//woken up by event signalled
261262
/* 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)) {
263264
sigaddset(&pending_signals, W32_SIGCHLD);
265+
sw_child_to_zombie(ret - WAIT_OBJECT_0);
266+
}
264267
}
265268
else if (ret == WAIT_IO_COMPLETION) {
266269
/* APC processed due to IO or signal*/

contrib/win32/win32compat/signal_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct _children {
2323
int sw_add_child(HANDLE child, DWORD pid);
2424
int sw_remove_child_at_index(DWORD index);
2525
int sw_child_to_zombie(DWORD index);
26-
int sw_remove_child(HANDLE child);
2726
void sw_cleanup_child_zombies();
2827

2928
struct _timer_info {

contrib/win32/win32compat/signal_sigalrm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sw_alarm(unsigned int sec) {
4848
ULONGLONG sec_passed;
4949
int ret = 0;
5050

51+
debug3("alarm() %d secs", sec);
5152
errno = 0;
5253
/* cancel any live timer if seconds is 0*/
5354
if (sec == 0) {

contrib/win32/win32compat/signal_sigchld.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,11 @@ sw_child_to_zombie(DWORD index) {
127127
return 0;
128128
}
129129

130-
int
131-
sw_remove_child(HANDLE child) {
132-
HANDLE* handles = children.handles;
133-
DWORD num_children = children.num_children;
134-
135-
while (num_children) {
136-
if (*handles == child)
137-
return sw_remove_child_at_index(children.num_children - num_children);
138-
handles++;
139-
num_children--;
140-
}
141-
142-
errno = EINVAL;
143-
return -1;
144-
}
145-
146130
int waitpid(int pid, int *status, int options) {
147131
DWORD index, ret, ret_id, exit_code, timeout = 0;
148132
HANDLE process = NULL;
149133

134+
debug3("waitpid - pid:%d, options:%d", pid, options);
150135
if (options & (~WNOHANG)) {
151136
errno = ENOTSUP;
152137
DebugBreak();

0 commit comments

Comments
 (0)