24 static int write_sigio_pid = -1;
25 static unsigned long write_sigio_stack;
32 #define SIGIO_FDS_INIT {-1, -1}
47 static struct pollfds current_poll;
48 static struct pollfds next_poll;
49 static struct pollfds all_sigio_fds;
51 static int write_sigio_thread(
void *
unused)
66 "%d, errno = %d\n", n, errno);
68 for (i = 0; i < fds->
used; i++) {
72 if (p->
fd == sigio_private[1]) {
77 "write_sigio_thread : "
78 "read on socket failed, "
81 current_poll = next_poll;
83 respond_fd = sigio_private[1];
86 respond_fd = write_sigio_fds[1];
89 (fds->
used - i) *
sizeof(*fds->
poll));
95 "write on socket failed, err = %d\n",
103 static int need_poll(
struct pollfds *polls,
int n)
107 if (n <= polls->
size)
129 static void update_thread(
void)
137 if (n !=
sizeof(c)) {
144 if (n !=
sizeof(c)) {
154 if (write_sigio_pid != -1) {
158 write_sigio_pid = -1;
159 close(sigio_private[0]);
160 close(sigio_private[1]);
161 close(write_sigio_fds[0]);
162 close(write_sigio_fds[1]);
173 for (i = 0; i < all_sigio_fds.used; i++) {
174 if (all_sigio_fds.poll[i].fd == fd)
177 if (i == all_sigio_fds.used)
180 p = &all_sigio_fds.poll[
i];
182 for (i = 0; i < current_poll.used; i++) {
183 if (current_poll.poll[i].fd == fd)
187 n = current_poll.used;
188 err = need_poll(&next_poll, n + 1);
192 memcpy(next_poll.poll, current_poll.poll,
193 current_poll.used *
sizeof(
struct pollfd));
194 next_poll.poll[
n] = *
p;
195 next_poll.used = n + 1;
205 int err = 0,
i, n = 0;
212 if (write_sigio_pid == -1)
216 for (i = 0; i < current_poll.used; i++) {
217 if (current_poll.poll[i].fd == fd)
220 if (i == current_poll.used)
223 err = need_poll(&next_poll, current_poll.used - 1);
227 for (i = 0; i < current_poll.used; i++) {
228 p = ¤t_poll.poll[
i];
230 next_poll.poll[n++] = *
p;
232 next_poll.used = current_poll.used - 1;
240 static struct pollfd *setup_initial_poll(
int fd)
256 static void write_sigio_workaround(
void)
260 int l_write_sigio_fds[2];
261 int l_sigio_private[2];
262 int l_write_sigio_pid;
266 l_write_sigio_pid = write_sigio_pid;
269 if (l_write_sigio_pid != -1)
272 err =
os_pipe(l_write_sigio_fds, 1, 1);
278 err =
os_pipe(l_sigio_private, 1, 1);
285 p = setup_initial_poll(l_sigio_private[1]);
295 if (write_sigio_pid != -1)
298 current_poll = ((
struct pollfds) { .poll =
p,
305 memcpy(write_sigio_fds, l_write_sigio_fds,
sizeof(l_write_sigio_fds));
306 memcpy(sigio_private, l_sigio_private,
sizeof(l_sigio_private));
312 if (write_sigio_pid < 0)
319 write_sigio_pid = -1;
320 write_sigio_fds[0] = -1;
321 write_sigio_fds[1] = -1;
322 sigio_private[0] = -1;
323 sigio_private[1] = -1;
332 close(l_sigio_private[0]);
333 close(l_sigio_private[1]);
335 close(l_write_sigio_fds[0]);
336 close(l_write_sigio_fds[1]);
343 write_sigio_workaround();
346 err = need_poll(&all_sigio_fds, all_sigio_fds.used + 1);
349 "for descriptor %d\n", fd);
353 all_sigio_fds.poll[all_sigio_fds.used++] =
362 static int pty_output_sigio;
363 static int pty_close_sigio;
370 if ((read || pty_output_sigio) && (!read || pty_close_sigio))
376 static void sigio_cleanup(
void)
378 if (write_sigio_pid == -1)
383 write_sigio_pid = -1;
389 static int got_sigio;
402 static void openpty_cb(
void *
arg)
415 flags = fcntl(master,
F_GETFL);
429 static void __init check_one_sigio(
void (*proc)(
int,
int))
445 if ((master == -1) || (slave == -1)) {
459 err = async_pty(master, slave);
468 "errno = %d\n", errno);
476 "errno = %d\n", errno);
488 "errno = %d\n", errno);
491 static void tty_output(
int master,
int slave)
498 memset(buf, 0,
sizeof(buf));
500 while (
write(master, buf,
sizeof(buf)) > 0) ;
504 while (((n =
read(slave, buf,
sizeof(buf))) > 0) &&
510 pty_output_sigio = 1;
517 static void tty_close(
int master,
int slave)
530 static void __init check_sigio(
void)
532 if ((
access(
"/dev/ptmx", R_OK) < 0) &&
533 (
access(
"/dev/ptyp0", R_OK) < 0)) {
535 "skipping pty SIGIO check\n");
538 check_one_sigio(tty_output);
539 check_one_sigio(tty_close);