diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-01-23 01:34:05 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-01-23 01:34:05 +0000 |
commit | de552874d2074ac48ea4b834d61c54e1b6971be3 (patch) | |
tree | 0360b39142f1c85e1cac2637e09c6e452cf1a444 /sysklogd/logger.c | |
parent | f4acea8cf5175de2292c86b58f2f30d262f14345 (diff) | |
download | busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.tar.gz busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.tar.bz2 busybox-w32-de552874d2074ac48ea4b834d61c54e1b6971be3.zip |
Some busybox updates. You no longer _have_ to put a "-" in front of tar
options, logger is better behaved and has a "-t" option now. init now supports
the kernel chroot patch, so you can chroot to a new device and umount the old
root.
-Erik
Diffstat (limited to 'sysklogd/logger.c')
-rw-r--r-- | sysklogd/logger.c | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 7aada5dbc..d7ae0233e 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -22,16 +22,11 @@ | |||
22 | 22 | ||
23 | #include "internal.h" | 23 | #include "internal.h" |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <sys/socket.h> | ||
26 | #include <sys/un.h> | ||
27 | #include <unistd.h> | 25 | #include <unistd.h> |
28 | #include <time.h> | ||
29 | #include <sys/types.h> | 26 | #include <sys/types.h> |
30 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
31 | #include <fcntl.h> | 28 | #include <fcntl.h> |
32 | #include <signal.h> | ||
33 | #include <ctype.h> | 29 | #include <ctype.h> |
34 | #include <netdb.h> | ||
35 | 30 | ||
36 | #if !defined BB_SYSLOGD | 31 | #if !defined BB_SYSLOGD |
37 | 32 | ||
@@ -56,6 +51,7 @@ static const char logger_usage[] = | |||
56 | "Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" | 51 | "Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" |
57 | "Options:\n" | 52 | "Options:\n" |
58 | "\t-s\tLog to stderr as well as the system log.\n" | 53 | "\t-s\tLog to stderr as well as the system log.\n" |
54 | "\t-t\tLog using the specified tag (defaults to user name).\n" | ||
59 | "\t-p\tEnter the message with the specified priority.\n" | 55 | "\t-p\tEnter the message with the specified priority.\n" |
60 | "\t\tThis may be numerical or a ``facility.level'' pair.\n"; | 56 | "\t\tThis may be numerical or a ``facility.level'' pair.\n"; |
61 | 57 | ||
@@ -116,14 +112,14 @@ pencode(char* s) | |||
116 | 112 | ||
117 | extern int logger_main(int argc, char **argv) | 113 | extern int logger_main(int argc, char **argv) |
118 | { | 114 | { |
119 | struct sockaddr_un sunx; | 115 | int pri = LOG_USER|LOG_NOTICE; |
120 | int fd, pri = LOG_USER|LOG_NOTICE; | 116 | int option = 0; |
121 | int fromStdinFlag=FALSE; | 117 | int fromStdinFlag=FALSE; |
122 | int toStdErrFlag=FALSE; | ||
123 | int stopLookingAtMeLikeThat=FALSE; | 118 | int stopLookingAtMeLikeThat=FALSE; |
124 | char *message, buf[1024], buf1[1024]; | 119 | char *message, buf[1024], name[128]; |
125 | time_t now; | 120 | |
126 | size_t addrLength; | 121 | /* Fill out the name string early (may be overwritten later */ |
122 | my_getpwuid(name, geteuid()); | ||
127 | 123 | ||
128 | /* Parse any options */ | 124 | /* Parse any options */ |
129 | while (--argc > 0 && **(++argv) == '-') { | 125 | while (--argc > 0 && **(++argv) == '-') { |
@@ -134,7 +130,7 @@ extern int logger_main(int argc, char **argv) | |||
134 | while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) { | 130 | while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) { |
135 | switch (**argv) { | 131 | switch (**argv) { |
136 | case 's': | 132 | case 's': |
137 | toStdErrFlag = TRUE; | 133 | option |= LOG_PERROR; |
138 | break; | 134 | break; |
139 | case 'p': | 135 | case 'p': |
140 | if (--argc == 0) { | 136 | if (--argc == 0) { |
@@ -143,6 +139,13 @@ extern int logger_main(int argc, char **argv) | |||
143 | pri = pencode(*(++argv)); | 139 | pri = pencode(*(++argv)); |
144 | stopLookingAtMeLikeThat=TRUE; | 140 | stopLookingAtMeLikeThat=TRUE; |
145 | break; | 141 | break; |
142 | case 't': | ||
143 | if (--argc == 0) { | ||
144 | usage(logger_usage); | ||
145 | } | ||
146 | strncpy(name, *(++argv), sizeof(name)); | ||
147 | stopLookingAtMeLikeThat=TRUE; | ||
148 | break; | ||
146 | default: | 149 | default: |
147 | usage(logger_usage); | 150 | usage(logger_usage); |
148 | } | 151 | } |
@@ -152,10 +155,10 @@ extern int logger_main(int argc, char **argv) | |||
152 | if (fromStdinFlag==TRUE) { | 155 | if (fromStdinFlag==TRUE) { |
153 | /* read from stdin */ | 156 | /* read from stdin */ |
154 | int c, i=0; | 157 | int c, i=0; |
155 | while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) { | 158 | while ((c = getc(stdin)) != EOF && i<sizeof(buf)) { |
156 | buf1[i++]=c; | 159 | buf[i++]=c; |
157 | } | 160 | } |
158 | message=buf1; | 161 | message=buf; |
159 | } else { | 162 | } else { |
160 | if (argc>=1) { | 163 | if (argc>=1) { |
161 | message=*argv; | 164 | message=*argv; |
@@ -165,30 +168,10 @@ extern int logger_main(int argc, char **argv) | |||
165 | } | 168 | } |
166 | } | 169 | } |
167 | 170 | ||
168 | memset(&sunx, 0, sizeof(sunx)); | 171 | openlog( name, option, (pri | LOG_FACMASK)); |
169 | sunx.sun_family = AF_UNIX; /* Unix domain socket */ | 172 | syslog( pri, message); |
170 | strncpy(sunx.sun_path, _PATH_LOG, sizeof(sunx.sun_path)); | 173 | closelog(); |
171 | if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) { | ||
172 | perror("Couldn't obtain descriptor for socket " _PATH_LOG); | ||
173 | exit( FALSE); | ||
174 | } | ||
175 | |||
176 | addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); | ||
177 | |||
178 | if (connect(fd, (struct sockaddr *) &sunx, addrLength)) { | ||
179 | perror("Could not connect to socket " _PATH_LOG); | ||
180 | exit( FALSE); | ||
181 | } | ||
182 | |||
183 | time(&now); | ||
184 | snprintf (buf, sizeof(buf), "<%d>%.15s %s", pri, ctime(&now)+4, message); | ||
185 | |||
186 | if (toStdErrFlag==TRUE) | ||
187 | fprintf(stderr, "%s\n", buf); | ||
188 | |||
189 | write( fd, buf, strlen(buf)+1); | ||
190 | 174 | ||
191 | close(fd); | ||
192 | exit( TRUE); | 175 | exit( TRUE); |
193 | } | 176 | } |
194 | 177 | ||