diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-04-14 21:45:29 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-04-14 21:45:29 +0000 |
commit | 95c1c1e05f290ccbcc2ff863a62bcee5d57bf5c8 (patch) | |
tree | 3b89971f6401d4cf4f8d94d28e8b528bef789486 /sysklogd | |
parent | d5ba77d03ee32b6757005ebd58c04b845b3a151a (diff) | |
download | busybox-w32-95c1c1e05f290ccbcc2ff863a62bcee5d57bf5c8.tar.gz busybox-w32-95c1c1e05f290ccbcc2ff863a62bcee5d57bf5c8.tar.bz2 busybox-w32-95c1c1e05f290ccbcc2ff863a62bcee5d57bf5c8.zip |
Fix a tar bug: tar removed leading '/'s for symlink targets.
Fix a syslogd bug: Only the first sizeof(buffer) was read from the
/dev/log socket, causing (for most cases) only every other log item to be logged.
-Erik
Diffstat (limited to 'sysklogd')
-rw-r--r-- | sysklogd/syslogd.c | 64 |
1 files changed, 20 insertions, 44 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index ec372fc56..8827265d5 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -81,21 +81,17 @@ static void message(char *fmt, ...) | |||
81 | int fd; | 81 | int fd; |
82 | va_list arguments; | 82 | va_list arguments; |
83 | 83 | ||
84 | if ( | 84 | if ( (fd = device_open(logFilePath, |
85 | (fd = | 85 | O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | |
86 | device_open(logFilePath, | 86 | O_NONBLOCK)) >= 0) { |
87 | O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | | ||
88 | O_NONBLOCK)) >= 0) { | ||
89 | va_start(arguments, fmt); | 87 | va_start(arguments, fmt); |
90 | vdprintf(fd, fmt, arguments); | 88 | vdprintf(fd, fmt, arguments); |
91 | va_end(arguments); | 89 | va_end(arguments); |
92 | close(fd); | 90 | close(fd); |
93 | } else { | 91 | } else { |
94 | /* Always send console messages to /dev/console so people will see them. */ | 92 | /* Always send console messages to /dev/console so people will see them. */ |
95 | if ( | 93 | if ( (fd = device_open(_PATH_CONSOLE, |
96 | (fd = | 94 | O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) { |
97 | device_open(_PATH_CONSOLE, | ||
98 | O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) { | ||
99 | va_start(arguments, fmt); | 95 | va_start(arguments, fmt); |
100 | vdprintf(fd, fmt, arguments); | 96 | vdprintf(fd, fmt, arguments); |
101 | va_end(arguments); | 97 | va_end(arguments); |
@@ -177,14 +173,10 @@ static void doSyslogd (void) | |||
177 | signal (SIGALRM, domark); | 173 | signal (SIGALRM, domark); |
178 | alarm (MarkInterval); | 174 | alarm (MarkInterval); |
179 | 175 | ||
180 | /* create the syslog file so realpath() can work | 176 | /* create the syslog file so realpath() can work */ |
181 | * (the ugle close(open()) stuff is just a cheap | 177 | close(open(_PATH_LOG, O_RDWR | O_CREAT, 0644)); |
182 | * touch command that avoids using system (system | ||
183 | * is always a bad thing to use) */ | ||
184 | close(open("touch " _PATH_LOG, O_RDWR | O_CREAT, 0644)); | ||
185 | if (realpath(_PATH_LOG, lfile) == NULL) { | 178 | if (realpath(_PATH_LOG, lfile) == NULL) { |
186 | perror("Could not resolv path to " _PATH_LOG); | 179 | fatalError("Could not resolv path to " _PATH_LOG); |
187 | exit (FALSE); | ||
188 | } | 180 | } |
189 | 181 | ||
190 | unlink (lfile); | 182 | unlink (lfile); |
@@ -194,20 +186,17 @@ static void doSyslogd (void) | |||
194 | sunx.sun_family = AF_UNIX; | 186 | sunx.sun_family = AF_UNIX; |
195 | strncpy (sunx.sun_path, lfile, sizeof(sunx.sun_path)); | 187 | strncpy (sunx.sun_path, lfile, sizeof(sunx.sun_path)); |
196 | if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { | 188 | if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { |
197 | perror ("Couldn't obtain descriptor for socket " _PATH_LOG); | 189 | fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG); |
198 | exit (FALSE); | ||
199 | } | 190 | } |
200 | 191 | ||
201 | addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path); | 192 | addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path); |
202 | if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || | 193 | if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || |
203 | (listen (sock_fd, 5))) { | 194 | (listen (sock_fd, 5))) { |
204 | perror ("Could not connect to socket " _PATH_LOG); | 195 | fatalError ("Could not connect to socket " _PATH_LOG); |
205 | exit (FALSE); | ||
206 | } | 196 | } |
207 | 197 | ||
208 | if (chmod (lfile, 0666) < 0) { | 198 | if (chmod (lfile, 0666) < 0) { |
209 | perror ("Could not set permission on " _PATH_LOG); | 199 | fatalError ("Could not set permission on " _PATH_LOG); |
210 | exit (FALSE); | ||
211 | } | 200 | } |
212 | 201 | ||
213 | FD_ZERO (&readfds); | 202 | FD_ZERO (&readfds); |
@@ -221,19 +210,17 @@ static void doSyslogd (void) | |||
221 | 210 | ||
222 | if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) { | 211 | if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) { |
223 | if (errno == EINTR) continue; /* alarm may have happened. */ | 212 | if (errno == EINTR) continue; /* alarm may have happened. */ |
224 | perror ("select"); | 213 | fatalError( "select error: %s\n", strerror(errno)); |
225 | exit (FALSE); | ||
226 | } | 214 | } |
227 | 215 | ||
228 | /* Skip stdin, stdout, stderr */ | 216 | /* Skip stdin, stdout, stderr */ |
229 | for (fd = 3; fd <= FD_SETSIZE; fd++) { | 217 | for (fd = 3; fd < FD_SETSIZE; fd++) { |
230 | if (FD_ISSET (fd, &readfds)) { | 218 | if (FD_ISSET (fd, &readfds)) { |
231 | if (fd == sock_fd) { | 219 | if (fd == sock_fd) { |
232 | int conn; | 220 | int conn; |
233 | if ((conn = accept(sock_fd, (struct sockaddr *) &sunx, | 221 | if ((conn = accept(sock_fd, (struct sockaddr *) &sunx, |
234 | &addrLength)) < 0) { | 222 | &addrLength)) < 0) { |
235 | perror ("accept"); | 223 | fatalError( "accept error: %s\n", strerror(errno)); |
236 | exit (FALSE); /* #### ??? */ | ||
237 | } | 224 | } |
238 | FD_SET (conn, &readfds); | 225 | FD_SET (conn, &readfds); |
239 | } | 226 | } |
@@ -242,17 +229,11 @@ static void doSyslogd (void) | |||
242 | char buf[BUFSIZE]; | 229 | char buf[BUFSIZE]; |
243 | char *q, *p; | 230 | char *q, *p; |
244 | int n_read; | 231 | int n_read; |
232 | char line[BUFSIZE]; | ||
233 | unsigned char c; | ||
245 | 234 | ||
246 | n_read = read (fd, buf, BUFSIZE); | 235 | /* Keep reading stuff till there is nothing else to read */ |
247 | 236 | while( (n_read = read (fd, buf, BUFSIZE)) > 0 && errno != EOF) { | |
248 | if (n_read < 0) { | ||
249 | // FIXME .. fd isn't set | ||
250 | perror ("read error"); | ||
251 | goto close_fd; | ||
252 | } | ||
253 | else if (n_read > 0) { | ||
254 | char line[BUFSIZE]; | ||
255 | unsigned char c; | ||
256 | int pri = (LOG_USER | LOG_NOTICE); | 237 | int pri = (LOG_USER | LOG_NOTICE); |
257 | 238 | ||
258 | memset (line, 0, sizeof(line)); | 239 | memset (line, 0, sizeof(line)); |
@@ -281,14 +262,9 @@ static void doSyslogd (void) | |||
281 | 262 | ||
282 | /* Now log it */ | 263 | /* Now log it */ |
283 | logMessage(pri, line); | 264 | logMessage(pri, line); |
284 | |||
285 | close_fd: | ||
286 | close (fd); | ||
287 | FD_CLR (fd, &readfds); | ||
288 | } | ||
289 | else { /* EOF */ | ||
290 | goto close_fd; | ||
291 | } | 265 | } |
266 | close (fd); | ||
267 | FD_CLR (fd, &readfds); | ||
292 | } | 268 | } |
293 | } | 269 | } |
294 | } | 270 | } |