aboutsummaryrefslogtreecommitdiff
path: root/sysklogd/logger.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysklogd/logger.c')
-rw-r--r--sysklogd/logger.c54
1 files changed, 19 insertions, 35 deletions
diff --git a/sysklogd/logger.c b/sysklogd/logger.c
index 8901bd79f..3a4f51575 100644
--- a/sysklogd/logger.c
+++ b/sysklogd/logger.c
@@ -8,13 +8,6 @@
8 */ 8 */
9 9
10#include "busybox.h" 10#include "busybox.h"
11#include <stdio.h>
12#include <unistd.h>
13#include <sys/types.h>
14#include <fcntl.h>
15#include <ctype.h>
16#include <string.h>
17#include <stdlib.h>
18 11
19#if !defined CONFIG_SYSLOGD 12#if !defined CONFIG_SYSLOGD
20 13
@@ -93,49 +86,40 @@ int logger_main(int argc, char **argv)
93 char *opt_p, *opt_t; 86 char *opt_p, *opt_t;
94 int pri = LOG_USER | LOG_NOTICE; 87 int pri = LOG_USER | LOG_NOTICE;
95 int option = 0; 88 int option = 0;
96 int c, i; 89 char name[80];
97 char buf[1024], name[128];
98 90
99 /* Fill out the name string early (may be overwritten later) */ 91 /* Fill out the name string early (may be overwritten later) */
100 bb_getpwuid(name, geteuid(), sizeof(name)); 92 bb_getpwuid(name, geteuid(), sizeof(name));
101 93
102 /* Parse any options */ 94 /* Parse any options */
103 opt = getopt32(argc, argv, "p:st:", &opt_p, &opt_t); 95 opt = getopt32(argc, argv, "p:st:", &opt_p, &opt_t);
96 argc -= optind;
97 argv += optind;
104 if (opt & 0x1) pri = pencode(opt_p); // -p 98 if (opt & 0x1) pri = pencode(opt_p); // -p
105 if (opt & 0x2) option |= LOG_PERROR; // -s 99 if (opt & 0x2) option |= LOG_PERROR; // -s
106 if (opt & 0x4) safe_strncpy(name, opt_t, sizeof(name)); // -t 100 if (opt & 0x4) safe_strncpy(name, opt_t, sizeof(name)); // -t
107 101
108 openlog(name, option, 0); 102 openlog(name, option, 0);
109 if (optind == argc) { 103 if (!argc) {
110 do { 104 while (fgets(bb_common_bufsiz1, BUFSIZ, stdin)) {
111 /* read from stdin */ 105 if (bb_common_bufsiz1[0]
112 i = 0; 106 && NOT_LONE_CHAR(bb_common_bufsiz1, '\n')
113 while ((c = getc(stdin)) != EOF && c != '\n' && 107 ) {
114 i < (sizeof(buf)-1)) { 108 /* Neither "" nor "\n" */
115 buf[i++] = c; 109 syslog(pri, "%s", bb_common_bufsiz1);
116 }
117 if (i > 0) {
118 buf[i++] = '\0';
119 syslog(pri, "%s", buf);
120 } 110 }
121 } while (c != EOF); 111 }
122 } else { 112 } else {
123 char *message = NULL; 113 char *message = NULL;
124 int len = argc - optind; /* for the space between the args 114 int len = 1; /* for NUL */
125 and '\0' */ 115 int pos = 0;
126 opt = len; 116 do {
127 argv += optind; 117 len += strlen(*argv) + 1;
128 for (i = 0; i < opt; i++) {
129 len += strlen(*argv);
130 message = xrealloc(message, len); 118 message = xrealloc(message, len);
131 if(!i) 119 sprintf(message + pos, " %s", *argv),
132 message[0] = '\0'; 120 pos = len;
133 else 121 } while (*++argv);
134 strcat(message, " "); 122 syslog(pri, "%s", message + 1); /* skip leading " " */
135 strcat(message, *argv);
136 argv++;
137 }
138 syslog(pri, "%s", message);
139 } 123 }
140 124
141 closelog(); 125 closelog();