console-server: Avoid SEGV on on failure to load configuration

On a system without a file at the default configuration path we hit
a SEGV:

```
$ ./build/obmc-console-server -i test $(realpath pts)
obmc-console-server: Can't open configuration file etc/obmc-console.conf: No such file or directory
../config.c:56:48: runtime error: member access within null pointer of type 'struct config'
AddressSanitizer:DEADLYSIGNAL
=================================================================
==693793==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55be18aa0d76 bp 0x7ffe1f8a5640 sp 0x7ffe1f8a53a0 T0)
==693793==The signal is caused by a READ memory access.
==693793==Hint: address points to the zero page.
    #0 0x55be18aa0d76 in config_get_value ../config.c:56
    #1 0x55be18a9e10e in main ../console-server.c:985
    #2 0x7f80bd046249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #3 0x7f80bd046304 in __libc_start_main_impl ../csu/libc-start.c:360
    #4 0x55be18aa0be0 in _start (/home/andrew/src/openbmc.org/openbmc/obmc-console/build/obmc-console-server+0x25be0)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../config.c:56 in config_get_value
==693793==ABORTING
```

Rework the cleanup sequence in main() to avoid the problem.

Change-Id: I6cbea10889d65666d660ee198c4ad6f6935fea85
Fixes: 1e04f449b7f0 ("use iniparser dependency for config file parsing")
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 file changed
tree: 611b355e30a442840b9ed30bb0ece6fbe9e3463e
  1. conf/
  2. subprojects/
  3. test/
  4. .clang-format
  5. .clang-tidy
  6. .gitignore
  7. .travis.yml
  8. CHANGELOG.md
  9. config-internal.h
  10. config.c
  11. config.h
  12. console-client.c
  13. console-dbus.c
  14. console-server.c
  15. console-server.h
  16. console-socket.c
  17. LICENSE
  18. log-handler.c
  19. meson.build
  20. meson.options
  21. OWNERS
  22. README.md
  23. ringbuffer.c
  24. socket-handler.c
  25. tty-handler.c
  26. util.c
README.md

To Build

To build this project, run the following shell commands:

meson setup build
meson compile -C build

To test:

meson test -C build

To Run Server

Running the server requires a serial port (e.g. /dev/ttyS0):

touch obmc-console.conf
./obmc-console-server --config obmc-console.conf ttyS0

To Connect Client

To connect to the server, simply run the client:

./obmc-console-client

To disconnect the client, use the standard ~. combination.

Underlying design

This shows how the host UART connection is abstracted within the BMC as a Unix domain socket.

               +---------------------------------------------------------------------------------------------+
               |                                                                                             |
               |       obmc-console-client       unix domain socket         obmc-console-server              |
               |                                                                                             |
               |     +----------------------+                           +------------------------+           |
               |     |   client.2200.conf   |  +---------------------+  | server.ttyVUART0.conf  |           |
           +---+--+  +----------------------+  |                     |  +------------------------+  +--------+-------+
Network    | 2200 +-->                      +->+ @obmc-console.host0 +<-+                        <--+ /dev/ttyVUART0 |   UARTs
           +---+--+  | console-id = "host0" |  |                     |  |  console-id = "host0"  |  +--------+-------+
               |     |                      |  +---------------------+  |                        |           |
               |     +----------------------+                           +------------------------+           |
               |                                                                                             |
               |                                                                                             |
               |                                                                                             |
               +---------------------------------------------------------------------------------------------+

This supports multiple independent consoles. The console-id is a unique portion for the unix domain socket created by the obmc-console-server instance. The server needs to know this because it needs to know what to name the pipe; the client needs to know it as it needs to form the abstract socket name to which to connect.