console-server.c (9a8f30ec5b58252caeb5b856c353d37df9e4cf4d) | console-server.c (954be0fbc4acdd0322041c4c86fa08fd33ded594) |
---|---|
1/** 2 * Console server process for OpenBMC 3 * 4 * 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 --- 39 unchanged lines hidden (view full) --- 48static bool sigint; 49 50static void usage(const char *progname) 51{ 52 fprintf(stderr, 53 "usage: %s [options] <DEVICE>\n" 54 "\n" 55 "Options:\n" | 1/** 2 * Console server process for OpenBMC 3 * 4 * 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 --- 39 unchanged lines hidden (view full) --- 48static bool sigint; 49 50static void usage(const char *progname) 51{ 52 fprintf(stderr, 53 "usage: %s [options] <DEVICE>\n" 54 "\n" 55 "Options:\n" |
56 " --config <FILE> Use FILE for configuration\n" | 56 " --config <FILE>\tUse FILE for configuration\n" 57 " --console-id <NAME>\tUse NAME in the UNIX domain socket address\n" |
57 "", 58 progname); 59} 60 61/* populates console->tty.dev and console->tty.sysfs_devnode, using the tty kernel name */ 62static int tty_find_device(struct console *console) 63{ 64 char *tty_class_device_link = NULL; --- 321 unchanged lines hidden (view full) --- 386} 387 388int console_data_out(struct console *console, const uint8_t *data, size_t len) 389{ 390 return write_buf_to_fd(console->tty.fd, data, len); 391} 392 393/* Read console if from config and prepare a socket name */ | 58 "", 59 progname); 60} 61 62/* populates console->tty.dev and console->tty.sysfs_devnode, using the tty kernel name */ 63static int tty_find_device(struct console *console) 64{ 65 char *tty_class_device_link = NULL; --- 321 unchanged lines hidden (view full) --- 387} 388 389int console_data_out(struct console *console, const uint8_t *data, size_t len) 390{ 391 return write_buf_to_fd(console->tty.fd, data, len); 392} 393 394/* Read console if from config and prepare a socket name */ |
394static int set_socket_info(struct console *console, struct config *config) | 395static int set_socket_info(struct console *console, struct config *config, 396 const char *console_id) |
395{ | 397{ |
398 const char *resolved_id; |
|
396 ssize_t len; 397 | 399 ssize_t len; 400 |
398 console->console_id = config_get_value(config, "console-id"); | 401 if (console_id) { 402 resolved_id = console_id; 403 } else { 404 resolved_id = config_get_value(config, "console-id"); |
399 | 405 |
400 /* socket-id is deprecated */ 401 if (!console->console_id) { 402 console->console_id = config_get_value(config, "socket-id"); | 406 /* socket-id is deprecated */ 407 if (!resolved_id) { 408 resolved_id = config_get_value(config, "socket-id"); 409 } |
403 } 404 | 410 } 411 |
405 if (!console->console_id) { 406 warnx("Error: The console-id is not set in the config file"); | 412 if (!resolved_id) { 413 warnx("console-id was not specified"); |
407 return EXIT_FAILURE; 408 } 409 | 414 return EXIT_FAILURE; 415 } 416 |
417 console->console_id = resolved_id; 418 |
|
410 /* Get the socket name/path */ | 419 /* Get the socket name/path */ |
411 len = console_socket_path(console->socket_name, console->console_id); | 420 len = console_socket_path(console->socket_name, resolved_id); |
412 if (len < 0) { 413 warn("Failed to set socket path: %s", strerror(errno)); 414 return EXIT_FAILURE; 415 } 416 417 /* Socket name is not a null terminated string hence save the length */ 418 console->socket_name_len = len; 419 --- 366 unchanged lines hidden (view full) --- 786 787 signal(SIGINT, sighandler_save); 788 sd_bus_unref(console->bus); 789 790 return rc ? -1 : 0; 791} 792static const struct option options[] = { 793 { "config", required_argument, 0, 'c' }, | 421 if (len < 0) { 422 warn("Failed to set socket path: %s", strerror(errno)); 423 return EXIT_FAILURE; 424 } 425 426 /* Socket name is not a null terminated string hence save the length */ 427 console->socket_name_len = len; 428 --- 366 unchanged lines hidden (view full) --- 795 796 signal(SIGINT, sighandler_save); 797 sd_bus_unref(console->bus); 798 799 return rc ? -1 : 0; 800} 801static const struct option options[] = { 802 { "config", required_argument, 0, 'c' }, |
803 { "console-id", required_argument, 0, 'i' }, |
|
794 { 0, 0, 0, 0 }, 795}; 796 797int main(int argc, char **argv) 798{ 799 const char *config_filename = NULL; 800 const char *config_tty_kname = NULL; | 804 { 0, 0, 0, 0 }, 805}; 806 807int main(int argc, char **argv) 808{ 809 const char *config_filename = NULL; 810 const char *config_tty_kname = NULL; |
811 const char *console_id = NULL; |
|
801 struct console *console; 802 struct config *config; 803 int rc; 804 805 for (;;) { 806 int c; 807 int idx; 808 | 812 struct console *console; 813 struct config *config; 814 int rc; 815 816 for (;;) { 817 int c; 818 int idx; 819 |
809 c = getopt_long(argc, argv, "c:", options, &idx); | 820 c = getopt_long(argc, argv, "c:i:", options, &idx); |
810 if (c == -1) { 811 break; 812 } 813 814 switch (c) { 815 case 'c': 816 config_filename = optarg; 817 break; | 821 if (c == -1) { 822 break; 823 } 824 825 switch (c) { 826 case 'c': 827 config_filename = optarg; 828 break; |
829 case 'i': 830 console_id = optarg; 831 break; |
|
818 case 'h': 819 case '?': 820 usage(argv[0]); 821 return EXIT_SUCCESS; 822 } 823 } 824 825 if (optind < argc) { --- 8 unchanged lines hidden (view full) --- 834 835 config = config_init(config_filename); 836 if (!config) { 837 warnx("Can't read configuration, exiting."); 838 rc = -1; 839 goto out_free; 840 } 841 | 832 case 'h': 833 case '?': 834 usage(argv[0]); 835 return EXIT_SUCCESS; 836 } 837 } 838 839 if (optind < argc) { --- 8 unchanged lines hidden (view full) --- 848 849 config = config_init(config_filename); 850 if (!config) { 851 warnx("Can't read configuration, exiting."); 852 rc = -1; 853 goto out_free; 854 } 855 |
842 if (set_socket_info(console, config)) { | 856 if (set_socket_info(console, config, console_id)) { |
843 rc = -1; 844 goto out_config_fini; 845 } 846 847 rc = tty_init(console, config, config_tty_kname); 848 if (rc) { 849 goto out_config_fini; 850 } --- 21 unchanged lines hidden --- | 857 rc = -1; 858 goto out_config_fini; 859 } 860 861 rc = tty_init(console, config, config_tty_kname); 862 if (rc) { 863 goto out_config_fini; 864 } --- 21 unchanged lines hidden --- |