More stuff
-Erik
This commit is contained in:
parent
9a8195cc03
commit
f13df3752c
@ -5,6 +5,8 @@
|
|||||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
|
||||||
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -74,8 +76,7 @@ static const char syslogd_usage[] =
|
|||||||
|
|
||||||
/* Note: There is also a function called "message()" in init.c */
|
/* Note: There is also a function called "message()" in init.c */
|
||||||
/* Print a message to the log file. */
|
/* Print a message to the log file. */
|
||||||
static void message(char *fmt, ...)
|
static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
__attribute__ ((format (printf, 1, 2)));
|
|
||||||
static void message (char *fmt, ...)
|
static void message (char *fmt, ...)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -161,11 +162,13 @@ static void doSyslogd (void)
|
|||||||
{
|
{
|
||||||
struct sockaddr_un sunx;
|
struct sockaddr_un sunx;
|
||||||
size_t addrLength;
|
size_t addrLength;
|
||||||
|
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
fd_set readfds;
|
fd_set fds;
|
||||||
|
|
||||||
char lfile[PATH_MAX];
|
char lfile[PATH_MAX];
|
||||||
|
|
||||||
/* Set up sig handlers */
|
/* Set up signal handlers. */
|
||||||
signal (SIGINT, quit_signal);
|
signal (SIGINT, quit_signal);
|
||||||
signal (SIGTERM, quit_signal);
|
signal (SIGTERM, quit_signal);
|
||||||
signal (SIGQUIT, quit_signal);
|
signal (SIGQUIT, quit_signal);
|
||||||
@ -173,77 +176,72 @@ static void doSyslogd (void)
|
|||||||
signal (SIGALRM, domark);
|
signal (SIGALRM, domark);
|
||||||
alarm (MarkInterval);
|
alarm (MarkInterval);
|
||||||
|
|
||||||
/* create the syslog file so realpath() can work */
|
/* Create the syslog file so realpath() can work. */
|
||||||
close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
|
close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
|
||||||
if (realpath(_PATH_LOG, lfile) == NULL) {
|
if (realpath (_PATH_LOG, lfile) == NULL)
|
||||||
fatalError("Could not resolv path to " _PATH_LOG);
|
fatalError ("Could not resolv path to " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
unlink (lfile);
|
unlink (lfile);
|
||||||
|
|
||||||
memset (&sunx, 0, sizeof (sunx));
|
memset (&sunx, 0, sizeof (sunx));
|
||||||
|
|
||||||
sunx.sun_family = AF_UNIX;
|
sunx.sun_family = AF_UNIX;
|
||||||
strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
|
strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
|
||||||
if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||||
fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG);
|
fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
|
addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
|
||||||
if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) ||
|
if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
|
||||||
(listen (sock_fd, 5))) {
|
fatalError ("Could not connect to socket " _PATH_LOG ": %s", strerror (errno));
|
||||||
fatalError ("Could not connect to socket " _PATH_LOG);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chmod (lfile, 0666) < 0) {
|
if (chmod (lfile, 0666) < 0)
|
||||||
fatalError ("Could not set permission on " _PATH_LOG);
|
fatalError ("Could not set permission on " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&fds);
|
||||||
FD_SET (sock_fd, &readfds);
|
FD_SET (sock_fd, &fds);
|
||||||
|
|
||||||
logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
|
logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
|
fd_set readfds;
|
||||||
int n_ready;
|
int n_ready;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
memcpy (&readfds, &fds, sizeof (fds));
|
||||||
|
|
||||||
if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
|
if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
|
||||||
if (errno == EINTR) continue; /* alarm may have happened. */
|
if (errno == EINTR) continue; /* alarm may have happened. */
|
||||||
fatalError ("select error: %s\n", strerror (errno));
|
fatalError ("select error: %s\n", strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip stdin, stdout, stderr */
|
for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
|
||||||
for (fd = 3; fd < FD_SETSIZE; fd++) {
|
|
||||||
if (FD_ISSET (fd, &readfds)) {
|
if (FD_ISSET (fd, &readfds)) {
|
||||||
|
--n_ready;
|
||||||
if (fd == sock_fd) {
|
if (fd == sock_fd) {
|
||||||
int conn;
|
int conn;
|
||||||
if ((conn = accept(sock_fd, (struct sockaddr *) &sunx,
|
if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
|
||||||
&addrLength)) < 0) {
|
|
||||||
fatalError ("accept error: %s\n", strerror (errno));
|
fatalError ("accept error: %s\n", strerror (errno));
|
||||||
}
|
}
|
||||||
FD_SET (conn, &readfds);
|
FD_SET (conn, &fds);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#define BUFSIZE 1024 + 1
|
# define BUFSIZE 1023
|
||||||
char buf;
|
char buf[ BUFSIZE + 1 ];
|
||||||
char *q, *p;
|
|
||||||
int n_read;
|
int n_read;
|
||||||
char line[BUFSIZE];
|
|
||||||
|
while ((n_read = read (fd, buf, BUFSIZE )) > 0) {
|
||||||
|
|
||||||
|
int pri = (LOG_USER | LOG_NOTICE);
|
||||||
|
char line[ BUFSIZE + 1 ];
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int pri;
|
char *p = buf, *q = line;
|
||||||
|
|
||||||
/* Get set to read in a line */
|
buf[ n_read - 1 ] = '\0';
|
||||||
memset (line, 0, sizeof(line));
|
|
||||||
pri = (LOG_USER | LOG_NOTICE);
|
|
||||||
|
|
||||||
/* Keep reading stuff till there is nothing else to read */
|
|
||||||
while( (n_read = read (fd, &buf, 1)) > 0) {
|
|
||||||
p = &buf;
|
|
||||||
q = line;
|
|
||||||
while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
|
while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
|
||||||
if (c == '<') {
|
if (c == '<') {
|
||||||
/* Parse the magic priority number */
|
/* Parse the magic priority number. */
|
||||||
pri = 0;
|
pri = 0;
|
||||||
while (isdigit (*(++p))) {
|
while (isdigit (*(++p))) {
|
||||||
pri = 10 * pri + (*p - '0');
|
pri = 10 * pri + (*p - '0');
|
||||||
@ -261,13 +259,11 @@ static void doSyslogd (void)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
/* Now log it */
|
/* Now log it */
|
||||||
logMessage (pri, line);
|
logMessage (pri, line);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
FD_CLR (fd, &readfds);
|
FD_CLR (fd, &fds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,7 +347,6 @@ static void doKlogd (void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void daemon_init (char **argv, char *dz, void fn (void)) __attribute__ ((noreturn));
|
|
||||||
static void daemon_init (char **argv, char *dz, void fn (void))
|
static void daemon_init (char **argv, char *dz, void fn (void))
|
||||||
{
|
{
|
||||||
setsid();
|
setsid();
|
||||||
|
81
syslogd.c
81
syslogd.c
@ -5,6 +5,8 @@
|
|||||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
|
||||||
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -74,8 +76,7 @@ static const char syslogd_usage[] =
|
|||||||
|
|
||||||
/* Note: There is also a function called "message()" in init.c */
|
/* Note: There is also a function called "message()" in init.c */
|
||||||
/* Print a message to the log file. */
|
/* Print a message to the log file. */
|
||||||
static void message(char *fmt, ...)
|
static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
__attribute__ ((format (printf, 1, 2)));
|
|
||||||
static void message (char *fmt, ...)
|
static void message (char *fmt, ...)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@ -161,11 +162,13 @@ static void doSyslogd (void)
|
|||||||
{
|
{
|
||||||
struct sockaddr_un sunx;
|
struct sockaddr_un sunx;
|
||||||
size_t addrLength;
|
size_t addrLength;
|
||||||
|
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
fd_set readfds;
|
fd_set fds;
|
||||||
|
|
||||||
char lfile[PATH_MAX];
|
char lfile[PATH_MAX];
|
||||||
|
|
||||||
/* Set up sig handlers */
|
/* Set up signal handlers. */
|
||||||
signal (SIGINT, quit_signal);
|
signal (SIGINT, quit_signal);
|
||||||
signal (SIGTERM, quit_signal);
|
signal (SIGTERM, quit_signal);
|
||||||
signal (SIGQUIT, quit_signal);
|
signal (SIGQUIT, quit_signal);
|
||||||
@ -173,77 +176,72 @@ static void doSyslogd (void)
|
|||||||
signal (SIGALRM, domark);
|
signal (SIGALRM, domark);
|
||||||
alarm (MarkInterval);
|
alarm (MarkInterval);
|
||||||
|
|
||||||
/* create the syslog file so realpath() can work */
|
/* Create the syslog file so realpath() can work. */
|
||||||
close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
|
close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
|
||||||
if (realpath(_PATH_LOG, lfile) == NULL) {
|
if (realpath (_PATH_LOG, lfile) == NULL)
|
||||||
fatalError("Could not resolv path to " _PATH_LOG);
|
fatalError ("Could not resolv path to " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
unlink (lfile);
|
unlink (lfile);
|
||||||
|
|
||||||
memset (&sunx, 0, sizeof (sunx));
|
memset (&sunx, 0, sizeof (sunx));
|
||||||
|
|
||||||
sunx.sun_family = AF_UNIX;
|
sunx.sun_family = AF_UNIX;
|
||||||
strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
|
strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
|
||||||
if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||||
fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG);
|
fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
|
addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
|
||||||
if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) ||
|
if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
|
||||||
(listen (sock_fd, 5))) {
|
fatalError ("Could not connect to socket " _PATH_LOG ": %s", strerror (errno));
|
||||||
fatalError ("Could not connect to socket " _PATH_LOG);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chmod (lfile, 0666) < 0) {
|
if (chmod (lfile, 0666) < 0)
|
||||||
fatalError ("Could not set permission on " _PATH_LOG);
|
fatalError ("Could not set permission on " _PATH_LOG ": %s", strerror (errno));
|
||||||
}
|
|
||||||
|
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&fds);
|
||||||
FD_SET (sock_fd, &readfds);
|
FD_SET (sock_fd, &fds);
|
||||||
|
|
||||||
logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
|
logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
|
fd_set readfds;
|
||||||
int n_ready;
|
int n_ready;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
memcpy (&readfds, &fds, sizeof (fds));
|
||||||
|
|
||||||
if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
|
if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
|
||||||
if (errno == EINTR) continue; /* alarm may have happened. */
|
if (errno == EINTR) continue; /* alarm may have happened. */
|
||||||
fatalError ("select error: %s\n", strerror (errno));
|
fatalError ("select error: %s\n", strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip stdin, stdout, stderr */
|
for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
|
||||||
for (fd = 3; fd < FD_SETSIZE; fd++) {
|
|
||||||
if (FD_ISSET (fd, &readfds)) {
|
if (FD_ISSET (fd, &readfds)) {
|
||||||
|
--n_ready;
|
||||||
if (fd == sock_fd) {
|
if (fd == sock_fd) {
|
||||||
int conn;
|
int conn;
|
||||||
if ((conn = accept(sock_fd, (struct sockaddr *) &sunx,
|
if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
|
||||||
&addrLength)) < 0) {
|
|
||||||
fatalError ("accept error: %s\n", strerror (errno));
|
fatalError ("accept error: %s\n", strerror (errno));
|
||||||
}
|
}
|
||||||
FD_SET (conn, &readfds);
|
FD_SET (conn, &fds);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#define BUFSIZE 1024 + 1
|
# define BUFSIZE 1023
|
||||||
char buf;
|
char buf[ BUFSIZE + 1 ];
|
||||||
char *q, *p;
|
|
||||||
int n_read;
|
int n_read;
|
||||||
char line[BUFSIZE];
|
|
||||||
|
while ((n_read = read (fd, buf, BUFSIZE )) > 0) {
|
||||||
|
|
||||||
|
int pri = (LOG_USER | LOG_NOTICE);
|
||||||
|
char line[ BUFSIZE + 1 ];
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
int pri;
|
char *p = buf, *q = line;
|
||||||
|
|
||||||
/* Get set to read in a line */
|
buf[ n_read - 1 ] = '\0';
|
||||||
memset (line, 0, sizeof(line));
|
|
||||||
pri = (LOG_USER | LOG_NOTICE);
|
|
||||||
|
|
||||||
/* Keep reading stuff till there is nothing else to read */
|
|
||||||
while( (n_read = read (fd, &buf, 1)) > 0) {
|
|
||||||
p = &buf;
|
|
||||||
q = line;
|
|
||||||
while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
|
while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
|
||||||
if (c == '<') {
|
if (c == '<') {
|
||||||
/* Parse the magic priority number */
|
/* Parse the magic priority number. */
|
||||||
pri = 0;
|
pri = 0;
|
||||||
while (isdigit (*(++p))) {
|
while (isdigit (*(++p))) {
|
||||||
pri = 10 * pri + (*p - '0');
|
pri = 10 * pri + (*p - '0');
|
||||||
@ -261,13 +259,11 @@ static void doSyslogd (void)
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
/* Now log it */
|
/* Now log it */
|
||||||
logMessage (pri, line);
|
logMessage (pri, line);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
FD_CLR (fd, &readfds);
|
FD_CLR (fd, &fds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,7 +347,6 @@ static void doKlogd (void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void daemon_init (char **argv, char *dz, void fn (void)) __attribute__ ((noreturn));
|
|
||||||
static void daemon_init (char **argv, char *dz, void fn (void))
|
static void daemon_init (char **argv, char *dz, void fn (void))
|
||||||
{
|
{
|
||||||
setsid();
|
setsid();
|
||||||
|
Loading…
Reference in New Issue
Block a user