mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Follow-up to 96f944b: fix regression in status output at boot
status() returns a pointer to a single static buffer, so calling it twice in the same cprintf() argument list — status(3) and status(rc) — causes one to overwrite the other before the format string is rendered. When status(3) wins, the line shows [ ⋯ ] instead of [ OK ]. Fix by copying status(rc) into a local buffer before calling status(3). Also drop the delline() calls added to print() — that macro writes \033[2K to buffered stdout while cprintf() writes unbuffered to stderr, so the erase sequences can arrive out of order. The \r\e[K already present in the cprintf format strings makes them redundant anyway. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+9
-4
@@ -379,7 +379,6 @@ void print(int rc, const char *fmt, ...)
|
||||
/* Pending state: show description with spinner, no final status yet */
|
||||
if (!buf[0])
|
||||
return;
|
||||
delline();
|
||||
if (progress_style == PROGRESS_CLASSIC)
|
||||
cprintf("\r%s ", pad(buf, sizeof(buf), ".", sizeof(buf)));
|
||||
else
|
||||
@@ -391,15 +390,21 @@ void print(int rc, const char *fmt, ...)
|
||||
* Final status. Emit description + status in a single cprintf() so
|
||||
* both reach the console in one write(), preventing kernel messages or
|
||||
* command output from splitting the description from its [ OK ]/[FAIL].
|
||||
*
|
||||
* status() returns a pointer to a static buffer, so we must copy the
|
||||
* result for rc before calling status(3) — the second call overwrites
|
||||
* the same buffer, corrupting the first result.
|
||||
*/
|
||||
last_desc[0] = 0;
|
||||
|
||||
if (buf[0]) {
|
||||
delline();
|
||||
char st[64];
|
||||
|
||||
strlcpy(st, status(rc), sizeof(st));
|
||||
if (progress_style == PROGRESS_CLASSIC)
|
||||
cprintf("\r%s %s\n", pad(buf, sizeof(buf), ".", sizeof(buf)), status(rc));
|
||||
cprintf("\r%s %s\n", pad(buf, sizeof(buf), ".", sizeof(buf)), st);
|
||||
else
|
||||
cprintf("\r\e[K%s%s\r%s\n", status(3), buf, status(rc));
|
||||
cprintf("\r\e[K%s%s\r%s\n", status(3), buf, st);
|
||||
} else {
|
||||
if (progress_style == PROGRESS_CLASSIC)
|
||||
cprintf("%s\n", status(rc));
|
||||
|
||||
Reference in New Issue
Block a user