VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
97870c34b4532 arch/um/os-Linux/sigio.c    (Alex Dewar                     2019-08-25 10:49:18 +0100   1) // SPDX-License-Identifier: GPL-2.0
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800   2) /*
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700   3)  * Copyright (C) 2002 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700   4)  */
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700   5) 
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700   6) #include <unistd.h>
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800   7) #include <errno.h>
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800   8) #include <fcntl.h>
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800   9) #include <poll.h>
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  10) #include <pty.h>
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  11) #include <sched.h>
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  12) #include <signal.h>
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  13) #include <string.h>
37185b3324087 arch/um/os-Linux/sigio.c    (Al Viro                        2012-10-08 03:27:32 +0100  14) #include <kern_util.h>
37185b3324087 arch/um/os-Linux/sigio.c    (Al Viro                        2012-10-08 03:27:32 +0100  15) #include <init.h>
37185b3324087 arch/um/os-Linux/sigio.c    (Al Viro                        2012-10-08 03:27:32 +0100  16) #include <os.h>
37185b3324087 arch/um/os-Linux/sigio.c    (Al Viro                        2012-10-08 03:27:32 +0100  17) #include <sigio.h>
37185b3324087 arch/um/os-Linux/sigio.c    (Al Viro                        2012-10-08 03:27:32 +0100  18) #include <um_malloc.h>
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  19) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  20) /*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  21)  * Protected by sigio_lock(), also used by sigio_cleanup, which is an
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  22)  * exitcall.
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  23)  */
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  24) static int write_sigio_pid = -1;
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700  25) static unsigned long write_sigio_stack;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  26) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  27) /*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  28)  * These arrays are initialized before the sigio thread is started, and
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  29)  * the descriptors closed after it is killed.  So, it can't see them change.
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  30)  * On the UML side, they are changed under the sigio_lock.
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  31)  */
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800  32) #define SIGIO_FDS_INIT {-1, -1}
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800  33) 
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800  34) static int write_sigio_fds[2] = SIGIO_FDS_INIT;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800  35) static int sigio_private[2] = SIGIO_FDS_INIT;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  36) 
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  37) struct pollfds {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  38) 	struct pollfd *poll;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  39) 	int size;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  40) 	int used;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  41) };
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  42) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  43) /*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  44)  * Protected by sigio_lock().  Used by the sigio thread, but the UML thread
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  45)  * synchronizes with it.
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  46)  */
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700  47) static struct pollfds current_poll;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700  48) static struct pollfds next_poll;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700  49) static struct pollfds all_sigio_fds;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  50) 
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  51) static int write_sigio_thread(void *unused)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  52) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  53) 	struct pollfds *fds, tmp;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  54) 	struct pollfd *p;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  55) 	int i, n, respond_fd;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  56) 	char c;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  57) 
91d44ff860a9e arch/um/os-Linux/sigio.c    (Richard Weinberger             2013-08-18 13:30:08 +0200  58) 	os_fix_helper_signals();
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  59) 	fds = &current_poll;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  60) 	while (1) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  61) 		n = poll(fds->poll, fds->used, -1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  62) 		if (n < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  63) 			if (errno == EINTR)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  64) 				continue;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  65) 			printk(UM_KERN_ERR "write_sigio_thread : poll returned "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  66) 			       "%d, errno = %d\n", n, errno);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  67) 		}
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  68) 		for (i = 0; i < fds->used; i++) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  69) 			p = &fds->poll[i];
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  70) 			if (p->revents == 0)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  71) 				continue;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  72) 			if (p->fd == sigio_private[1]) {
a61f334fd2864 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:35 -0700  73) 				CATCH_EINTR(n = read(sigio_private[1], &c,
a61f334fd2864 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:35 -0700  74) 						     sizeof(c)));
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  75) 				if (n != sizeof(c))
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  76) 					printk(UM_KERN_ERR
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  77) 					       "write_sigio_thread : "
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700  78) 					       "read on socket failed, "
a61f334fd2864 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:35 -0700  79) 					       "err = %d\n", errno);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  80) 				tmp = current_poll;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  81) 				current_poll = next_poll;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  82) 				next_poll = tmp;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  83) 				respond_fd = sigio_private[1];
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  84) 			}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  85) 			else {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  86) 				respond_fd = write_sigio_fds[1];
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  87) 				fds->used--;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  88) 				memmove(&fds->poll[i], &fds->poll[i + 1],
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  89) 					(fds->used - i) * sizeof(*fds->poll));
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  90) 			}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  91) 
a61f334fd2864 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:35 -0700  92) 			CATCH_EINTR(n = write(respond_fd, &c, sizeof(c)));
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  93) 			if (n != sizeof(c))
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  94) 				printk(UM_KERN_ERR "write_sigio_thread : "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  95) 				       "write on socket failed, err = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800  96) 				       errno);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  97) 		}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700  98) 	}
1b57e9c27882a arch/um/kernel/sigio_user.c (Jeff Dike                      2006-01-06 00:18:49 -0800  99) 
1b57e9c27882a arch/um/kernel/sigio_user.c (Jeff Dike                      2006-01-06 00:18:49 -0800 100) 	return 0;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 101) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 102) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 103) static int need_poll(struct pollfds *polls, int n)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 104) {
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 105) 	struct pollfd *new;
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 106) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 107) 	if (n <= polls->size)
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 108) 		return 0;
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 109) 
43f5b3085fdd2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:52 -0700 110) 	new = uml_kmalloc(n * sizeof(struct pollfd), UM_GFP_ATOMIC);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 111) 	if (new == NULL) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 112) 		printk(UM_KERN_ERR "need_poll : failed to allocate new "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 113) 		       "pollfds\n");
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 114) 		return -ENOMEM;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 115) 	}
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 116) 
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 117) 	memcpy(new, polls->poll, polls->used * sizeof(struct pollfd));
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 118) 	kfree(polls->poll);
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 119) 
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 120) 	polls->poll = new;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 121) 	polls->size = n;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 122) 	return 0;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 123) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 124) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 125) /*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 126)  * Must be called with sigio_lock held, because it's needed by the marked
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 127)  * critical section.
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 128)  */
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 129) static void update_thread(void)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 130) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 131) 	unsigned long flags;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 132) 	int n;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 133) 	char c;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 134) 
0dafcbe128d2a arch/um/os-Linux/sigio.c    (Johannes Berg                  2019-08-23 13:16:23 +0200 135) 	flags = set_signals_trace(0);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 136) 	CATCH_EINTR(n = write(sigio_private[0], &c, sizeof(c)));
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 137) 	if (n != sizeof(c)) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 138) 		printk(UM_KERN_ERR "update_thread : write failed, err = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 139) 		       errno);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 140) 		goto fail;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 141) 	}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 142) 
a61f334fd2864 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:35 -0700 143) 	CATCH_EINTR(n = read(sigio_private[0], &c, sizeof(c)));
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 144) 	if (n != sizeof(c)) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 145) 		printk(UM_KERN_ERR "update_thread : read failed, err = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 146) 		       errno);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 147) 		goto fail;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 148) 	}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 149) 
0dafcbe128d2a arch/um/os-Linux/sigio.c    (Johannes Berg                  2019-08-23 13:16:23 +0200 150) 	set_signals_trace(flags);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 151) 	return;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 152)  fail:
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 153) 	/* Critical section start */
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 154) 	if (write_sigio_pid != -1) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 155) 		os_kill_process(write_sigio_pid, 1);
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 156) 		free_stack(write_sigio_stack, 0);
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 157) 	}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 158) 	write_sigio_pid = -1;
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 159) 	close(sigio_private[0]);
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 160) 	close(sigio_private[1]);
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 161) 	close(write_sigio_fds[0]);
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 162) 	close(write_sigio_fds[1]);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 163) 	/* Critical section end */
0dafcbe128d2a arch/um/os-Linux/sigio.c    (Johannes Berg                  2019-08-23 13:16:23 +0200 164) 	set_signals_trace(flags);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 165) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 166) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 167) int __add_sigio_fd(int fd)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 168) {
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 169) 	struct pollfd *p;
d66c91836b8d7 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-11-23 20:44:02 +0100 170) 	int err, i, n;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 171) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 172) 	for (i = 0; i < all_sigio_fds.used; i++) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 173) 		if (all_sigio_fds.poll[i].fd == fd)
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 174) 			break;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 175) 	}
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 176) 	if (i == all_sigio_fds.used)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 177) 		return -ENOSPC;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 178) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 179) 	p = &all_sigio_fds.poll[i];
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 180) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 181) 	for (i = 0; i < current_poll.used; i++) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 182) 		if (current_poll.poll[i].fd == fd)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 183) 			return 0;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 184) 	}
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 185) 
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 186) 	n = current_poll.used;
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 187) 	err = need_poll(&next_poll, n + 1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 188) 	if (err)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 189) 		return err;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 190) 
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 191) 	memcpy(next_poll.poll, current_poll.poll,
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 192) 	       current_poll.used * sizeof(struct pollfd));
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 193) 	next_poll.poll[n] = *p;
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 194) 	next_poll.used = n + 1;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 195) 	update_thread();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 196) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 197) 	return 0;
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 198) }
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 199) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 200) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 201) int add_sigio_fd(int fd)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 202) {
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 203) 	int err;
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 204) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 205) 	sigio_lock();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 206) 	err = __add_sigio_fd(fd);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 207) 	sigio_unlock();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 208) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 209) 	return err;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 210) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 211) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 212) int __ignore_sigio_fd(int fd)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 213) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 214) 	struct pollfd *p;
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 215) 	int err, i, n = 0;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 216) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 217) 	/*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 218) 	 * This is called from exitcalls elsewhere in UML - if
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 219) 	 * sigio_cleanup has already run, then update_thread will hang
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 220) 	 * or fail because the thread is no longer running.
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 221) 	 */
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 222) 	if (write_sigio_pid == -1)
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 223) 		return -EIO;
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 224) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 225) 	for (i = 0; i < current_poll.used; i++) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 226) 		if (current_poll.poll[i].fd == fd)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 227) 			break;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 228) 	}
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 229) 	if (i == current_poll.used)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 230) 		return -ENOENT;
f206aabb03531 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:33 -0800 231) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 232) 	err = need_poll(&next_poll, current_poll.used - 1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 233) 	if (err)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 234) 		return err;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 235) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 236) 	for (i = 0; i < current_poll.used; i++) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 237) 		p = &current_poll.poll[i];
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 238) 		if (p->fd != fd)
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 239) 			next_poll.poll[n++] = *p;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 240) 	}
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 241) 	next_poll.used = current_poll.used - 1;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 242) 
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 243) 	update_thread();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 244) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 245) 	return 0;
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 246) }
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 247) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 248) int ignore_sigio_fd(int fd)
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 249) {
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 250) 	int err;
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 251) 
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 252) 	sigio_lock();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 253) 	err = __ignore_sigio_fd(fd);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 254) 	sigio_unlock();
cae20ba0a16cd arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-11 10:56:07 +0100 255) 
61232f2fe44f7 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 256) 	return err;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 257) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 258) 
f206aabb03531 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:33 -0800 259) static struct pollfd *setup_initial_poll(int fd)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 260) {
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 261) 	struct pollfd *p;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 262) 
43f5b3085fdd2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:52 -0700 263) 	p = uml_kmalloc(sizeof(struct pollfd), UM_GFP_KERNEL);
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 264) 	if (p == NULL) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 265) 		printk(UM_KERN_ERR "setup_initial_poll : failed to allocate "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 266) 		       "poll\n");
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 267) 		return NULL;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 268) 	}
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 269) 	*p = ((struct pollfd) { .fd		= fd,
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 270) 				.events 	= POLLIN,
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 271) 				.revents 	= 0 });
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 272) 	return p;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 273) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 274) 
8e64d96aeb495 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 275) static void write_sigio_workaround(void)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 276) {
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 277) 	struct pollfd *p;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 278) 	int err;
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 279) 	int l_write_sigio_fds[2];
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 280) 	int l_sigio_private[2];
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 281) 	int l_write_sigio_pid;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 282) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 283) 	/* We call this *tons* of times - and most ones we must just fail. */
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 284) 	sigio_lock();
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 285) 	l_write_sigio_pid = write_sigio_pid;
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 286) 	sigio_unlock();
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 287) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 288) 	if (l_write_sigio_pid != -1)
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 289) 		return;
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 290) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 291) 	err = os_pipe(l_write_sigio_fds, 1, 1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 292) 	if (err < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 293) 		printk(UM_KERN_ERR "write_sigio_workaround - os_pipe 1 failed, "
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 294) 		       "err = %d\n", -err);
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 295) 		return;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 296) 	}
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 297) 	err = os_pipe(l_sigio_private, 1, 1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 298) 	if (err < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 299) 		printk(UM_KERN_ERR "write_sigio_workaround - os_pipe 2 failed, "
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 300) 		       "err = %d\n", -err);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 301) 		goto out_close1;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 302) 	}
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 303) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 304) 	p = setup_initial_poll(l_sigio_private[1]);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 305) 	if (!p)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 306) 		goto out_close2;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 307) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 308) 	sigio_lock();
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 309) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 310) 	/*
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 311) 	 * Did we race? Don't try to optimize this, please, it's not so likely
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 312) 	 * to happen, and no more than once at the boot.
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 313) 	 */
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 314) 	if (write_sigio_pid != -1)
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 315) 		goto out_free;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 316) 
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 317) 	current_poll = ((struct pollfds) { .poll 	= p,
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 318) 					   .used 	= 1,
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 319) 					   .size 	= 1 });
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 320) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 321) 	if (write_sigio_irq(l_write_sigio_fds[0]))
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 322) 		goto out_clear_poll;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 323) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 324) 	memcpy(write_sigio_fds, l_write_sigio_fds, sizeof(l_write_sigio_fds));
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 325) 	memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 326) 
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 327) 	write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 328) 					    CLONE_FILES | CLONE_VM,
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 329) 					    &write_sigio_stack);
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 330) 
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 331) 	if (write_sigio_pid < 0)
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 332) 		goto out_clear;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 333) 
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 334) 	sigio_unlock();
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 335) 	return;
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 336) 
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 337) out_clear:
b6a2b13778873 arch/um/kernel/sigio_user.c (Paolo 'Blaisorblade' Giarrusso 2006-01-18 17:42:57 -0800 338) 	write_sigio_pid = -1;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 339) 	write_sigio_fds[0] = -1;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 340) 	write_sigio_fds[1] = -1;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 341) 	sigio_private[0] = -1;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 342) 	sigio_private[1] = -1;
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 343) out_clear_poll:
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 344) 	current_poll = ((struct pollfds) { .poll	= NULL,
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 345) 					   .size	= 0,
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 346) 					   .used	= 0 });
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 347) out_free:
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 348) 	sigio_unlock();
e6fb54abb8a36 arch/um/os-Linux/sigio.c    (Paolo 'Blaisorblade' Giarrusso 2006-04-10 22:53:36 -0700 349) 	kfree(p);
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 350) out_close2:
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 351) 	close(l_sigio_private[0]);
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 352) 	close(l_sigio_private[1]);
5f4e8fd08f399 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-03-27 01:14:40 -0800 353) out_close1:
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 354) 	close(l_write_sigio_fds[0]);
8e367065eea04 arch/um/kernel/sigio_user.c (Jeff Dike                      2006-03-27 01:14:32 -0800 355) 	close(l_write_sigio_fds[1]);
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 356) }
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 357) 
2fccfcc0c7426 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-02 12:59:55 +0100 358) void sigio_broken(int fd)
8e64d96aeb495 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 359) {
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 360) 	int err;
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 361) 
8e64d96aeb495 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 362) 	write_sigio_workaround();
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 363) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 364) 	sigio_lock();
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 365) 	err = need_poll(&all_sigio_fds, all_sigio_fds.used + 1);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 366) 	if (err) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 367) 		printk(UM_KERN_ERR "maybe_sigio_broken - failed to add pollfd "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 368) 		       "for descriptor %d\n", fd);
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 369) 		goto out;
04a51e66adcdc arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-28 20:13:11 -0800 370) 	}
838e56a11cdb2 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-02-16 01:27:21 -0800 371) 
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 372) 	all_sigio_fds.poll[all_sigio_fds.used++] =
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 373) 		((struct pollfd) { .fd  	= fd,
2fccfcc0c7426 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-02 12:59:55 +0100 374) 				   .events 	= POLLIN,
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 375) 				   .revents 	= 0 });
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 376) out:
19bdf0409f25a arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-09-25 23:33:04 -0700 377) 	sigio_unlock();
8e64d96aeb495 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 378) }
8e64d96aeb495 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:11 -0700 379) 
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 380) /* Changed during early boot */
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 381) static int pty_output_sigio;
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 382) 
2fccfcc0c7426 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-02 12:59:55 +0100 383) void maybe_sigio_broken(int fd)
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 384) {
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 385) 	if (!isatty(fd))
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 386) 		return;
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 387) 
2fccfcc0c7426 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-02 12:59:55 +0100 388) 	if (pty_output_sigio)
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 389) 		return;
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 390) 
2fccfcc0c7426 arch/um/os-Linux/sigio.c    (Johannes Berg                  2020-12-02 12:59:55 +0100 391) 	sigio_broken(fd);
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 392) }
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 393) 
29ac1c2142346 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:12 -0700 394) static void sigio_cleanup(void)
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 395) {
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 396) 	if (write_sigio_pid == -1)
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 397) 		return;
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 398) 
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 399) 	os_kill_process(write_sigio_pid, 1);
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 400) 	free_stack(write_sigio_stack, 0);
c43990162fc7f arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-07-15 23:38:56 -0700 401) 	write_sigio_pid = -1;
^1da177e4c3f4 arch/um/kernel/sigio_user.c (Linus Torvalds                 2005-04-16 15:20:36 -0700 402) }
29ac1c2142346 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:12 -0700 403) 
29ac1c2142346 arch/um/os-Linux/sigio.c    (Jeff Dike                      2006-07-10 04:45:12 -0700 404) __uml_exitcall(sigio_cleanup);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 405) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 406) /* Used as a flag during SIGIO testing early in boot */
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 407) static int got_sigio;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 408) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 409) static void __init handler(int sig)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 410) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 411) 	got_sigio = 1;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 412) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 413) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 414) struct openpty_arg {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 415) 	int master;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 416) 	int slave;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 417) 	int err;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 418) };
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 419) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 420) static void openpty_cb(void *arg)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 421) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 422) 	struct openpty_arg *info = arg;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 423) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 424) 	info->err = 0;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 425) 	if (openpty(&info->master, &info->slave, NULL, NULL, NULL))
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 426) 		info->err = -errno;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 427) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 428) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 429) static int async_pty(int master, int slave)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 430) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 431) 	int flags;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 432) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 433) 	flags = fcntl(master, F_GETFL);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 434) 	if (flags < 0)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 435) 		return -errno;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 436) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 437) 	if ((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 438) 	    (fcntl(master, F_SETOWN, os_getpid()) < 0))
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 439) 		return -errno;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 440) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 441) 	if ((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 442) 		return -errno;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 443) 
c0a9290ecf0db arch/um/os-Linux/sigio.c    (WANG Cong                      2008-02-04 22:30:41 -0800 444) 	return 0;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 445) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 446) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 447) static void __init check_one_sigio(void (*proc)(int, int))
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 448) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 449) 	struct sigaction old, new;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 450) 	struct openpty_arg pty = { .master = -1, .slave = -1 };
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 451) 	int master, slave, err;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 452) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 453) 	initial_thread_cb(openpty_cb, &pty);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 454) 	if (pty.err) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 455) 		printk(UM_KERN_ERR "check_one_sigio failed, errno = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 456) 		       -pty.err);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 457) 		return;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 458) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 459) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 460) 	master = pty.master;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 461) 	slave = pty.slave;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 462) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 463) 	if ((master == -1) || (slave == -1)) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 464) 		printk(UM_KERN_ERR "check_one_sigio failed to allocate a "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 465) 		       "pty\n");
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 466) 		return;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 467) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 468) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 469) 	/* Not now, but complain so we now where we failed. */
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 470) 	err = raw(master);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 471) 	if (err < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 472) 		printk(UM_KERN_ERR "check_one_sigio : raw failed, errno = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 473) 		      -err);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 474) 		return;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 475) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 476) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 477) 	err = async_pty(master, slave);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 478) 	if (err < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 479) 		printk(UM_KERN_ERR "check_one_sigio : sigio_async failed, "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 480) 		       "err = %d\n", -err);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 481) 		return;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 482) 	}
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 483) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 484) 	if (sigaction(SIGIO, NULL, &old) < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 485) 		printk(UM_KERN_ERR "check_one_sigio : sigaction 1 failed, "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 486) 		       "errno = %d\n", errno);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 487) 		return;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 488) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 489) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 490) 	new = old;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 491) 	new.sa_handler = handler;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 492) 	if (sigaction(SIGIO, &new, NULL) < 0) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 493) 		printk(UM_KERN_ERR "check_one_sigio : sigaction 2 failed, "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 494) 		       "errno = %d\n", errno);
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 495) 		return;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 496) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 497) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 498) 	got_sigio = 0;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 499) 	(*proc)(master, slave);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 500) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 501) 	close(master);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 502) 	close(slave);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 503) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 504) 	if (sigaction(SIGIO, &old, NULL) < 0)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 505) 		printk(UM_KERN_ERR "check_one_sigio : sigaction 3 failed, "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 506) 		       "errno = %d\n", errno);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 507) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 508) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 509) static void tty_output(int master, int slave)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 510) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 511) 	int n;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 512) 	char buf[512];
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 513) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 514) 	printk(UM_KERN_INFO "Checking that host ptys support output SIGIO...");
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 515) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 516) 	memset(buf, 0, sizeof(buf));
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 517) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 518) 	while (write(master, buf, sizeof(buf)) > 0) ;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 519) 	if (errno != EAGAIN)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 520) 		printk(UM_KERN_ERR "tty_output : write failed, errno = %d\n",
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 521) 		       errno);
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 522) 	while (((n = read(slave, buf, sizeof(buf))) > 0) &&
5d33e4d7fd9a5 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-05-12 14:01:58 -0700 523) 	       !({ barrier(); got_sigio; }))
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 524) 		;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 525) 
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 526) 	if (got_sigio) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 527) 		printk(UM_KERN_CONT "Yes\n");
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 528) 		pty_output_sigio = 1;
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 529) 	} else if (n == -EAGAIN)
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 530) 		printk(UM_KERN_CONT "No, enabling workaround\n");
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 531) 	else
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 532) 		printk(UM_KERN_CONT "tty_output : read failed, err = %d\n", n);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 533) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 534) 
99764fa4ceeec arch/um/os-Linux/sigio.c    (WANG Cong                      2008-07-23 21:28:49 -0700 535) static void __init check_sigio(void)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 536) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 537) 	if ((access("/dev/ptmx", R_OK) < 0) &&
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 538) 	    (access("/dev/ptyp0", R_OK) < 0)) {
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 539) 		printk(UM_KERN_WARNING "No pseudo-terminals available - "
fee64d3c153f1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2008-02-04 22:31:02 -0800 540) 		       "skipping pty SIGIO check\n");
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 541) 		return;
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 542) 	}
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 543) 	check_one_sigio(tty_output);
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 544) }
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 545) 
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 546) /* Here because it only does the SIGIO testing for now */
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 547) void __init os_check_bugs(void)
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 548) {
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 549) 	check_sigio();
c65badbdf5dc1 arch/um/os-Linux/sigio.c    (Jeff Dike                      2007-05-06 14:51:06 -0700 550) }