Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 1 | /** |
| 2 | * Console server process for OpenBMC |
| 3 | * |
| 4 | * Copyright © 2016 IBM Corporation <jk@ozlabs.org> |
| 5 | */ |
| 6 | |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 7 | #define _GNU_SOURCE |
| 8 | |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #include <stdbool.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdio.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <unistd.h> |
| 15 | #include <err.h> |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 16 | #include <string.h> |
| 17 | #include <getopt.h> |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 18 | #include <limits.h> |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 19 | |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/poll.h> |
| 22 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 23 | #include "console-server.h" |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 24 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 25 | struct console { |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 26 | const char *tty_kname; |
| 27 | char *tty_sysfs_devnode; |
| 28 | char *tty_dev; |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 29 | int tty_sirq; |
| 30 | int tty_lpc_addr; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 31 | int tty_fd; |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 32 | struct handler **handlers; |
| 33 | int n_handlers; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static void usage(const char *progname) |
| 37 | { |
| 38 | fprintf(stderr, |
| 39 | "usage: %s [options]\n" |
| 40 | "\n" |
| 41 | "Options:\n" |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 42 | " --device <TTY> Use serial device TTY (eg, ttyS0)\n" |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 43 | "", |
| 44 | progname); |
| 45 | } |
| 46 | |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 47 | /* populates tty_dev and tty_sysfs_devnode, using the tty kernel name */ |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 48 | static int tty_find_device(struct console *console) |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 49 | { |
| 50 | char *tty_class_device_link; |
| 51 | char *tty_device_tty_dir; |
| 52 | char *tty_device_reldir; |
| 53 | int rc; |
| 54 | |
| 55 | rc = -1; |
| 56 | tty_class_device_link = NULL; |
| 57 | tty_device_tty_dir = NULL; |
| 58 | tty_device_reldir = NULL; |
| 59 | |
| 60 | rc = asprintf(&tty_class_device_link, |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 61 | "/sys/class/tty/%s", console->tty_kname); |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 62 | if (rc < 0) |
| 63 | return -1; |
| 64 | |
| 65 | tty_device_tty_dir = realpath(tty_class_device_link, NULL); |
| 66 | if (rc < 0) { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 67 | warn("Can't query sysfs for device %s", console->tty_kname); |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 68 | goto out_free; |
| 69 | } |
| 70 | |
| 71 | rc = asprintf(&tty_device_reldir, "%s/../../", tty_device_tty_dir); |
| 72 | if (rc < 0) |
| 73 | goto out_free; |
| 74 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 75 | console->tty_sysfs_devnode = realpath(tty_device_reldir, NULL); |
| 76 | if (!console->tty_sysfs_devnode) |
| 77 | warn("Can't find parent device for %s", console->tty_kname); |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /* todo: lookup from major/minor info in sysfs, in case udev has |
| 81 | * renamed us */ |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 82 | rc = asprintf(&console->tty_dev, "/dev/%s", console->tty_kname); |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 83 | if (rc < 0) |
| 84 | goto out_free; |
| 85 | |
| 86 | rc = 0; |
| 87 | |
| 88 | out_free: |
| 89 | free(tty_class_device_link); |
| 90 | free(tty_device_tty_dir); |
| 91 | free(tty_device_reldir); |
| 92 | return rc; |
| 93 | } |
| 94 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 95 | static int tty_set_sysfs_attr(struct console *console, const char *name, |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 96 | int value) |
| 97 | { |
| 98 | char *path; |
| 99 | FILE *fp; |
| 100 | int rc; |
| 101 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 102 | rc = asprintf(&path, "%s/%s", console->tty_sysfs_devnode, name); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 103 | if (rc < 0) |
| 104 | return -1; |
| 105 | |
| 106 | fp = fopen(path, "w"); |
| 107 | if (!fp) { |
| 108 | warn("Can't access attribute %s on device %s", |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 109 | name, console->tty_kname); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 110 | rc = -1; |
| 111 | goto out_free; |
| 112 | } |
| 113 | setvbuf(fp, NULL, _IONBF, 0); |
| 114 | |
| 115 | rc = fprintf(fp, "0x%x", value); |
| 116 | if (rc < 0) |
| 117 | warn("Error writing to %s attribute of device %s", |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 118 | name, console->tty_kname); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 119 | fclose(fp); |
| 120 | |
| 121 | |
| 122 | |
| 123 | out_free: |
| 124 | free(path); |
| 125 | return rc; |
| 126 | } |
| 127 | |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 128 | /** |
| 129 | * Open and initialise the serial device |
| 130 | */ |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 131 | static int tty_init_io(struct console *console) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 132 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 133 | if (console->tty_sirq) |
| 134 | tty_set_sysfs_attr(console, "sirq", console->tty_sirq); |
| 135 | if (console->tty_lpc_addr) |
| 136 | tty_set_sysfs_attr(console, "lpc_address", |
| 137 | console->tty_lpc_addr); |
| 138 | tty_set_sysfs_attr(console, "enabled", 1); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 139 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 140 | console->tty_fd = open(console->tty_dev, O_RDWR); |
| 141 | if (console->tty_fd <= 0) { |
| 142 | warn("Can't open tty %s", console->tty_dev); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 143 | return -1; |
| 144 | } |
| 145 | |
| 146 | /* Disable character delay. We may want to later enable this when |
| 147 | * we detect larger amounts of data |
| 148 | */ |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 149 | fcntl(console->tty_fd, F_SETFL, FNDELAY); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 154 | |
| 155 | int console_data_out(struct console *console, const uint8_t *data, size_t len) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 156 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 157 | return write_buf_to_fd(console->tty_fd, data, len); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 158 | } |
| 159 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 160 | static void handlers_init(struct console *console) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 161 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 162 | extern struct handler *__start_handlers, *__stop_handlers; |
| 163 | struct handler *handler; |
| 164 | int i; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 165 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 166 | console->n_handlers = &__stop_handlers - &__start_handlers; |
| 167 | console->handlers = &__start_handlers; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 168 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 169 | printf("%d handler%s\n", console->n_handlers, |
| 170 | console->n_handlers == 1 ? "" : "s"); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 171 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 172 | for (i = 0; i < console->n_handlers; i++) { |
| 173 | handler = console->handlers[i]; |
| 174 | |
| 175 | printf(" %s\n", handler->name); |
| 176 | |
| 177 | if (handler->init) |
| 178 | handler->init(handler, console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 179 | } |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 180 | } |
| 181 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 182 | static void handlers_fini(struct console *console) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 183 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 184 | struct handler *handler; |
| 185 | int i; |
| 186 | |
| 187 | for (i = 0; i < console->n_handlers; i++) { |
| 188 | handler = console->handlers[i]; |
| 189 | if (handler->fini) |
| 190 | handler->fini(handler); |
| 191 | } |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 192 | } |
| 193 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 194 | static int handlers_data_in(struct console *console, uint8_t *buf, size_t len) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 195 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 196 | struct handler *handler; |
| 197 | int i, rc, tmp; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 198 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 199 | rc = 0; |
| 200 | |
| 201 | for (i = 0; i < console->n_handlers; i++) { |
| 202 | handler = console->handlers[i]; |
| 203 | |
| 204 | if (!handler->data_in) |
| 205 | continue; |
| 206 | |
| 207 | tmp = handler->data_in(handler, buf, len); |
| 208 | if (tmp == HANDLER_EXIT) |
| 209 | rc = 1; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 210 | } |
| 211 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 212 | return rc; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 215 | static int handlers_poll_event(struct console *console, |
| 216 | struct pollfd *pollfds) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 217 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 218 | struct handler *handler; |
| 219 | int i, rc, tmp; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 220 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 221 | rc = 0; |
| 222 | |
| 223 | for (i = 0; i < console->n_handlers; i++) { |
| 224 | handler = console->handlers[i]; |
| 225 | |
| 226 | if (!handler->poll_event) |
| 227 | continue; |
| 228 | |
| 229 | tmp = handler->poll_event(handler, pollfds[i].revents); |
| 230 | if (tmp == HANDLER_EXIT) |
| 231 | rc = 1; |
| 232 | } |
| 233 | |
| 234 | return rc; |
| 235 | } |
| 236 | |
| 237 | int run_console(struct console *console) |
| 238 | { |
| 239 | struct handler *handler; |
| 240 | struct pollfd *pollfds; |
| 241 | int i, rc; |
| 242 | |
| 243 | pollfds = calloc(console->n_handlers + 1, sizeof(*pollfds)); |
| 244 | |
| 245 | pollfds[0].fd = console->tty_fd; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 246 | pollfds[0].events = POLLIN; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 247 | |
| 248 | for (;;) { |
| 249 | uint8_t buf[4096]; |
| 250 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 251 | /* init pollers */ |
| 252 | for (i = 0; i < console->n_handlers; i++) { |
| 253 | handler = console->handlers[i]; |
| 254 | handler->init_poll(handler, &pollfds[i+1]); |
| 255 | } |
| 256 | |
| 257 | rc = poll(pollfds, console->n_handlers + 1, -1); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 258 | if (rc < 0) { |
| 259 | warn("poll error"); |
| 260 | return -1; |
| 261 | } |
| 262 | |
| 263 | if (pollfds[0].revents) { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 264 | rc = read(console->tty_fd, buf, sizeof(buf)); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 265 | if (rc <= 0) { |
| 266 | warn("Error reading from tty device"); |
| 267 | return -1; |
| 268 | } |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 269 | rc = handlers_data_in(console, buf, rc); |
| 270 | if (rc) |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 271 | return 0; |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 272 | } |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 273 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 274 | rc = handlers_poll_event(console, pollfds + 1); |
| 275 | if (rc) |
| 276 | return 0; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 277 | } |
| 278 | } |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 279 | static const struct option options[] = { |
| 280 | { "device", required_argument, 0, 'd'}, |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 281 | { "sirq", required_argument, 0, 's'}, |
| 282 | { "lpc-addr", required_argument, 0, 'l'}, |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 283 | { }, |
| 284 | }; |
| 285 | |
| 286 | int main(int argc, char **argv) |
| 287 | { |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 288 | struct console *console; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 289 | int rc; |
| 290 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 291 | console = malloc(sizeof(struct console)); |
| 292 | memset(console, 0, sizeof(*console)); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 293 | rc = -1; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 294 | |
| 295 | for (;;) { |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 296 | char *endp; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 297 | int c, idx; |
| 298 | |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 299 | c = getopt_long(argc, argv, "d:s:l:", options, &idx); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 300 | if (c == -1) |
| 301 | break; |
| 302 | |
| 303 | switch (c) { |
| 304 | case 'd': |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 305 | console->tty_kname = optarg; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 306 | break; |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 307 | case 'l': |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 308 | console->tty_lpc_addr = strtoul(optarg, &endp, 0); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 309 | if (endp == optarg) { |
| 310 | warnx("Invalid sirq: '%s'", optarg); |
| 311 | goto out_free; |
| 312 | } |
| 313 | break; |
| 314 | |
| 315 | case 's': |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 316 | console->tty_sirq = strtoul(optarg, &endp, 0); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 317 | if (endp == optarg) { |
| 318 | warnx("Invalid sirq: '%s'", optarg); |
| 319 | goto out_free; |
| 320 | } |
| 321 | break; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 322 | |
| 323 | case 'h': |
| 324 | case '?': |
| 325 | usage(argv[0]); |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 326 | rc = 0; |
| 327 | goto out_free; |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 331 | if (!console->tty_kname) { |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 332 | fprintf(stderr, |
| 333 | "Error: No TTY device specified (use --device)\n"); |
| 334 | return EXIT_FAILURE; |
| 335 | } |
| 336 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 337 | rc = tty_find_device(console); |
Jeremy Kerr | 1721784 | 2016-01-29 18:44:21 +0800 | [diff] [blame] | 338 | if (rc) |
| 339 | return EXIT_FAILURE; |
| 340 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 341 | rc = tty_init_io(console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 342 | if (rc) |
| 343 | return EXIT_FAILURE; |
| 344 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 345 | handlers_init(console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 346 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 347 | rc = run_console(console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 348 | |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 349 | handlers_fini(console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 350 | |
Jeremy Kerr | 957818b | 2016-03-08 14:35:15 +0800 | [diff] [blame] | 351 | out_free: |
Jeremy Kerr | 1a0e03b | 2016-03-08 17:57:11 +0800 | [diff] [blame^] | 352 | free(console->tty_sysfs_devnode); |
| 353 | free(console->tty_dev); |
| 354 | free(console); |
Jeremy Kerr | d831f96 | 2016-01-29 17:18:01 +0800 | [diff] [blame] | 355 | |
| 356 | return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 357 | } |