Version:
~ [ 0.6-2.3.46 ] ~
Architecture:
~ [ um ] ~
** Warning: Cannot open xref database.
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <signal.h>
4 #include <sched.h>
5 #include <errno.h>
6 #include <termios.h>
7 #include <fcntl.h>
8 #include <sys/select.h>
9 #include "stdio_console.h"
10 #include "user_util.h"
11 #include "kern_util.h"
12 #include "user.h"
13
14 void stdio_write(int fd, const char *string, int len)
15 {
16 static int need_cr = 0;
17 int i;
18
19 for(i=0;i<len;i++){
20 if(*string == '\n') need_cr = 1;
21 else if(need_cr){
22 if(*string != '\r') write(fd, "\r", 1);
23 need_cr = 0;
24 }
25 write(fd, string++, 1);
26 }
27 }
28
29 void stdio_rcv_proc(int fd)
30 {
31 int n;
32 char ch;
33
34 if((n = read(fd, &ch, sizeof(ch))) < 0){
35 if(errno != EAGAIN)
36 printk("stdio_rcv_proc read failed, errno = %d\n", errno);
37 return;
38 }
39 stdio_receive_char(fd, ch);
40 }
41
42 void setup_fd(int fd)
43 {
44 struct termios tt;
45 unsigned long flags;
46
47 if(fcntl(fd, F_GETFL, &flags) < 0){
48 perror("fcntl getting flags");
49 return;
50 }
51 flags |= O_NDELAY;
52 if(fcntl(fd, F_SETFL, &flags) < 0){
53 perror("fcntl setting flags");
54 return;
55 }
56 tcgetattr(fd, &tt);
57 cfmakeraw(&tt);
58 if(tcsetattr(fd, TCSADRAIN, &tt) < 0){
59 printk("tcsetattr failed, errno = %d\n", errno);
60 panic("stdio receive thread couldn't set fd raw");
61 }
62 }
63
64 static int about_to_exec = 0;
65
66 static int xterm_tramp(void *arg)
67 {
68 char **args;
69
70 args = arg;
71 about_to_exec = 1;
72 execlp("xterm", "xterm", args[0], "-T", args[1], NULL);
73 return(-1);
74 }
75
76 int open_vt(int n)
77 {
78 unsigned long stack;
79 int master, slave, pid;
80 char title[sizeof("Virtual Console nn\0")], dev[] = "/dev/ptyXX";
81 char flag[sizeof("Sxxnn\0")], *args[2], c;
82
83 master = getmaster(dev);
84 dev[strlen("/dev/")] = 't';
85 slave = open(dev, O_RDWR);
86 if(slave != -1){
87 sprintf(title, "Virtual Console %d", n);
88 sprintf(flag, "-S%c%c%d", dev[strlen("/dev/pty")],
89 dev[strlen("/dev/ptyX")], master);
90 stack = alloc_stack();
91 args[0] = &flag[0];
92 args[1] = &title[0];
93 pid = clone(xterm_tramp, (void *) stack_sp(stack), SIGCHLD, args);
94 register_pid(pid, 0);
95 while((read(slave, &c, sizeof(c)) == sizeof(c)) && (c != '\n')) ;
96 if(!about_to_exec) panic("Freeing stack too soon in open_vt");
97 about_to_exec = 0;
98 free_stack(stack);
99 }
100 setup_fd(slave);
101 return(slave);
102 }
103
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.