diff options
author | Erik Andersen | 2000-01-23 01:34:05 +0000 |
---|---|---|
committer | Erik Andersen | 2000-01-23 01:34:05 +0000 |
commit | de552874d2074ac48ea4b834d61c54e1b6971be3 (patch) | |
tree | 0360b39142f1c85e1cac2637e09c6e452cf1a444 /sysklogd | |
parent | f4acea8cf5175de2292c86b58f2f30d262f14345 (diff) | |
download | busybox-de552874d2074ac48ea4b834d61c54e1b6971be3.zip busybox-de552874d2074ac48ea4b834d61c54e1b6971be3.tar.gz |
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')
-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 7aada5d..d7ae023 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -22,16 +22,11 @@ #include "internal.h" #include <stdio.h> -#include <sys/socket.h> -#include <sys/un.h> #include <unistd.h> -#include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <signal.h> #include <ctype.h> -#include <netdb.h> #if !defined BB_SYSLOGD @@ -56,6 +51,7 @@ static const char logger_usage[] = "Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" "Options:\n" "\t-s\tLog to stderr as well as the system log.\n" + "\t-t\tLog using the specified tag (defaults to user name).\n" "\t-p\tEnter the message with the specified priority.\n" "\t\tThis may be numerical or a ``facility.level'' pair.\n"; @@ -116,14 +112,14 @@ pencode(char* s) extern int logger_main(int argc, char **argv) { - struct sockaddr_un sunx; - int fd, pri = LOG_USER|LOG_NOTICE; + int pri = LOG_USER|LOG_NOTICE; + int option = 0; int fromStdinFlag=FALSE; - int toStdErrFlag=FALSE; int stopLookingAtMeLikeThat=FALSE; - char *message, buf[1024], buf1[1024]; - time_t now; - size_t addrLength; + char *message, buf[1024], name[128]; + + /* Fill out the name string early (may be overwritten later */ + my_getpwuid(name, geteuid()); /* Parse any options */ while (--argc > 0 && **(++argv) == '-') { @@ -134,7 +130,7 @@ extern int logger_main(int argc, char **argv) while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) { switch (**argv) { case 's': - toStdErrFlag = TRUE; + option |= LOG_PERROR; break; case 'p': if (--argc == 0) { @@ -143,6 +139,13 @@ extern int logger_main(int argc, char **argv) pri = pencode(*(++argv)); stopLookingAtMeLikeThat=TRUE; break; + case 't': + if (--argc == 0) { + usage(logger_usage); + } + strncpy(name, *(++argv), sizeof(name)); + stopLookingAtMeLikeThat=TRUE; + break; default: usage(logger_usage); } @@ -152,10 +155,10 @@ extern int logger_main(int argc, char **argv) if (fromStdinFlag==TRUE) { /* read from stdin */ int c, i=0; - while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) { - buf1[i++]=c; + while ((c = getc(stdin)) != EOF && i<sizeof(buf)) { + buf[i++]=c; } - message=buf1; + message=buf; } else { if (argc>=1) { message=*argv; @@ -165,30 +168,10 @@ extern int logger_main(int argc, char **argv) } } - memset(&sunx, 0, sizeof(sunx)); - sunx.sun_family = AF_UNIX; /* Unix domain socket */ - strncpy(sunx.sun_path, _PATH_LOG, sizeof(sunx.sun_path)); - if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) { - perror("Couldn't obtain descriptor for socket " _PATH_LOG); - exit( FALSE); - } - - addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); - - if (connect(fd, (struct sockaddr *) &sunx, addrLength)) { - perror("Could not connect to socket " _PATH_LOG); - exit( FALSE); - } - - time(&now); - snprintf (buf, sizeof(buf), "<%d>%.15s %s", pri, ctime(&now)+4, message); - - if (toStdErrFlag==TRUE) - fprintf(stderr, "%s\n", buf); - - write( fd, buf, strlen(buf)+1); + openlog( name, option, (pri | LOG_FACMASK)); + syslog( pri, message); + closelog(); - close(fd); exit( TRUE); } |