commit | 2f1abc37384d6a5fda99f89b20ca0c11db940663 | [log] [tgz] |
---|---|---|
author | John Wang <wangzhiqiang02@ieisystem.com> | Tue Jun 04 20:58:33 2024 +0800 |
committer | John Wang <wangzhiqiang02@ieisystem.com> | Wed Jun 05 12:50:27 2024 +0800 |
tree | e73029c738cf7f2c571af30f49f7f8493afa6949 | |
parent | b7dddbc63e601298474dee68ea4c0cc25b865461 [diff] |
Fix realloc() with size 0 Valgrind reported “realloc() with size 0" ''' ==508== realloc() with size 0 ==508== at 0x484DB80: realloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==508== by 0x1093E3: ringbuffer_consumer_unregister (ringbuffer.c:103) ==508== by 0x10942B: ringbuffer_fini (ringbuffer.c:48) ==508== by 0x109989: test_simple_poll (test-ringbuffer-simple-poll.c:31) ==508== by 0x109A3A: main (test-ringbuffer-simple-poll.c:37) ''' And gnu libc manual[1] said: Portable programs should not attempt to reallocate blocks to be size zero. On other implementations if ptr is non-null, realloc (ptr, 0) might free the block and return a non-null pointer to a size-zero object, or it might fail and return NULL without freeing the block. The ISO C17 standard allows these variations. So use free instead of realloc with size 0 [1] https://www.gnu.org/software/libc/manual/html_node/Changing-Block-Size.html Change-Id: Ie716dd6ea84696a2091c680d71a0624423d1a185 Signed-off-by: John Wang <wangzhiqiang02@ieisystem.com>
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.