diff options
author | yaworsky <yaworsky> | 2005-09-16 08:36:39 +0000 |
---|---|---|
committer | yaworsky <yaworsky> | 2005-09-16 08:36:39 +0000 |
commit | cc936dc1a09d275915f82733611d7c0146846788 (patch) | |
tree | 8facf6641a8fbf8cf7f7d41a2004b39116872350 | |
parent | a2c534419863b2c09fd122d8d1ef6769398f7cf0 (diff) | |
download | syslog-win32-cc936dc1a09d275915f82733611d7c0146846788.tar.gz syslog-win32-cc936dc1a09d275915f82733611d7c0146846788.tar.xz syslog-win32-cc936dc1a09d275915f82733611d7c0146846788.zip |
Modified for native win32.
Diffstat (limited to '')
-rw-r--r-- | client/logger.c | 112 | ||||
-rw-r--r-- | include/syslog.h | 8 |
2 files changed, 21 insertions, 99 deletions
diff --git a/client/logger.c b/client/logger.c index 8f28e39..f80bb67 100644 --- a/client/logger.c +++ b/client/logger.c @@ -34,83 +34,27 @@ * - added Native Language Support * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> * - fixed strerr(errno) in gettext calls + * 2005-06-17 Alexander Yaworsky <yaworsky@mail.ru> + * - modified for native win32 */ #include <errno.h> -#include <unistd.h> +#include <getopt.h> #include <stdlib.h> #include <time.h> #include <stdio.h> #include <ctype.h> #include <string.h> #include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include "nls.h" #define SYSLOG_NAMES #include <syslog.h> -int decode __P((char *, CODE *)); -int pencode __P((char *)); -void usage __P((void)); +#define _(s) s -static int optd = 0; - -static int -myopenlog(const char *sock) { - int fd; - static struct sockaddr_un s_addr; /* AF_UNIX address of local logger */ - - if (strlen(sock) >= sizeof(s_addr.sun_path)) { - printf ("logger: openlog: pathname too long\n"); - exit(1); - } - - s_addr.sun_family = AF_UNIX; - (void)strcpy(s_addr.sun_path, sock); - - if ((fd = socket(AF_UNIX, optd ? SOCK_DGRAM : SOCK_STREAM, 0)) == -1) { - printf ("socket: %s.\n", strerror(errno)); - exit (1); - } - - if (connect(fd, (struct sockaddr *) &s_addr, sizeof(s_addr)) == -1) { - printf ("connect: %s.\n", strerror(errno)); - exit (1); - } - return fd; -} - -static void -mysyslog(int fd, int logflags, int pri, char *tag, char *msg) { - char buf[1000], pid[30], *cp, *tp; - time_t now; - - if (fd > -1) { - /* avoid snprintf - it does not exist on ancient systems */ - if (logflags & LOG_PID) - sprintf (pid, "[%d]", getpid()); - else - pid[0] = 0; - if (tag) - cp = tag; - else { - cp = getlogin(); - if (!cp) - cp = "<someone>"; - } - (void)time(&now); - tp = ctime(&now)+4; - - /* do snprintf by hand - ugly, but for once... */ - sprintf(buf, "<%d>%.15s %.200s%s: %.400s", - pri, tp, cp, pid, msg); - - if (write(fd, buf, strlen(buf)+1) < 0) - return; /* error */ - } -} +int decode (char *, CODE *); +int pencode (char *); +void usage (void); /* * logger -- read and log utility @@ -122,17 +66,11 @@ int main(int argc, char **argv) { int ch, logflags, pri; char *tag, buf[1024]; - char *usock = NULL; - int LogSock = -1; - - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); tag = NULL; pri = LOG_NOTICE; logflags = 0; - while ((ch = getopt(argc, argv, "f:ip:st:u:d")) != -1) + while ((ch = getopt(argc, argv, "f:ip:st:")) != -1) switch((char)ch) { case 'f': /* file to log */ if (freopen(optarg, "r", stdin) == NULL) { @@ -154,12 +92,6 @@ main(int argc, char **argv) { case 't': /* tag */ tag = optarg; break; - case 'u': /* unix socket */ - usock = optarg; - break; - case 'd': - optd = 1; /* use datagrams */ - break; case '?': default: usage(); @@ -168,10 +100,7 @@ main(int argc, char **argv) { argv += optind; /* setup for logging */ - if (!usock) - openlog(tag ? tag : getlogin(), logflags, 0); - else - LogSock = myopenlog(usock); + openlog(tag ? tag : "logger", logflags, 0); (void) fclose(stdout); @@ -183,29 +112,20 @@ main(int argc, char **argv) { for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { - if (!usock) syslog(pri, "%s", buf); - else - mysyslog(LogSock, logflags, pri, tag, buf); p = buf; } if (len > sizeof(buf) - 1) { - if (!usock) syslog(pri, "%s", *argv++); - else - mysyslog(LogSock, logflags, pri, tag, *argv++); } else { if (p != buf) *p++ = ' '; - bcopy(*argv++, p, len); + memmove(p, *argv++, len); *(p += len) = '\0'; } } if (p != buf) { - if (!usock) syslog(pri, "%s", buf); - else - mysyslog(LogSock, logflags, pri, tag, buf); } } else while (fgets(buf, sizeof(buf), stdin) != NULL) { @@ -216,15 +136,9 @@ main(int argc, char **argv) { if (len > 0 && buf[len - 1] == '\n') buf[len - 1] = '\0'; - if (!usock) - syslog(pri, "%s", buf); - else - mysyslog(LogSock, logflags, pri, tag, buf); + syslog(pri, "%s", buf); } - if (!usock) - closelog(); - else - close(LogSock); + closelog(); exit(0); } @@ -283,6 +197,6 @@ void usage() { (void)fprintf(stderr, - _("usage: logger [-is] [-f file] [-p pri] [-t tag] [-u socket] [ message ... ]\n")); + _("usage: logger [-is] [-f file] [-p pri] [-t tag] [ message ... ]\n")); exit(1); } diff --git a/include/syslog.h b/include/syslog.h index 0883455..2dbf821 100644 --- a/include/syslog.h +++ b/include/syslog.h @@ -182,6 +182,14 @@ extern void syslog (int __pri, char *__fmt, ...); /* Generate a log message using FMT and using arguments pointed to by AP. */ extern void vsyslog (int __pri, char *__fmt, va_list __ap); +/* windows-specific; + set directory from where syslog.host must be read; + this file contains a single line with hostname and port of syslog daemon; + default is localhost:514 +*/ +extern const char* set_syslog_conf_dir( const char* dir ); + + #ifdef __cplusplus } #endif |