#include <unistd.h>
#include <string.h>
#include <errno.h>
-#include <fcntl.h>
#include <termios.h>
#include <signal.h>
#include <sched.h>
#include <sys/socket.h>
#include "kern_util.h"
#include "chan_user.h"
-#include "helper.h"
#include "user_util.h"
#include "user.h"
#include "os.h"
int direct_rcv;
};
-void *xterm_init(char *str, int device, struct chan_opts *opts)
+/* Not static because it's called directly by the tt mode gdb code */
+void *xterm_init(char *str, int device, const struct chan_opts *opts)
{
struct xterm_chan *data;
- if((data = malloc(sizeof(*data))) == NULL) return(NULL);
+ data = malloc(sizeof(*data));
+ if(data == NULL) return(NULL);
*data = ((struct xterm_chan) { .pid = -1,
.helper_pid = -1,
.device = device,
" are 'xterm=gnome-terminal,-t,-x'.\n\n"
);
-int xterm_open(int input, int output, int primary, void *d, char **dev_out)
+/* XXX This badly needs some cleaning up in the error paths
+ * Not static because it's called directly by the tt mode gdb code
+ */
+int xterm_open(int input, int output, int primary, void *d,
+ char **dev_out)
{
struct xterm_chan *data = d;
unsigned long stack;
"/usr/lib/uml/port-helper", "-uml-socket",
file, NULL };
- if(access(argv[4], X_OK))
+ if(os_access(argv[4], OS_ACC_X_OK) < 0)
argv[4] = "port-helper";
+ /* Check that DISPLAY is set, this doesn't guarantee the xterm
+ * will work but w/o it we can be pretty sure it won't. */
+ if (!getenv("DISPLAY")) {
+ printk("xterm_open: $DISPLAY not set.\n");
+ return -ENODEV;
+ }
+
fd = mkstemp(file);
if(fd < 0){
+ err = -errno;
printk("xterm_open : mkstemp failed, errno = %d\n", errno);
- return(-errno);
+ return err;
}
if(unlink(file)){
+ err = -errno;
printk("xterm_open : unlink failed, errno = %d\n", errno);
- return(-errno);
+ return err;
}
- close(fd);
+ os_close_file(fd);
- fd = create_unix_socket(file, sizeof(file));
+ fd = os_create_unix_socket(file, sizeof(file), 1);
if(fd < 0){
printk("xterm_open : create_unix_socket failed, errno = %d\n",
-fd);
- return(-fd);
+ return(fd);
}
sprintf(title, data->title, data->device);
return(pid);
}
- if(data->stack == 0) free_stack(stack, 0);
-
- if(data->direct_rcv)
+ if (data->direct_rcv) {
new = os_rcv_fd(fd, &data->helper_pid);
- else {
- if((err = os_set_fd_block(fd, 0)) != 0){
+ } else {
+ err = os_set_fd_block(fd, 0);
+ if(err < 0){
printk("xterm_open : failed to set descriptor "
- "non-blocking, errno = %d\n", err);
+ "non-blocking, err = %d\n", -err);
return(err);
}
new = xterm_fd(fd, &data->helper_pid);
}
if(new < 0){
- printk("xterm_open : os_rcv_fd failed, errno = %d\n", -new);
+ printk("xterm_open : os_rcv_fd failed, err = %d\n", -new);
+ goto out;
+ }
+
+ CATCH_EINTR(err = tcgetattr(new, &data->tt));
+ if(err){
+ new = err;
goto out;
}
- tcgetattr(new, &data->tt);
- if(data->raw) raw(new, 0);
+ if(data->raw){
+ err = raw(new);
+ if(err){
+ new = err;
+ goto out;
+ }
+ }
data->pid = pid;
*dev_out = NULL;
return(new);
}
+/* Not static because it's called directly by the tt mode gdb code */
void xterm_close(int fd, void *d)
{
struct xterm_chan *data = d;
if(data->helper_pid != -1)
os_kill_process(data->helper_pid, 0);
data->helper_pid = -1;
- close(fd);
+ os_close_file(fd);
}
-void xterm_free(void *d)
+static void xterm_free(void *d)
{
free(d);
}
-int xterm_console_write(int fd, const char *buf, int n, void *d)
-{
- struct xterm_chan *data = d;
-
- return(generic_console_write(fd, buf, n, &data->tt));
-}
-
-struct chan_ops xterm_ops = {
+const struct chan_ops xterm_ops = {
.type = "xterm",
.init = xterm_init,
.open = xterm_open,
.close = xterm_close,
.read = generic_read,
.write = generic_write,
- .console_write = xterm_console_write,
+ .console_write = generic_console_write,
.window_size = generic_window_size,
.free = xterm_free,
.winch = 1,