Lines Matching refs:server
72 console_server_find_released_pollfd(struct console_server *server) in console_server_find_released_pollfd() argument
74 for (size_t i = 0; i < server->capacity_pollfds; i++) { in console_server_find_released_pollfd()
75 struct pollfd *p = &server->pollfds[i]; in console_server_find_released_pollfd()
85 ssize_t console_server_request_pollfd(struct console_server *server, int fd, in console_server_request_pollfd() argument
91 index = console_server_find_released_pollfd(server); in console_server_request_pollfd()
94 const size_t newcap = server->capacity_pollfds + 1; in console_server_request_pollfd()
96 struct pollfd *newarr = reallocarray(server->pollfds, newcap, in console_server_request_pollfd()
101 server->pollfds = newarr; in console_server_request_pollfd()
103 index = (ssize_t)server->capacity_pollfds; in console_server_request_pollfd()
105 server->capacity_pollfds = newcap; in console_server_request_pollfd()
108 pollfd = &server->pollfds[index]; in console_server_request_pollfd()
116 int console_server_release_pollfd(struct console_server *server, in console_server_release_pollfd() argument
119 if (pollfd_index >= server->capacity_pollfds) { in console_server_release_pollfd()
123 struct pollfd *pfd = &server->pollfds[pollfd_index]; in console_server_release_pollfd()
137 static int tty_find_device(struct console_server *server) in tty_find_device() argument
149 server->tty.type = TTY_DEVICE_UNDEFINED; in tty_find_device()
151 assert(server->tty.kname); in tty_find_device()
152 if (!strlen(server->tty.kname)) { in tty_find_device()
158 if (server->tty.kname[0] == '/') { in tty_find_device()
159 tty_path_input = strdup(server->tty.kname); in tty_find_device()
165 rc = asprintf(&tty_path_input, "/dev/%s", server->tty.kname); in tty_find_device()
185 server->tty.type = TTY_DEVICE_PTY; in tty_find_device()
186 server->tty.dev = strdup(server->tty.kname); in tty_find_device()
187 rc = server->tty.dev ? 0 : -1; in tty_find_device()
193 warn("Can't find real name for %s", server->tty.kname); in tty_find_device()
221 rc = asprintf(&server->tty.dev, "/dev/%s", tty_kname_real); in tty_find_device()
227 server->tty.type = TTY_DEVICE_UART; in tty_find_device()
239 server->tty.type = TTY_DEVICE_VUART; in tty_find_device()
240 server->tty.vuart.sysfs_devnode = in tty_find_device()
258 static int tty_set_sysfs_attr(struct console_server *server, const char *name, in tty_set_sysfs_attr() argument
265 assert(server->tty.type == TTY_DEVICE_VUART); in tty_set_sysfs_attr()
267 if (!server->tty.vuart.sysfs_devnode) { in tty_set_sysfs_attr()
271 rc = asprintf(&path, "%s/%s", server->tty.vuart.sysfs_devnode, name); in tty_set_sysfs_attr()
279 server->tty.kname); in tty_set_sysfs_attr()
288 server->tty.kname); in tty_set_sysfs_attr()
300 void tty_init_termios(struct console_server *server) in tty_init_termios() argument
305 rc = tcgetattr(server->tty.fd, &termios); in tty_init_termios()
311 if (server->tty.type == TTY_DEVICE_UART && server->tty.uart.baud) { in tty_init_termios()
312 if (cfsetspeed(&termios, server->tty.uart.baud) < 0) { in tty_init_termios()
313 warn("Couldn't set speeds for %s", server->tty.kname); in tty_init_termios()
322 rc = tcsetattr(server->tty.fd, TCSANOW, &termios); in tty_init_termios()
324 warn("Can't set terminal options for %s", server->tty.kname); in tty_init_termios()
331 static void tty_init_vuart_io(struct console_server *server) in tty_init_vuart_io() argument
333 assert(server->tty.type == TTY_DEVICE_VUART); in tty_init_vuart_io()
335 if (server->tty.vuart.sirq) { in tty_init_vuart_io()
336 tty_set_sysfs_attr(server, "sirq", server->tty.vuart.sirq); in tty_init_vuart_io()
339 if (server->tty.vuart.lpc_addr) { in tty_init_vuart_io()
340 tty_set_sysfs_attr(server, "lpc_address", in tty_init_vuart_io()
341 server->tty.vuart.lpc_addr); in tty_init_vuart_io()
345 static int tty_init_io(struct console_server *server) in tty_init_io() argument
347 server->tty.fd = open(server->tty.dev, O_RDWR); in tty_init_io()
348 if (server->tty.fd <= 0) { in tty_init_io()
349 warn("Can't open tty %s", server->tty.dev); in tty_init_io()
356 fcntl(server->tty.fd, F_SETFL, FNDELAY); in tty_init_io()
358 tty_init_termios(server); in tty_init_io()
361 console_server_request_pollfd(server, server->tty.fd, POLLIN); in tty_init_io()
367 server->tty_pollfd_index = (size_t)index; in tty_init_io()
372 static int tty_init_vuart(struct console_server *server, struct config *config) in tty_init_vuart() argument
378 assert(server->tty.type == TTY_DEVICE_VUART); in tty_init_vuart()
395 server->tty.vuart.lpc_addr = (uint16_t)parsed; in tty_init_vuart()
415 server->tty.vuart.sirq = (int)parsed; in tty_init_vuart()
424 static int tty_init(struct console_server *server, struct config *config, in tty_init() argument
431 server->tty.kname = tty_arg; in tty_init()
433 server->tty.kname = val; in tty_init()
439 rc = tty_find_device(server); in tty_init()
444 switch (server->tty.type) { in tty_init()
446 rc = tty_init_vuart(server, config); in tty_init()
451 tty_init_vuart_io(server); in tty_init()
456 if (config_parse_baud(&server->tty.uart.baud, val)) { in tty_init()
469 return tty_init_io(server); in tty_init()
472 static void tty_fini(struct console_server *server) in tty_fini() argument
474 if (server->tty_pollfd_index < server->capacity_pollfds) { in tty_fini()
475 console_server_release_pollfd(server, server->tty_pollfd_index); in tty_fini()
476 server->tty_pollfd_index = SIZE_MAX; in tty_fini()
479 if (server->tty.type == TTY_DEVICE_VUART) { in tty_fini()
480 free(server->tty.vuart.sysfs_devnode); in tty_fini()
483 free(server->tty.dev); in tty_fini()
594 return write_buf_to_fd(console->server->tty.fd, data, len); in console_data_out()
717 console->server, fd, (short)(events & 0x7fff)); in console_poller_register()
785 console_server_release_pollfd(console->server, poller->pollfd_index); in console_poller_unregister()
793 console->server->pollfds[poller->pollfd_index].events = in console_poller_set_events()
862 pollfd = &console->server->pollfds[poller->pollfd_index]; in call_pollers()
953 static int run_console_iteration(struct console_server *server) in run_console_iteration() argument
966 timeout = get_poll_timeout(server->active, &tv); in run_console_iteration()
968 rc = poll(server->pollfds, server->capacity_pollfds, (int)timeout); in run_console_iteration()
984 if (server->pollfds[server->tty_pollfd_index].revents) { in run_console_iteration()
985 rc = read(server->tty.fd, buf, sizeof(buf)); in run_console_iteration()
991 rc = ringbuffer_queue(server->active->rb, buf, rc); in run_console_iteration()
999 &(server->pollfds[server->dbus_pollfd_index]); in run_console_iteration()
1001 sd_bus_process(server->bus, NULL); in run_console_iteration()
1004 for (size_t i = 0; i < server->n_consoles; i++) { in run_console_iteration()
1005 struct console *console = server->consoles[i]; in run_console_iteration()
1016 int run_server(struct console_server *server) in run_server() argument
1021 if (server->n_consoles == 0) { in run_server()
1028 rc = run_console_iteration(server); in run_server()
1044 static struct console *console_init(struct console_server *server, in console_init() argument
1057 console->server = server; in console_init()
1117 static int console_server_add_console(struct console_server *server, in console_server_add_console() argument
1126 struct console **tmp = reallocarray(server->consoles, in console_server_add_console()
1127 server->n_consoles + 1, in console_server_add_console()
1133 server->consoles = tmp; in console_server_add_console()
1135 console = console_init(server, config, console_id); in console_server_add_console()
1141 server->consoles[server->n_consoles++] = console; in console_server_add_console()
1148 console_server_add_consoles(struct console_server *server, in console_server_add_consoles() argument
1153 const int nsections = config_count_sections(server->config); in console_server_add_consoles()
1161 rc = console_server_add_console(server, server->config, in console_server_add_consoles()
1170 config_get_section_name(server->config, i); in console_server_add_consoles()
1177 rc = console_server_add_console(server, server->config, in console_server_add_consoles()
1185 config_get_value(server->config, "active-console"); in console_server_add_consoles()
1187 return server->consoles[0]; in console_server_add_consoles()
1193 for (size_t i = 0; i < server->n_consoles; i++) { in console_server_add_consoles()
1194 struct console *console = server->consoles[i]; in console_server_add_consoles()
1207 int console_server_init(struct console_server *server, in console_server_init() argument
1212 memset(server, 0, sizeof(struct console_server)); in console_server_init()
1214 server->tty_pollfd_index = -1; in console_server_init()
1216 server->config = config_init(config_filename); in console_server_init()
1217 if (server->config == NULL) { in console_server_init()
1221 rc = console_server_mux_init(server); in console_server_init()
1226 uart_routing_init(server->config); in console_server_init()
1228 rc = tty_init(server, server->config, config_tty_kname); in console_server_init()
1234 rc = dbus_server_init(server); in console_server_init()
1241 console_server_add_consoles(server, console_id); in console_server_init()
1254 void console_server_fini(struct console_server *server) in console_server_fini() argument
1256 for (size_t i = 0; i < server->n_consoles; i++) { in console_server_fini()
1257 console_fini(server->consoles[i]); in console_server_fini()
1260 free(server->consoles); in console_server_fini()
1261 dbus_server_fini(server); in console_server_fini()
1262 tty_fini(server); in console_server_fini()
1263 free(server->pollfds); in console_server_fini()
1264 console_server_mux_fini(server); in console_server_fini()
1265 config_fini(server->config); in console_server_fini()
1273 struct console_server server = { 0 }; in main() local
1305 rc = console_server_init(&server, config_filename, config_tty_kname, in main()
1309 rc = run_server(&server); in main()
1312 console_server_fini(&server); in main()