diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-11 15:43:19 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-11 15:43:19 +0000 |
| commit | bd1aeeb850e441e3fa4f9e1f8aedd804a48b9cb1 (patch) | |
| tree | bcd130850cb83d83b7fa2860f741b8451ae3fdcb | |
| parent | 87f40bac149dcaf1025abd745decafb3a8ac4e0c (diff) | |
| download | busybox-w32-bd1aeeb850e441e3fa4f9e1f8aedd804a48b9cb1.tar.gz busybox-w32-bd1aeeb850e441e3fa4f9e1f8aedd804a48b9cb1.tar.bz2 busybox-w32-bd1aeeb850e441e3fa4f9e1f8aedd804a48b9cb1.zip | |
logger: "clean up" a dirty hack a bit
| -rw-r--r-- | sysklogd/Kbuild | 4 | ||||
| -rw-r--r-- | sysklogd/logger.c | 31 | ||||
| -rw-r--r-- | sysklogd/logread.c | 1 | ||||
| -rw-r--r-- | sysklogd/syslogd.c | 18 | ||||
| -rw-r--r-- | sysklogd/syslogd_and_logger.c | 51 |
5 files changed, 75 insertions, 30 deletions
diff --git a/sysklogd/Kbuild b/sysklogd/Kbuild index 0d5b2b929..d802198e6 100644 --- a/sysklogd/Kbuild +++ b/sysklogd/Kbuild | |||
| @@ -6,6 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | lib-y:= | 7 | lib-y:= |
| 8 | lib-$(CONFIG_KLOGD) += klogd.o | 8 | lib-$(CONFIG_KLOGD) += klogd.o |
| 9 | lib-$(CONFIG_LOGGER) += logger.o | 9 | lib-$(CONFIG_LOGGER) += syslogd_and_logger.o |
| 10 | lib-$(CONFIG_LOGREAD) += logread.o | 10 | lib-$(CONFIG_LOGREAD) += logread.o |
| 11 | lib-$(CONFIG_SYSLOGD) += syslogd.o | 11 | lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o |
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 090750173..625811356 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
| @@ -7,34 +7,13 @@ | |||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | /* | ||
| 11 | * Done in syslogd_and_logger.c: | ||
| 10 | #include "libbb.h" | 12 | #include "libbb.h" |
| 11 | #ifndef CONFIG_SYSLOGD | ||
| 12 | #define SYSLOG_NAMES | 13 | #define SYSLOG_NAMES |
| 13 | #define SYSLOG_NAMES_CONST | 14 | #define SYSLOG_NAMES_CONST |
| 14 | #include <syslog.h> | 15 | #include <syslog.h> |
| 15 | #else | 16 | */ |
| 16 | /* brokenness alert. Everybody except dietlibc get's this wrong by neither | ||
| 17 | * providing a typedef nor an extern for facilitynames and prioritynames | ||
| 18 | * in syslog.h. | ||
| 19 | */ | ||
| 20 | # include <syslog.h> | ||
| 21 | # ifndef __dietlibc__ | ||
| 22 | /* We have to do this since the header file does neither provide a sane type | ||
| 23 | * for this structure nor extern definitions. Argh.... bad libc, bad, bad... | ||
| 24 | */ | ||
| 25 | typedef struct _code { | ||
| 26 | char *c_name; /* FIXME: this should be const char *const c_name ! */ | ||
| 27 | int c_val; | ||
| 28 | } CODE; | ||
| 29 | # ifdef __UCLIBC__ | ||
| 30 | extern const CODE prioritynames[]; | ||
| 31 | extern const CODE facilitynames[]; | ||
| 32 | # else | ||
| 33 | extern CODE prioritynames[]; | ||
| 34 | extern CODE facilitynames[]; | ||
| 35 | # endif | ||
| 36 | # endif | ||
| 37 | #endif | ||
| 38 | 17 | ||
| 39 | /* Decode a symbolic name to a numeric value | 18 | /* Decode a symbolic name to a numeric value |
| 40 | * this function is based on code | 19 | * this function is based on code |
| @@ -87,6 +66,7 @@ static int pencode(char *s) | |||
| 87 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); | 66 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); |
| 88 | } | 67 | } |
| 89 | 68 | ||
| 69 | #define strbuf bb_common_bufsiz1 | ||
| 90 | 70 | ||
| 91 | int logger_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 71 | int logger_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 92 | int logger_main(int argc, char **argv) | 72 | int logger_main(int argc, char **argv) |
| @@ -113,7 +93,6 @@ int logger_main(int argc, char **argv) | |||
| 113 | argc -= optind; | 93 | argc -= optind; |
| 114 | argv += optind; | 94 | argv += optind; |
| 115 | if (!argc) { | 95 | if (!argc) { |
| 116 | #define strbuf bb_common_bufsiz1 | ||
| 117 | while (fgets(strbuf, COMMON_BUFSIZE, stdin)) { | 96 | while (fgets(strbuf, COMMON_BUFSIZE, stdin)) { |
| 118 | if (strbuf[0] | 97 | if (strbuf[0] |
| 119 | && NOT_LONE_CHAR(strbuf, '\n') | 98 | && NOT_LONE_CHAR(strbuf, '\n') |
| @@ -139,6 +118,8 @@ int logger_main(int argc, char **argv) | |||
| 139 | return EXIT_SUCCESS; | 118 | return EXIT_SUCCESS; |
| 140 | } | 119 | } |
| 141 | 120 | ||
| 121 | /* Clean up. Needed because we are included from syslogd_and_logger.c */ | ||
| 122 | #undef strbuf | ||
| 142 | 123 | ||
| 143 | /*- | 124 | /*- |
| 144 | * Copyright (c) 1983, 1993 | 125 | * Copyright (c) 1983, 1993 |
diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 7eb8db176..ace246fc4 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | #define DEBUG 0 | 17 | #define DEBUG 0 |
| 18 | 18 | ||
| 19 | /* our shared key (syslogd.c and logread.c must be in sync) */ | ||
| 19 | enum { KEY_ID = 0x414e4547 }; /* "GENA" */ | 20 | enum { KEY_ID = 0x414e4547 }; /* "GENA" */ |
| 20 | 21 | ||
| 21 | struct shbuf_ds { | 22 | struct shbuf_ds { |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 1b8d718f4..b9af9c55f 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
| @@ -13,10 +13,13 @@ | |||
| 13 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 13 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | /* | ||
| 17 | * Done in syslogd_and_logger.c: | ||
| 16 | #include "libbb.h" | 18 | #include "libbb.h" |
| 17 | #define SYSLOG_NAMES | 19 | #define SYSLOG_NAMES |
| 18 | #define SYSLOG_NAMES_CONST | 20 | #define SYSLOG_NAMES_CONST |
| 19 | #include <syslog.h> | 21 | #include <syslog.h> |
| 22 | */ | ||
| 20 | 23 | ||
| 21 | #include <paths.h> | 24 | #include <paths.h> |
| 22 | #include <sys/un.h> | 25 | #include <sys/un.h> |
| @@ -192,8 +195,8 @@ enum { | |||
| 192 | #error Please check CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE | 195 | #error Please check CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE |
| 193 | #endif | 196 | #endif |
| 194 | 197 | ||
| 195 | /* our shared key */ | 198 | /* our shared key (syslogd.c and logread.c must be in sync) */ |
| 196 | #define KEY_ID ((long)0x414e4547) /* "GENA" */ | 199 | enum { KEY_ID = 0x414e4547 }; /* "GENA" */ |
| 197 | 200 | ||
| 198 | static void ipcsyslog_cleanup(void) | 201 | static void ipcsyslog_cleanup(void) |
| 199 | { | 202 | { |
| @@ -211,7 +214,7 @@ static void ipcsyslog_cleanup(void) | |||
| 211 | static void ipcsyslog_init(void) | 214 | static void ipcsyslog_init(void) |
| 212 | { | 215 | { |
| 213 | if (DEBUG) | 216 | if (DEBUG) |
| 214 | printf("shmget(%lx, %d,...)\n", KEY_ID, G.shm_size); | 217 | printf("shmget(%x, %d,...)\n", (int)KEY_ID, G.shm_size); |
| 215 | 218 | ||
| 216 | G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 0644); | 219 | G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 0644); |
| 217 | if (G.shmid == -1) { | 220 | if (G.shmid == -1) { |
| @@ -631,6 +634,7 @@ static void do_syslogd(void) | |||
| 631 | split_escape_and_log(recvbuf, sz); | 634 | split_escape_and_log(recvbuf, sz); |
| 632 | } | 635 | } |
| 633 | } /* for (;;) */ | 636 | } /* for (;;) */ |
| 637 | #undef recvbuf | ||
| 634 | } | 638 | } |
| 635 | 639 | ||
| 636 | int syslogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 640 | int syslogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -682,3 +686,11 @@ int syslogd_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 682 | do_syslogd(); | 686 | do_syslogd(); |
| 683 | /* return EXIT_SUCCESS; */ | 687 | /* return EXIT_SUCCESS; */ |
| 684 | } | 688 | } |
| 689 | |||
| 690 | /* Clean up. Needed because we are included from syslogd_and_logger.c */ | ||
| 691 | #undef G | ||
| 692 | #undef GLOBALS | ||
| 693 | #undef INIT_G | ||
| 694 | #undef OPTION_STR | ||
| 695 | #undef OPTION_DECL | ||
| 696 | #undef OPTION_PARAM | ||
diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c new file mode 100644 index 000000000..51573bd92 --- /dev/null +++ b/sysklogd/syslogd_and_logger.c | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * prioritynames[] and facilitynames[] | ||
| 4 | * | ||
| 5 | * Copyright (C) 2008 by Denys Vlasenko <vda.linux@gmail.com> | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "libbb.h" | ||
| 11 | #define SYSLOG_NAMES | ||
| 12 | #define SYSLOG_NAMES_CONST | ||
| 13 | #include <syslog.h> | ||
| 14 | |||
| 15 | #if 0 | ||
| 16 | /* For the record: with SYSLOG_NAMES <syslog.h> defines | ||
| 17 | * (not declares) the following: | ||
| 18 | */ | ||
| 19 | typedef struct _code { | ||
| 20 | /*const*/ char *c_name; | ||
| 21 | int c_val; | ||
| 22 | } CODE; | ||
| 23 | /*const*/ CODE prioritynames[] = { | ||
| 24 | { "alert", LOG_ALERT }, | ||
| 25 | ... | ||
| 26 | { NULL, -1 } | ||
| 27 | }; | ||
| 28 | /* same for facilitynames[] */ | ||
| 29 | |||
| 30 | /* This MUST occur only once per entire executable, | ||
| 31 | * therefore we can't just do it in syslogd.c and logger.c - | ||
| 32 | * there will be two copies of it. | ||
| 33 | * | ||
| 34 | * We cannot even do it in separate file and then just reference | ||
| 35 | * prioritynames[] from syslogd.c and logger.c - bare <syslog.h> | ||
| 36 | * will not emit extern decls for prioritynames[]! Attempts to | ||
| 37 | * emit "matching" struct _code declaration defeat the whole purpose | ||
| 38 | * of <syslog.h>. | ||
| 39 | * | ||
| 40 | * For now, syslogd.c and logger.c are simply compiled into | ||
| 41 | * one object file. | ||
| 42 | */ | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #if ENABLE_SYSLOGD | ||
| 46 | #include "syslogd.c" | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #if ENABLE_LOGGER | ||
| 50 | #include "logger.c" | ||
| 51 | #endif | ||
