Skip to content

Conversation

@JeepWay
Copy link
Contributor

@JeepWay JeepWay commented Apr 29, 2025

When reading /sys/class/kxo/kxo/kxo_state using cat, the output lacked a newline, causing the terminal prompt to appear on the same line (e.g., 1 1 0user@Ubuntu:~$).

The issue was diagnosed by analyzing kxo_state_show: the snprintf function was called with a size parameter of 6, which includes the null terminator (\0). This left only 5 bytes for the output (e.g., 1 0 0\n), truncating the newline character (\n). Thus, kxo_state_show outputs 1 0 0\0, not 1 0 0\n\0.

This patch fixes the issue by increasing the size parameter of snprintf from 6 to 7, ensuring the output includes the newline.

hachmd record

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to mention the kernel module in the git commit message as "kxo" already indicates which kernel module is being referenced. Instead, the message should emphasize how you diagnosed and resolved the unintended truncation issue.

When using cat command to read /sys/class/kxo/kxo/kxo_state file, the
output (e.g., "1 1 0") did not include a newline, causing the terminal
prompt to appear on the same line (e.g., "1 1 0user@Ubuntu:~$").

This truncation issue is diagnosed by examining kxo_state_show, which
uses snprintf with a format string "%c %c %c\n". The size parameter of
snprintf set to 6 included the null terminator \0 as the last character,
leaving only 5 bytes for the desired output (e.g., "1 0 0\n"), thus the
newline symbol \n was truncated by null terminator.

This commit resolves the issue by increasing the size parameter of
snprintf from 6 to 7, ensuring the output includes the newline.
@JeepWay JeepWay force-pushed the show-missing-newline branch from 9390568 to 2829628 Compare April 30, 2025 06:37
@JeepWay JeepWay changed the title Fix missing newline in kxo_state_show output Fix missing newline in sysfs file kxo_state Apr 30, 2025
@JeepWay
Copy link
Contributor Author

JeepWay commented Apr 30, 2025

It is not necessary to mention the kernel module in the git commit message as "kxo" already indicates which kernel module is being referenced. Instead, the message should emphasize how you diagnosed and resolved the unintended truncation issue.

@jserv I have updated the original commit message to emphasize the diagnosis and resolving process.

@JeepWay JeepWay requested a review from jserv April 30, 2025 07:08
@jserv jserv merged commit 04978e7 into sysprog21:main Apr 30, 2025
@jserv
Copy link
Contributor

jserv commented Apr 30, 2025

Thank @JeepWay for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants