diff options
author | Roy Marples <roy@marples.name> | 2007-08-16 16:53:20 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-08-16 16:53:20 +0000 |
commit | 6e5c8f8e5a02f624f2f8dd7d0b639d54e2993498 (patch) | |
tree | 44ab712d1368edb5cd2c78552ecadc325981b72e | |
parent | b8b1352b3890e7a4500e424d53f5de1ea0601c44 (diff) |
Add esyslog support
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/einfo.h | 1 | ||||
-rw-r--r-- | src/libeinfo.c | 21 | ||||
-rw-r--r-- | src/librc-depend.c | 7 | ||||
-rw-r--r-- | src/rc.c | 41 |
5 files changed, 57 insertions, 15 deletions
diff --git a/src/Makefile b/src/Makefile index dc6d86f5..6c52c878 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,7 +43,7 @@ SYS_WHITELIST = env_whitelist TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS) RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ - eindent eoutdent eval_ecolors \ + eindent eoutdent esyslog eval_ecolors \ veinfo vewarn vebegin veend vewend veindent veoutdent \ service_starting service_inactive service_started \ service_stopping service_stopped \ diff --git a/src/einfo.h b/src/einfo.h index a0078ea4..dc07b903 100644 --- a/src/einfo.h +++ b/src/einfo.h @@ -36,6 +36,7 @@ typedef enum have the va_list concept */ const char *ecolor (einfo_color_t); +void elog (int level, const char *fmt, ...) EINFO_PRINTF (2, 3); int einfon (const char *fmt, ...) EINFO_PRINTF (1, 2); int ewarnn (const char *fmt, ...) EINFO_PRINTF (1, 2); int eerrorn (const char *fmt, ...) EINFO_PRINTF (1, 2); diff --git a/src/libeinfo.c b/src/libeinfo.c index e1b4db56..489b3469 100644 --- a/src/libeinfo.c +++ b/src/libeinfo.c @@ -38,6 +38,7 @@ hidden_proto(einfo) hidden_proto(einfon) hidden_proto(einfov) hidden_proto(einfovn) +hidden_proto(elog) hidden_proto(eoutdent) hidden_proto(eoutdentv) hidden_proto(ewarn) @@ -193,7 +194,7 @@ void eprefix (const char *prefix) { _eprefix = prefix; } -static void elog (int level, const char *fmt, va_list ap) +static void elogv (int level, const char *fmt, va_list ap) { char *e = getenv ("RC_ELOG"); va_list apc; @@ -208,6 +209,16 @@ static void elog (int level, const char *fmt, va_list ap) } } +void elog (int level, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + elogv (level, fmt, ap); + va_end (ap); +} +hidden_def(elog) + static int _eindent (FILE *stream) { char *env = getenv ("RC_EINDENT"); @@ -376,7 +387,7 @@ int ewarn (const char *fmt, ...) return (0); va_start (ap, fmt); - elog (LOG_WARNING, fmt, ap); + elogv (LOG_WARNING, fmt, ap); retval = _ewarnvn (fmt, ap); retval += printf ("\n"); va_end (ap); @@ -392,7 +403,7 @@ void ewarnx (const char *fmt, ...) if (fmt && ! is_env ("RC_QUIET", "yes")) { va_start (ap, fmt); - elog (LOG_WARNING, fmt, ap); + elogv (LOG_WARNING, fmt, ap); retval = _ewarnvn (fmt, ap); va_end (ap); retval += printf ("\n"); @@ -410,7 +421,7 @@ int eerror (const char *fmt, ...) return (0); va_start (ap, fmt); - elog (LOG_ERR, fmt, ap); + elogv (LOG_ERR, fmt, ap); retval = _eerrorvn (fmt, ap); va_end (ap); retval += fprintf (stderr, "\n"); @@ -425,7 +436,7 @@ void eerrorx (const char *fmt, ...) if (fmt) { va_start (ap, fmt); - elog (LOG_ERR, fmt, ap); + elogv (LOG_ERR, fmt, ap); _eerrorvn (fmt, ap); va_end (ap); fprintf (stderr, "\n"); diff --git a/src/librc-depend.c b/src/librc-depend.c index c3ccaf75..71ea118a 100644 --- a/src/librc-depend.c +++ b/src/librc-depend.c @@ -330,10 +330,11 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo, /* Check coldplugged services */ if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_stopped)) + { DO } - /* Check manually started */ - if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_started)) - { DO } + /* Check manually started */ + if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_started)) + { DO } if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_starting)) return (providers.list); @@ -13,6 +13,8 @@ #define APPLET "rc" +#define SYSLOG_NAMES + #include <sys/types.h> #include <sys/stat.h> #include <sys/utsname.h> @@ -27,6 +29,7 @@ #include <stdlib.h> #include <signal.h> #include <string.h> +#include <syslog.h> #include <termios.h> #include <unistd.h> @@ -114,6 +117,20 @@ static void cleanup (void) free (applet); } +static int syslog_decode (char *name, CODE *codetab) +{ + CODE *c; + + if (isdigit (*name)) + return (atoi (name)); + + for (c = codetab; c->c_name; c++) + if (! strcasecmp (name, c->c_name)) + return (c->c_val); + + return (-1); +} + static int do_e (int argc, char **argv) { int retval = EXIT_SUCCESS; @@ -122,6 +139,7 @@ static int do_e (int argc, char **argv) char *message = NULL; char *p; char *fmt = NULL; + int level = 0; if (strcmp (applet, "eval_ecolors") == 0) { printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n", @@ -134,12 +152,13 @@ static int do_e (int argc, char **argv) exit (EXIT_SUCCESS); } - if (strcmp (applet, "eend") == 0 || - strcmp (applet, "ewend") == 0 || - strcmp (applet, "veend") == 0 || - strcmp (applet, "vweend") == 0) - { - if (argc > 0) { + if (argc > 0) { + + if (strcmp (applet, "eend") == 0 || + strcmp (applet, "ewend") == 0 || + strcmp (applet, "veend") == 0 || + strcmp (applet, "vweend") == 0) + { errno = 0; retval = strtol (argv[0], NULL, 0); if (errno != 0) @@ -148,9 +167,17 @@ static int do_e (int argc, char **argv) argc--; argv++; } + } else if (strcmp (applet, "esyslog") == 0 || + strcmp (applet, "elog") == 0) { + char *dot = strchr (argv[0], '.'); + if ((level = syslog_decode (dot + 1, prioritynames)) == -1) + eerrorx ("%s: invalid log level `%s'", applet, argv[0]); + argc--; + argv++; } } + if (argc > 0) { for (i = 0; i < argc; i++) l += strlen (argv[i]) + 1; @@ -190,6 +217,8 @@ static int do_e (int argc, char **argv) eend (retval, fmt, message); else if (strcmp (applet, "ewend") == 0) ewend (retval, fmt, message); + else if (strcmp (applet, "esyslog") == 0) + elog (level, fmt, message); else if (strcmp (applet, "veinfo") == 0) einfov (fmt, message); else if (strcmp (applet, "veinfon") == 0) |