Add esyslog support

This commit is contained in:
Roy Marples 2007-08-16 16:53:20 +00:00
parent b8b1352b38
commit 6e5c8f8e5a
5 changed files with 57 additions and 15 deletions

View File

@ -43,7 +43,7 @@ SYS_WHITELIST = env_whitelist
TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS) TARGET = $(LIB_TARGETS) $(BIN_TARGETS) $(SBIN_TARGETS) $(PRIV_BIN_TARGETS)
RCLINKS = einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \ 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 \ veinfo vewarn vebegin veend vewend veindent veoutdent \
service_starting service_inactive service_started \ service_starting service_inactive service_started \
service_stopping service_stopped \ service_stopping service_stopped \

View File

@ -36,6 +36,7 @@ typedef enum
have the va_list concept have the va_list concept
*/ */
const char *ecolor (einfo_color_t); 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 einfon (const char *fmt, ...) EINFO_PRINTF (1, 2);
int ewarnn (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); int eerrorn (const char *fmt, ...) EINFO_PRINTF (1, 2);

View File

@ -38,6 +38,7 @@ hidden_proto(einfo)
hidden_proto(einfon) hidden_proto(einfon)
hidden_proto(einfov) hidden_proto(einfov)
hidden_proto(einfovn) hidden_proto(einfovn)
hidden_proto(elog)
hidden_proto(eoutdent) hidden_proto(eoutdent)
hidden_proto(eoutdentv) hidden_proto(eoutdentv)
hidden_proto(ewarn) hidden_proto(ewarn)
@ -193,7 +194,7 @@ void eprefix (const char *prefix) {
_eprefix = 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"); char *e = getenv ("RC_ELOG");
va_list apc; 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) static int _eindent (FILE *stream)
{ {
char *env = getenv ("RC_EINDENT"); char *env = getenv ("RC_EINDENT");
@ -376,7 +387,7 @@ int ewarn (const char *fmt, ...)
return (0); return (0);
va_start (ap, fmt); va_start (ap, fmt);
elog (LOG_WARNING, fmt, ap); elogv (LOG_WARNING, fmt, ap);
retval = _ewarnvn (fmt, ap); retval = _ewarnvn (fmt, ap);
retval += printf ("\n"); retval += printf ("\n");
va_end (ap); va_end (ap);
@ -392,7 +403,7 @@ void ewarnx (const char *fmt, ...)
if (fmt && ! is_env ("RC_QUIET", "yes")) { if (fmt && ! is_env ("RC_QUIET", "yes")) {
va_start (ap, fmt); va_start (ap, fmt);
elog (LOG_WARNING, fmt, ap); elogv (LOG_WARNING, fmt, ap);
retval = _ewarnvn (fmt, ap); retval = _ewarnvn (fmt, ap);
va_end (ap); va_end (ap);
retval += printf ("\n"); retval += printf ("\n");
@ -410,7 +421,7 @@ int eerror (const char *fmt, ...)
return (0); return (0);
va_start (ap, fmt); va_start (ap, fmt);
elog (LOG_ERR, fmt, ap); elogv (LOG_ERR, fmt, ap);
retval = _eerrorvn (fmt, ap); retval = _eerrorvn (fmt, ap);
va_end (ap); va_end (ap);
retval += fprintf (stderr, "\n"); retval += fprintf (stderr, "\n");
@ -425,7 +436,7 @@ void eerrorx (const char *fmt, ...)
if (fmt) { if (fmt) {
va_start (ap, fmt); va_start (ap, fmt);
elog (LOG_ERR, fmt, ap); elogv (LOG_ERR, fmt, ap);
_eerrorvn (fmt, ap); _eerrorvn (fmt, ap);
va_end (ap); va_end (ap);
fprintf (stderr, "\n"); fprintf (stderr, "\n");

View File

@ -330,6 +330,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
/* Check coldplugged services */ /* Check coldplugged services */
if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_stopped)) if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_stopped))
{ DO }
/* Check manually started */ /* Check manually started */
if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_started)) if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_started))

View File

@ -13,6 +13,8 @@
#define APPLET "rc" #define APPLET "rc"
#define SYSLOG_NAMES
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/utsname.h> #include <sys/utsname.h>
@ -27,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <syslog.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
@ -114,6 +117,20 @@ static void cleanup (void)
free (applet); 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) static int do_e (int argc, char **argv)
{ {
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
@ -122,6 +139,7 @@ static int do_e (int argc, char **argv)
char *message = NULL; char *message = NULL;
char *p; char *p;
char *fmt = NULL; char *fmt = NULL;
int level = 0;
if (strcmp (applet, "eval_ecolors") == 0) { if (strcmp (applet, "eval_ecolors") == 0) {
printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n", 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); exit (EXIT_SUCCESS);
} }
if (argc > 0) {
if (strcmp (applet, "eend") == 0 || if (strcmp (applet, "eend") == 0 ||
strcmp (applet, "ewend") == 0 || strcmp (applet, "ewend") == 0 ||
strcmp (applet, "veend") == 0 || strcmp (applet, "veend") == 0 ||
strcmp (applet, "vweend") == 0) strcmp (applet, "vweend") == 0)
{ {
if (argc > 0) {
errno = 0; errno = 0;
retval = strtol (argv[0], NULL, 0); retval = strtol (argv[0], NULL, 0);
if (errno != 0) if (errno != 0)
@ -148,9 +167,17 @@ static int do_e (int argc, char **argv)
argc--; argc--;
argv++; 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) { if (argc > 0) {
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
l += strlen (argv[i]) + 1; l += strlen (argv[i]) + 1;
@ -190,6 +217,8 @@ static int do_e (int argc, char **argv)
eend (retval, fmt, message); eend (retval, fmt, message);
else if (strcmp (applet, "ewend") == 0) else if (strcmp (applet, "ewend") == 0)
ewend (retval, fmt, message); ewend (retval, fmt, message);
else if (strcmp (applet, "esyslog") == 0)
elog (level, fmt, message);
else if (strcmp (applet, "veinfo") == 0) else if (strcmp (applet, "veinfo") == 0)
einfov (fmt, message); einfov (fmt, message);
else if (strcmp (applet, "veinfon") == 0) else if (strcmp (applet, "veinfon") == 0)