2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
14 #include <sys/socket.h>
15 #include "kern_util.h"
16 #include "chan_user.h"
18 #include "user_util.h"
34 /* Not static because it's called directly by the tt mode gdb code */
35 void *xterm_init(char *str
, int device
, struct chan_opts
*opts
)
37 struct xterm_chan
*data
;
39 data
= malloc(sizeof(*data
));
40 if(data
== NULL
) return(NULL
);
41 *data
= ((struct xterm_chan
) { .pid
= -1,
44 .title
= opts
->xterm_title
,
46 .stack
= opts
->tramp_stack
,
47 .direct_rcv
= !opts
->in_kernel
} );
51 /* Only changed by xterm_setup, which is a setup */
52 static char *terminal_emulator
= "xterm";
53 static char *title_switch
= "-T";
54 static char *exec_switch
= "-e";
56 static int __init
xterm_setup(char *line
, int *add
)
59 terminal_emulator
= line
;
61 line
= strchr(line
, ',');
62 if(line
== NULL
) return(0);
64 if(*line
) title_switch
= line
;
66 line
= strchr(line
, ',');
67 if(line
== NULL
) return(0);
69 if(*line
) exec_switch
= line
;
74 __uml_setup("xterm=", xterm_setup
,
75 "xterm=<terminal emulator>,<title switch>,<exec switch>\n"
76 " Specifies an alternate terminal emulator to use for the debugger,\n"
77 " consoles, and serial lines when they are attached to the xterm channel.\n"
78 " The values are the terminal emulator binary, the switch it uses to set\n"
79 " its title, and the switch it uses to execute a subprocess,\n"
80 " respectively. The title switch must have the form '<switch> title',\n"
81 " not '<switch>=title'. Similarly, the exec switch must have the form\n"
82 " '<switch> command arg1 arg2 ...'.\n"
83 " The default values are 'xterm=xterm,-T,-e'. Values for gnome-terminal\n"
84 " are 'xterm=gnome-terminal,-t,-x'.\n\n"
87 /* XXX This badly needs some cleaning up in the error paths
88 * Not static because it's called directly by the tt mode gdb code
90 int xterm_open(int input
, int output
, int primary
, void *d
,
93 struct xterm_chan
*data
= d
;
95 int pid
, fd
, new, err
;
96 char title
[256], file
[] = "/tmp/xterm-pipeXXXXXX";
97 char *argv
[] = { terminal_emulator
, title_switch
, title
, exec_switch
,
98 "/usr/lib/uml/port-helper", "-uml-socket",
101 if(os_access(argv
[4], OS_ACC_X_OK
) < 0)
102 argv
[4] = "port-helper";
104 /* Check that DISPLAY is set, this doesn't guarantee the xterm
105 * will work but w/o it we can be pretty sure it won't. */
106 if (!getenv("DISPLAY")) {
107 printk("xterm_open: $DISPLAY not set.\n");
113 printk("xterm_open : mkstemp failed, errno = %d\n", errno
);
118 printk("xterm_open : unlink failed, errno = %d\n", errno
);
123 fd
= os_create_unix_socket(file
, sizeof(file
), 1);
125 printk("xterm_open : create_unix_socket failed, errno = %d\n",
130 sprintf(title
, data
->title
, data
->device
);
132 pid
= run_helper(NULL
, NULL
, argv
, &stack
);
134 printk("xterm_open : run_helper failed, errno = %d\n", -pid
);
138 if(data
->stack
== 0) free_stack(stack
, 0);
140 if (data
->direct_rcv
) {
141 new = os_rcv_fd(fd
, &data
->helper_pid
);
143 err
= os_set_fd_block(fd
, 0);
145 printk("xterm_open : failed to set descriptor "
146 "non-blocking, err = %d\n", -err
);
149 new = xterm_fd(fd
, &data
->helper_pid
);
152 printk("xterm_open : os_rcv_fd failed, err = %d\n", -new);
156 CATCH_EINTR(err
= tcgetattr(new, &data
->tt
));
177 /* Not static because it's called directly by the tt mode gdb code */
178 void xterm_close(int fd
, void *d
)
180 struct xterm_chan
*data
= d
;
183 os_kill_process(data
->pid
, 1);
185 if(data
->helper_pid
!= -1)
186 os_kill_process(data
->helper_pid
, 0);
187 data
->helper_pid
= -1;
191 static void xterm_free(void *d
)
196 static int xterm_console_write(int fd
, const char *buf
, int n
, void *d
)
198 struct xterm_chan
*data
= d
;
200 return(generic_console_write(fd
, buf
, n
, &data
->tt
));
203 struct chan_ops xterm_ops
= {
207 .close
= xterm_close
,
208 .read
= generic_read
,
209 .write
= generic_write
,
210 .console_write
= xterm_console_write
,
211 .window_size
= generic_window_size
,
217 * Overrides for Emacs so that we follow Linus's tabbing style.
218 * Emacs will notice this stuff at the end of the file and automatically
219 * adjust the settings for this buffer only. This must remain at the end
221 * ---------------------------------------------------------------------------
223 * c-file-style: "linux"