blob: 3857de1f894f5e35d495f93b311442c5a11304ad [file] [log] [blame]
Jeremy Kerrd831f962016-01-29 17:18:01 +08001/**
2 * Console server process for OpenBMC
3 *
Jeremy Kerr9326d772016-03-17 17:15:02 +08004 * Copyright © 2016 IBM Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Jeremy Kerrd831f962016-01-29 17:18:01 +080017 */
18
Jeremy Kerr17217842016-01-29 18:44:21 +080019#define _GNU_SOURCE
20
Jeremy Kerr329a35f2016-03-10 15:36:01 +080021#include <assert.h>
Jeremy Kerr769cee12016-03-15 17:53:56 +080022#include <errno.h>
23#include <signal.h>
Jeremy Kerrd831f962016-01-29 17:18:01 +080024#include <stdint.h>
25#include <stdbool.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <fcntl.h>
29#include <unistd.h>
30#include <err.h>
Jeremy Kerrd831f962016-01-29 17:18:01 +080031#include <string.h>
32#include <getopt.h>
Jeremy Kerr17217842016-01-29 18:44:21 +080033#include <limits.h>
Jeremy Kerrd831f962016-01-29 17:18:01 +080034
35#include <sys/types.h>
36#include <sys/poll.h>
37
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +080038#include "console-server.h"
Jeremy Kerrd831f962016-01-29 17:18:01 +080039
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +080040struct console {
Jeremy Kerr17217842016-01-29 18:44:21 +080041 const char *tty_kname;
42 char *tty_sysfs_devnode;
43 char *tty_dev;
Jeremy Kerr957818b2016-03-08 14:35:15 +080044 int tty_sirq;
45 int tty_lpc_addr;
Jeremy Kerrd831f962016-01-29 17:18:01 +080046 int tty_fd;
Jeremy Kerr329a35f2016-03-10 15:36:01 +080047
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +080048 struct handler **handlers;
49 int n_handlers;
Jeremy Kerr329a35f2016-03-10 15:36:01 +080050
51 struct poller **pollers;
52 int n_pollers;
53
54 struct pollfd *pollfds;
Jeremy Kerrd831f962016-01-29 17:18:01 +080055};
56
Jeremy Kerr329a35f2016-03-10 15:36:01 +080057struct poller {
58 struct handler *handler;
59 void *data;
60 poller_fn_t fn;
61 bool remove;
62};
63
64/* we have one extra entry in the pollfds array for the VUART tty */
65static const int n_internal_pollfds = 1;
66
Jeremy Kerr769cee12016-03-15 17:53:56 +080067/* state shared with the signal handler */
68static bool sigint;
Jeremy Kerr329a35f2016-03-10 15:36:01 +080069
Jeremy Kerrd831f962016-01-29 17:18:01 +080070static void usage(const char *progname)
71{
72 fprintf(stderr,
73"usage: %s [options]\n"
74"\n"
75"Options:\n"
Jeremy Kerrd66195c2016-03-16 17:24:51 +080076" --config <FILE> Use FILE for configuration\n"
Jeremy Kerrd831f962016-01-29 17:18:01 +080077"",
78 progname);
79}
80
Jeremy Kerr17217842016-01-29 18:44:21 +080081/* populates tty_dev and tty_sysfs_devnode, using the tty kernel name */
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +080082static int tty_find_device(struct console *console)
Jeremy Kerr17217842016-01-29 18:44:21 +080083{
84 char *tty_class_device_link;
85 char *tty_device_tty_dir;
86 char *tty_device_reldir;
87 int rc;
88
Jeremy Kerr17217842016-01-29 18:44:21 +080089 tty_class_device_link = NULL;
90 tty_device_tty_dir = NULL;
91 tty_device_reldir = NULL;
92
93 rc = asprintf(&tty_class_device_link,
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +080094 "/sys/class/tty/%s", console->tty_kname);
Jeremy Kerr17217842016-01-29 18:44:21 +080095 if (rc < 0)
96 return -1;
97
98 tty_device_tty_dir = realpath(tty_class_device_link, NULL);
99 if (rc < 0) {
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800100 warn("Can't query sysfs for device %s", console->tty_kname);
Jeremy Kerr17217842016-01-29 18:44:21 +0800101 goto out_free;
102 }
103
104 rc = asprintf(&tty_device_reldir, "%s/../../", tty_device_tty_dir);
105 if (rc < 0)
106 goto out_free;
107
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800108 console->tty_sysfs_devnode = realpath(tty_device_reldir, NULL);
109 if (!console->tty_sysfs_devnode)
110 warn("Can't find parent device for %s", console->tty_kname);
Jeremy Kerr17217842016-01-29 18:44:21 +0800111
112
113 /* todo: lookup from major/minor info in sysfs, in case udev has
114 * renamed us */
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800115 rc = asprintf(&console->tty_dev, "/dev/%s", console->tty_kname);
Jeremy Kerr17217842016-01-29 18:44:21 +0800116 if (rc < 0)
117 goto out_free;
118
119 rc = 0;
120
121out_free:
122 free(tty_class_device_link);
123 free(tty_device_tty_dir);
124 free(tty_device_reldir);
125 return rc;
126}
127
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800128static int tty_set_sysfs_attr(struct console *console, const char *name,
Jeremy Kerr957818b2016-03-08 14:35:15 +0800129 int value)
130{
131 char *path;
132 FILE *fp;
133 int rc;
134
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800135 rc = asprintf(&path, "%s/%s", console->tty_sysfs_devnode, name);
Jeremy Kerr957818b2016-03-08 14:35:15 +0800136 if (rc < 0)
137 return -1;
138
139 fp = fopen(path, "w");
140 if (!fp) {
141 warn("Can't access attribute %s on device %s",
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800142 name, console->tty_kname);
Jeremy Kerr957818b2016-03-08 14:35:15 +0800143 rc = -1;
144 goto out_free;
145 }
146 setvbuf(fp, NULL, _IONBF, 0);
147
148 rc = fprintf(fp, "0x%x", value);
149 if (rc < 0)
150 warn("Error writing to %s attribute of device %s",
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800151 name, console->tty_kname);
Jeremy Kerr957818b2016-03-08 14:35:15 +0800152 fclose(fp);
153
154
155
156out_free:
157 free(path);
158 return rc;
159}
160
Jeremy Kerrd831f962016-01-29 17:18:01 +0800161/**
162 * Open and initialise the serial device
163 */
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800164static int tty_init_io(struct console *console)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800165{
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800166 if (console->tty_sirq)
167 tty_set_sysfs_attr(console, "sirq", console->tty_sirq);
168 if (console->tty_lpc_addr)
169 tty_set_sysfs_attr(console, "lpc_address",
170 console->tty_lpc_addr);
171 tty_set_sysfs_attr(console, "enabled", 1);
Jeremy Kerr957818b2016-03-08 14:35:15 +0800172
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800173 console->tty_fd = open(console->tty_dev, O_RDWR);
174 if (console->tty_fd <= 0) {
175 warn("Can't open tty %s", console->tty_dev);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800176 return -1;
177 }
178
179 /* Disable character delay. We may want to later enable this when
180 * we detect larger amounts of data
181 */
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800182 fcntl(console->tty_fd, F_SETFL, FNDELAY);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800183
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800184 console->pollfds[console->n_pollers].fd = console->tty_fd;
185 console->pollfds[console->n_pollers].events = POLLIN;
186
Jeremy Kerrd831f962016-01-29 17:18:01 +0800187 return 0;
188}
189
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800190static int tty_init(struct console *console, struct config *config)
191{
192 const char *val;
193 char *endp;
194 int rc;
195
196 console->tty_kname = config_get_value(config, "device");
197
198 val = config_get_value(config, "lpc-address");
199 if (val) {
200 console->tty_lpc_addr = strtoul(val, &endp, 0);
201 if (endp == optarg) {
202 warn("Invalid LPC address: '%s'", val);
203 return -1;
204 }
205 }
206
207 val = config_get_value(config, "sirq");
208 if (val) {
209 console->tty_sirq = strtoul(val, &endp, 0);
210 if (endp == optarg)
211 warn("Invalid sirq: '%s'", val);
212 }
213
214 if (!console->tty_kname) {
215 warnx("Error: No TTY device specified");
216 return -1;
217 }
218
219 rc = tty_find_device(console);
220 if (rc)
221 return rc;
222
223 rc = tty_init_io(console);
224 return rc;
225}
226
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800227
228int console_data_out(struct console *console, const uint8_t *data, size_t len)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800229{
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800230 return write_buf_to_fd(console->tty_fd, data, len);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800231}
232
Jeremy Kerrd47963e2016-03-16 17:29:55 +0800233static void handlers_init(struct console *console, struct config *config)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800234{
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800235 extern struct handler *__start_handlers, *__stop_handlers;
236 struct handler *handler;
237 int i;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800238
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800239 console->n_handlers = &__stop_handlers - &__start_handlers;
240 console->handlers = &__start_handlers;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800241
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800242 printf("%d handler%s\n", console->n_handlers,
243 console->n_handlers == 1 ? "" : "s");
Jeremy Kerrd831f962016-01-29 17:18:01 +0800244
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800245 for (i = 0; i < console->n_handlers; i++) {
246 handler = console->handlers[i];
247
248 printf(" %s\n", handler->name);
249
250 if (handler->init)
Jeremy Kerrd47963e2016-03-16 17:29:55 +0800251 handler->init(handler, console, config);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800252 }
Jeremy Kerrd831f962016-01-29 17:18:01 +0800253}
254
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800255static void handlers_fini(struct console *console)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800256{
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800257 struct handler *handler;
258 int i;
259
260 for (i = 0; i < console->n_handlers; i++) {
261 handler = console->handlers[i];
262 if (handler->fini)
263 handler->fini(handler);
264 }
Jeremy Kerrd831f962016-01-29 17:18:01 +0800265}
266
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800267static int handlers_data_in(struct console *console, uint8_t *buf, size_t len)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800268{
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800269 struct handler *handler;
270 int i, rc, tmp;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800271
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800272 rc = 0;
273
274 for (i = 0; i < console->n_handlers; i++) {
275 handler = console->handlers[i];
276
277 if (!handler->data_in)
278 continue;
279
280 tmp = handler->data_in(handler, buf, len);
281 if (tmp == HANDLER_EXIT)
282 rc = 1;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800283 }
284
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800285 return rc;
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800286
Jeremy Kerrd831f962016-01-29 17:18:01 +0800287}
288
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800289struct poller *console_register_poller(struct console *console,
290 struct handler *handler, poller_fn_t poller_fn,
291 int fd, int events, void *data)
Jeremy Kerrd831f962016-01-29 17:18:01 +0800292{
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800293 struct poller *poller;
294 int n;
295
296 poller = malloc(sizeof(*poller));
297 poller->remove = false;
298 poller->handler = handler;
299 poller->fn = poller_fn;
300 poller->data = data;
301
302 /* add one to our pollers array */
303 n = console->n_pollers++;
304 console->pollers = realloc(console->pollers,
305 sizeof(*console->pollers) * console->n_pollers);
306
307 console->pollers[n] = poller;
308
309 /* increase pollfds array too */
310 console->pollfds = realloc(console->pollfds,
311 sizeof(*console->pollfds) *
312 (n_internal_pollfds + console->n_pollers));
313
314 /* shift the end pollfds up by one */
315 memcpy(&console->pollfds[n+n_internal_pollfds],
316 &console->pollfds[n],
317 sizeof(*console->pollfds) * n_internal_pollfds);
318
319 console->pollfds[n].fd = fd;
320 console->pollfds[n].events = events;
321
322 return poller;
323}
324
325void console_unregister_poller(struct console *console,
326 struct poller *poller)
327{
328 int i;
329
330 /* find the entry in our pollers array */
331 for (i = 0; i < console->n_pollers; i++)
332 if (console->pollers[i] == poller)
333 break;
334
335 assert(i < console->n_pollers);
336
337 console->n_pollers--;
338
339 /* remove the item from the pollers array... */
340 memmove(&console->pollers[i], &console->pollers[i+1],
341 sizeof(*console->pollers)
342 * (console->n_pollers - i));
343
344 console->pollers = realloc(console->pollers,
345 sizeof(*console->pollers) * console->n_pollers);
346
347 /* ... and the pollfds array */
348 memmove(&console->pollfds[i], &console->pollfds[i+1],
349 sizeof(*console->pollfds) *
350 (n_internal_pollfds + console->n_pollers - i));
351
352 console->pollfds = realloc(console->pollfds,
353 sizeof(*console->pollfds) *
354 (n_internal_pollfds + console->n_pollers));
355
356
357 free(poller);
358}
359
360static int call_pollers(struct console *console)
361{
362 struct poller *poller;
363 struct pollfd *pollfd;
364 enum poller_ret prc;
365 int i, rc;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800366
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800367 rc = 0;
368
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800369 /*
370 * Process poll events by iterating through the pollers and pollfds
371 * in-step, calling any pollers that we've found revents for.
372 */
373 for (i = 0; i < console->n_pollers; i++) {
374 poller = console->pollers[i];
375 pollfd = &console->pollfds[i];
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800376
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800377 if (!pollfd->revents)
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800378 continue;
379
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800380 prc = poller->fn(poller->handler, pollfd->revents,
381 poller->data);
382 if (prc == POLLER_EXIT)
383 rc = -1;
384 else if (prc == POLLER_REMOVE)
385 poller->remove = true;
386 }
387
388 /**
389 * Process deferred removals; restarting each time we unregister, as
390 * the array will have changed
391 */
392 for (;;) {
393 bool removed = false;
394
395 for (i = 0; i < console->n_pollers; i++) {
396 poller = console->pollers[i];
397 if (poller->remove) {
398 console_unregister_poller(console, poller);
399 removed = true;
400 break;
401 }
402 }
403 if (!removed)
404 break;
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800405 }
406
407 return rc;
408}
409
Jeremy Kerr769cee12016-03-15 17:53:56 +0800410static void sighandler(int signal)
411{
412 if (signal == SIGINT)
413 sigint = true;
414}
415
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800416int run_console(struct console *console)
417{
Jeremy Kerr769cee12016-03-15 17:53:56 +0800418 sighandler_t sighandler_save;
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800419 int rc;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800420
Jeremy Kerr769cee12016-03-15 17:53:56 +0800421 sighandler_save = signal(SIGINT, sighandler);
422
423 rc = 0;
424
Jeremy Kerrd831f962016-01-29 17:18:01 +0800425 for (;;) {
426 uint8_t buf[4096];
427
Jeremy Kerr769cee12016-03-15 17:53:56 +0800428 if (sigint) {
429 fprintf(stderr, "Received interrupt, exiting\n");
430 break;
431 }
432
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800433 rc = poll(console->pollfds,
434 console->n_pollers + n_internal_pollfds, -1);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800435 if (rc < 0) {
Jeremy Kerr769cee12016-03-15 17:53:56 +0800436 if (errno == EINTR) {
437 continue;
438 } else {
439 warn("poll error");
440 break;
441 }
Jeremy Kerrd831f962016-01-29 17:18:01 +0800442 }
443
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800444 /* process internal fd first */
445 BUILD_ASSERT(n_internal_pollfds == 1);
446
447 if (console->pollfds[console->n_pollers].revents) {
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800448 rc = read(console->tty_fd, buf, sizeof(buf));
Jeremy Kerrd831f962016-01-29 17:18:01 +0800449 if (rc <= 0) {
450 warn("Error reading from tty device");
Jeremy Kerr769cee12016-03-15 17:53:56 +0800451 rc = -1;
452 break;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800453 }
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800454 rc = handlers_data_in(console, buf, rc);
455 if (rc)
Jeremy Kerr769cee12016-03-15 17:53:56 +0800456 break;
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800457 }
Jeremy Kerrd831f962016-01-29 17:18:01 +0800458
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800459 /* ... and then the pollers */
460 rc = call_pollers(console);
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800461 if (rc)
Jeremy Kerr769cee12016-03-15 17:53:56 +0800462 break;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800463 }
Jeremy Kerr769cee12016-03-15 17:53:56 +0800464
465 signal(SIGINT, sighandler_save);
466
467 return rc ? -1 : 0;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800468}
Jeremy Kerrd831f962016-01-29 17:18:01 +0800469static const struct option options[] = {
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800470 { "config", required_argument, 0, 'c'},
Jeremy Kerre3f94542016-03-17 16:38:37 +0800471 { 0 },
Jeremy Kerrd831f962016-01-29 17:18:01 +0800472};
473
474int main(int argc, char **argv)
475{
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800476 const char *config_filename = NULL;
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800477 struct console *console;
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800478 struct config *config;
479 int rc;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800480
Jeremy Kerr957818b2016-03-08 14:35:15 +0800481 rc = -1;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800482
483 for (;;) {
484 int c, idx;
485
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800486 c = getopt_long(argc, argv, "c:", options, &idx);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800487 if (c == -1)
488 break;
489
490 switch (c) {
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800491 case 'c':
492 config_filename = optarg;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800493 break;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800494 case 'h':
495 case '?':
496 usage(argv[0]);
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800497 return EXIT_SUCCESS;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800498 }
499 }
500
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800501 console = malloc(sizeof(struct console));
502 memset(console, 0, sizeof(*console));
Jeremy Kerr329a35f2016-03-10 15:36:01 +0800503 console->pollfds = calloc(n_internal_pollfds,
504 sizeof(*console->pollfds));
505
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800506 config = config_init(config_filename);
507 if (!config) {
508 warnx("Can't read configuration, exiting.");
509 goto out_free;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800510 }
511
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800512 rc = tty_init(console, config);
Jeremy Kerr17217842016-01-29 18:44:21 +0800513 if (rc)
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800514 goto out_config_fini;
Jeremy Kerrd831f962016-01-29 17:18:01 +0800515
Jeremy Kerrd47963e2016-03-16 17:29:55 +0800516 handlers_init(console, config);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800517
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800518 rc = run_console(console);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800519
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800520 handlers_fini(console);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800521
Jeremy Kerrd66195c2016-03-16 17:24:51 +0800522out_config_fini:
523 config_fini(config);
524
Jeremy Kerr957818b2016-03-08 14:35:15 +0800525out_free:
Jeremy Kerr89ea8192016-03-15 17:57:43 +0800526 free(console->pollers);
527 free(console->pollfds);
Jeremy Kerr1a0e03b2016-03-08 17:57:11 +0800528 free(console->tty_sysfs_devnode);
529 free(console->tty_dev);
530 free(console);
Jeremy Kerrd831f962016-01-29 17:18:01 +0800531
532 return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
533}