Skip to content

Commit de21b0b

Browse files
committed
rtapi: RTAI ends every message that lacks the newline too
The RTAI kernel handler and rtapi_print_msg() in RTAI user space follow the same rule as uspace: every rtapi_print_msg() message is a line, and rtapi_print() prints like printf. printk() shows a message without the newline only when the next one comes. The kernel handler now gives rt_printk() the text as an argument instead of as the format. Hannes Diethelm pointed out both on #4697.
1 parent 0440f1c commit de21b0b

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/rtapi/rtai_rtapi.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,19 @@ int rtapi_snprintf(char *buf, unsigned long int size, const char *fmt, ...)
433433

434434
#define BUFFERLEN 1024
435435

436+
/* Every rtapi_print_msg() message is one line: end one that lacks the
437+
newline. rtapi_print() (RTAPI_MSG_ALL) prints like printf. */
436438
void default_rtapi_msg_handler(msg_level_t level, const char *fmt, va_list ap) {
437439
char buf[BUFFERLEN];
438-
rtapi_vsnprintf(buf, BUFFERLEN, fmt, ap);
439-
rt_printk(buf);
440+
size_t n;
441+
/* leave room for the newline */
442+
rtapi_vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
443+
n = strlen(buf);
444+
if (level != RTAPI_MSG_ALL && n > 0 && buf[n - 1] != '\n') {
445+
buf[n] = '\n';
446+
buf[n + 1] = '\0';
447+
}
448+
rt_printk("%s", buf);
440449
}
441450
static rtapi_msg_handler_t rtapi_msg_handler = default_rtapi_msg_handler;
442451

‎src/rtapi/rtai_ulapi.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,18 @@ void rtapi_print_msg(msg_level_t level, const char *fmt, ...)
269269
va_list args;
270270

271271
if ((level <= msg_level) && (msg_level != RTAPI_MSG_NONE)) {
272+
/* one message is one line: end one that lacks the newline */
273+
char *msg;
274+
int n;
272275
va_start(args, fmt);
273-
vfprintf(stderr, fmt, args);
276+
n = vasprintf(&msg, fmt, args);
274277
va_end(args);
278+
if (n < 0)
279+
return;
280+
fputs(msg, stderr);
281+
if (level != RTAPI_MSG_ALL && n > 0 && msg[n - 1] != '\n')
282+
fputc('\n', stderr);
283+
free(msg);
275284
}
276285
}
277286

0 commit comments

Comments
 (0)