/*
* Mini syslogd implementation for busybox
*
- * Copyright (C) 1999,2000,2001 by Lineo, inc.
- * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
*
* Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
*
#define __LOG_FILE "/var/log/messages"
/* Path to the unix socket */
-static char lfile[BUFSIZ] = "";
+static char lfile[BUFSIZ];
static char *logFilePath = __LOG_FILE;
/* localhost's name */
static char LocalHostName[32];
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
#include <netinet/in.h>
/* udp socket for logging to remote host */
static int remotefd = -1;
#endif
/* circular buffer variables/structures */
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+
+#if __GNU_LIBRARY__ < 5
+#error Sorry. Looks like you are using libc5.
+#error libc5 shm support isnt good enough.
+#error Please disable CONFIG_FEATURE_IPC_SYSLOG
+#endif
#include <sys/ipc.h>
#include <sys/sem.h>
fl.l_start = 0;
fl.l_len = 1;
-#ifdef BB_FEATURE_IPC_SYSLOG
- if ((circular_logging == TRUE) && (buf != NULL)){
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+ if ((circular_logging) && (buf != NULL)){
char b[1024];
va_start (arguments, fmt);
vsprintf (b, fmt, arguments);
/* todo: supress duplicates */
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
/* send message to remote logger */
if ( -1 != remotefd){
static const int IOV_COUNT = 2;
struct iovec iov[IOV_COUNT];
struct iovec *v = iov;
- bzero(&res, sizeof(res));
+ memset(&res, 0, sizeof(res));
snprintf(res, sizeof(res), "<%d>", pri);
v->iov_base = res ;
v->iov_len = strlen(res);
"%s:%d",RemoteHost,RemotePort);
}
}
- if (local_logging == TRUE)
+ if (local_logging)
#endif
/* now spew out the message to wherever it is supposed to go */
message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
{
logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting.");
unlink(lfile);
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
ipcsyslog_cleanup();
#endif
#define BUFSIZE 1023
static int serveConnection (int conn)
{
- RESERVE_BB_BUFFER(tmpbuf, BUFSIZE + 1);
+ RESERVE_CONFIG_BUFFER(tmpbuf, BUFSIZE + 1);
int n_read;
+ char *p = tmpbuf;
n_read = read (conn, tmpbuf, BUFSIZE );
- if (n_read > 0) {
+ while (p < tmpbuf + n_read) {
int pri = (LOG_USER | LOG_NOTICE);
char line[ BUFSIZE + 1 ];
unsigned char c;
- char *p = tmpbuf, *q = line;
+ char *q = line;
tmpbuf[ n_read - 1 ] = '\0';
p++;
}
*q = '\0';
+ p++;
/* Now log it */
logMessage (pri, line);
}
+ RELEASE_CONFIG_BUFFER (tmpbuf);
return n_read;
}
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
static void init_RemoteLog (void){
struct sockaddr_in remoteaddr;
struct hostent *hostinfo;
int len = sizeof(remoteaddr);
- bzero(&remoteaddr, len);
+ memset(&remoteaddr, 0, len);
remotefd = socket(AF_INET, SOCK_DGRAM, 0);
FD_ZERO (&fds);
FD_SET (sock_fd, &fds);
-#ifdef BB_FEATURE_IPC_SYSLOG
- if (circular_logging == TRUE ){
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
+ if (circular_logging ){
ipcsyslog_init();
}
#endif
- #ifdef BB_FEATURE_REMOTE_LOG
- if (doRemoteLog == TRUE){
+ #ifdef CONFIG_FEATURE_REMOTE_LOG
+ if (doRemoteLog){
init_RemoteLog();
}
#endif
doFork = FALSE;
break;
case 'O':
- logFilePath = strdup(optarg);
+ logFilePath = xstrdup(optarg);
break;
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
case 'R':
- RemoteHost = strdup(optarg);
+ RemoteHost = xstrdup(optarg);
if ( (p = strchr(RemoteHost, ':'))){
RemotePort = atoi(p+1);
*p = '\0';
local_logging = TRUE;
break;
#endif
-#ifdef BB_FEATURE_IPC_SYSLOG
+#ifdef CONFIG_FEATURE_IPC_SYSLOG
case 'C':
circular_logging = TRUE;
break;
}
}
-#ifdef BB_FEATURE_REMOTE_LOG
+#ifdef CONFIG_FEATURE_REMOTE_LOG
/* If they have not specified remote logging, then log locally */
- if (doRemoteLog == FALSE)
+ if (! doRemoteLog)
local_logging = TRUE;
#endif
umask(0);
- if (doFork == TRUE) {
+ if (doFork) {
+#if !defined(__UCLIBC__) || defined(__UCLIBC_HAS_MMU__)
if (daemon(0, 1) < 0)
perror_msg_and_die("daemon");
+#else
+ error_msg_and_die("daemon not supported");
+#endif
}
doSyslogd();