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"
17 #include "user_util.h"
33 /* Not static because it's called directly by the tt mode gdb code */
34 void *xterm_init(char *str, int device, struct chan_opts *opts)
36 struct xterm_chan *data;
38 data = malloc(sizeof(*data));
39 if(data == NULL) return(NULL);
40 *data = ((struct xterm_chan) { .pid = -1,
43 .title = opts->xterm_title,
45 .stack = opts->tramp_stack,
46 .direct_rcv = !opts->in_kernel } );
50 /* Only changed by xterm_setup, which is a setup */
51 static char *terminal_emulator = "xterm";
52 static char *title_switch = "-T";
53 static char *exec_switch = "-e";
55 static int __init xterm_setup(char *line, int *add)
58 terminal_emulator = line;
60 line = strchr(line, ',');
61 if(line == NULL) return(0);
63 if(*line) title_switch = line;
65 line = strchr(line, ',');
66 if(line == NULL) return(0);
68 if(*line) exec_switch = line;
73 __uml_setup("xterm=", xterm_setup,
74 "xterm=<terminal emulator>,<title switch>,<exec switch>\n"
75 " Specifies an alternate terminal emulator to use for the debugger,\n"
76 " consoles, and serial lines when they are attached to the xterm channel.\n"
77 " The values are the terminal emulator binary, the switch it uses to set\n"
78 " its title, and the switch it uses to execute a subprocess,\n"
79 " respectively. The title switch must have the form '<switch> title',\n"
80 " not '<switch>=title'. Similarly, the exec switch must have the form\n"
81 " '<switch> command arg1 arg2 ...'.\n"
82 " The default values are 'xterm=xterm,-T,-e'. Values for gnome-terminal\n"
83 " are 'xterm=gnome-terminal,-t,-x'.\n\n"
86 /* XXX This badly needs some cleaning up in the error paths
87 * Not static because it's called directly by the tt mode gdb code
89 int xterm_open(int input, int output, int primary, void *d,
92 struct xterm_chan *data = d;
94 int pid, fd, new, err;
95 char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
96 char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
97 "/usr/lib/uml/port-helper", "-uml-socket",
100 if(os_access(argv[4], OS_ACC_X_OK) < 0)
101 argv[4] = "port-helper";
103 /* Check that DISPLAY is set, this doesn't guarantee the xterm
104 * will work but w/o it we can be pretty sure it won't. */
105 if (!getenv("DISPLAY")) {
106 printk("xterm_open: $DISPLAY not set.\n");
113 printk("xterm_open : mkstemp failed, errno = %d\n", errno);
119 printk("xterm_open : unlink failed, errno = %d\n", errno);
124 fd = os_create_unix_socket(file, sizeof(file), 1);
126 printk("xterm_open : create_unix_socket failed, errno = %d\n",
131 sprintf(title, data->title, data->device);
133 pid = run_helper(NULL, NULL, argv, &stack);
135 printk("xterm_open : run_helper failed, errno = %d\n", -pid);
139 if(data->stack == 0) free_stack(stack, 0);
141 if (data->direct_rcv) {
142 new = os_rcv_fd(fd, &data->helper_pid);
144 err = os_set_fd_block(fd, 0);
146 printk("xterm_open : failed to set descriptor "
147 "non-blocking, err = %d\n", -err);
150 new = xterm_fd(fd, &data->helper_pid);
153 printk("xterm_open : os_rcv_fd failed, err = %d\n", -new);
157 CATCH_EINTR(err = tcgetattr(new, &data->tt));
178 /* Not static because it's called directly by the tt mode gdb code */
179 void xterm_close(int fd, void *d)
181 struct xterm_chan *data = d;
184 os_kill_process(data->pid, 1);
186 if(data->helper_pid != -1)
187 os_kill_process(data->helper_pid, 0);
188 data->helper_pid = -1;
192 static void xterm_free(void *d)
197 static int xterm_console_write(int fd, const char *buf, int n, void *d)
199 struct xterm_chan *data = d;
201 return(generic_console_write(fd, buf, n, &data->tt));
204 struct chan_ops xterm_ops = {
208 .close = xterm_close,
209 .read = generic_read,
210 .write = generic_write,
211 .console_write = xterm_console_write,
212 .window_size = generic_window_size,
218 * Overrides for Emacs so that we follow Linus's tabbing style.
219 * Emacs will notice this stuff at the end of the file and automatically
220 * adjust the settings for this buffer only. This must remain at the end
222 * ---------------------------------------------------------------------------
224 * c-file-style: "linux"