| commit | 28a1761ac718dcaa7a21ff91cfc3c8806650c766 | [log] [tgz] |
|---|---|---|
| author | Andrew Jeffery <andrew@codeconstruct.com.au> | Wed Jul 10 09:32:05 2024 +0930 |
| committer | Andrew Jeffery <andrew@codeconstruct.com.au> | Wed Jul 10 09:56:53 2024 +0930 |
| tree | 611b355e30a442840b9ed30bb0ece6fbe9e3463e | |
| parent | ab64dadd9506d6f93ff98b9e1d51d12a9df76523 [diff] |
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>
To build this project, run the following shell commands:
meson setup build meson compile -C build
To test:
meson test -C build
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 to the server, simply run the client:
./obmc-console-client
To disconnect the client, use the standard ~. combination.
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.