From 35f4a9220aa9769a75e5950aa02d514edeb0ffa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 29 Feb 2008 09:10:44 +0000 Subject: [PATCH] * Now always adds a newline at the end of the given arguments. This fixes bug #1875. * This does not apply when retrieving the string from stdin, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24176 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/logger.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bin/logger.cpp b/src/bin/logger.cpp index 9219ad35a2..1cbeb3a6d6 100644 --- a/src/bin/logger.cpp +++ b/src/bin/logger.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2006-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -108,7 +108,8 @@ get_priority(const char *option) static void usage(void) { - fprintf(stderr, "usage: %s [-i] [-t ] [-p <[facility.]priority>] \n\n" + fprintf(stderr, "usage: %s [-i] [-t ] [-p <[facility.]priority>] " + "\n\n" "Sends a message to the system logging facility.\n" "If is omitted, the message is read from stdin.\n\n" " -i\tAdds the team ID to the log.\n" @@ -175,7 +176,7 @@ main(int argc, char **argv) for (int32 i = 0; i < argc; i++) { int32 newLength = length + strlen(argv[i]) + 1; - buffer = (char *)realloc(buffer, newLength); + buffer = (char *)realloc(buffer, newLength + 1); if (buffer == NULL) { fprintf(stderr, "%s: out of memory\n", sProgramName); return -1; @@ -187,7 +188,12 @@ main(int argc, char **argv) buffer[length - 1] = ' '; } - buffer[length - 1] = '\0'; + if (length > 1 && buffer[length - 2] != '\n') { + buffer[length - 1] = '\n'; + buffer[length] = '\0'; + } else + buffer[length - 1] = '\0'; + syslog(priority, "%s", buffer); free(buffer); } else {