--- fsl.c 2002/07/25 16:28:43 1.30
+++ fsl.c 2002/07/27 15:35:23 1.31
@@ -50,28 +50,28 @@
#include "cfg.h"
#include "pcre.h"
+/* autoconfiguration */
+#include "config.h"
+
/* pcre static vector size */
#define OVECSIZE 30
+/* backward compatibility */
#ifndef LOG_PRIMASK
-#define LOG_PRIMASK (LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG)
+#define LOG_PRIMASK (LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|\
+ LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG)
#endif
#ifndef LOG_PRI
#define LOG_PRI(p) ((p) & LOG_PRIMASK)
#endif
-#include "config.h"
-#define FSL_PREFIX "fsl."
-
+/* cleanup sequence macros */
#define STMT(stuff) do { stuff } while (0)
#define CU(returncode) STMT( rc = returncode; goto CUS; )
#define VCU STMT( goto CUS; )
-typedef struct {
- char *base;
- size_t used;
- size_t size;
-} buf_t;
+/* prefix of configuration files */
+#define FSL_PREFIX "fsl."
/* general return codes */
typedef enum {
@@ -80,18 +80,16 @@
FSL_ERR_USE, /* invalid use */
FSL_ERR_MEM, /* no more memory available */
FSL_ERR_SYS /* operating system error, see errno */
-#if 0
- FSL_ERR_FMT, /* formatting error */
- FSL_ERR_INT, /* internal error */
- FSL_ERR_SYN, /* syntax error */
-#endif
} fsl_rc_t;
-fsl_rc_t readfileorallfiles(buf_t *, const char *);
-fsl_rc_t readfile (buf_t *, const char *);
-fsl_rc_t readallfiles (buf_t *);
-fsl_rc_t appendfiletobuffer(buf_t *, const char *);
+/* file buffer handling sub-API */
+typedef struct {
+ char *base;
+ size_t used;
+ size_t size;
+} buf_t;
+/* mapping table for syslog(3) facilities to strings */
static struct {
int facility;
char *string;
@@ -132,6 +130,7 @@
{ -1, NULL }
};
+/* mapping table for syslog(3) levels/priorities strings/numbers to L2 levels */
static struct {
char *string;
int level;
@@ -148,6 +147,7 @@
{ NULL, -1, -1 }
};
+/* mapping table for L2 level strings to L2 level numbers */
static struct {
char *string;
l2_level_t level;
@@ -163,12 +163,14 @@
{ "debug", L2_LEVEL_DEBUG, },
{ NULL, -1 }
};
+
+/* type of run-time syslog(3) to L2 level mapping table */
typedef struct {
int syslog;
l2_level_t l2;
} levelmap_t;
-/* internal context structure */
+/* internal global context structure */
static struct {
l2_env_t *l2_fslenv;
l2_channel_t *l2_fslnch;
@@ -189,19 +191,157 @@
FALSE
};
+/* internal debugging function */
static void fsldebug(l2_level_t level, const char *message, ...)
{
- va_list args;
+ va_list ap;
- va_start(args, message);
+ va_start(ap, message);
if (ctx.l2_fslnch != NULL)
- l2_channel_vlog(ctx.l2_fslnch, level, message, args);
+ l2_channel_vlog(ctx.l2_fslnch, level, message, ap);
else
- vfprintf(stderr, message, args);
- va_end(args);
+ vfprintf(stderr, message, ap);
+ va_end(ap);
return;
}
+/* append contents of a file to buffer */
+static fsl_rc_t appendfiletobuffer(buf_t *buffer, const char *filename)
+{
+ fsl_rc_t rc;
+ int fd = -1;
+ int filesize;
+ int fileread;
+ int bufferneed;
+
+ if (filename == NULL || buffer == NULL)
+ CU(FSL_ERR_ARG);
+
+ fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")\n", filename);
+
+ if ((fd = open(filename, O_RDONLY)) == -1)
+ CU(FSL_ERR_SYS);
+ if ((filesize = (int)lseek(fd, 0, SEEK_END)) == -1)
+ CU(FSL_ERR_SYS);
+
+ bufferneed = buffer->used + filesize;
+ if (bufferneed > buffer->size) {
+ if (buffer->base == NULL) {
+ if ((buffer->base = (char *)malloc(bufferneed)) == NULL)
+ CU(FSL_ERR_MEM);
+ buffer->size = bufferneed;
+ buffer->used = 0;
+ }
+ else {
+ if ((buffer->base = (char *)realloc(buffer->base, bufferneed)) == NULL)
+ CU(FSL_ERR_MEM);
+ buffer->size = bufferneed;
+ }
+ }
+
+ if (lseek(fd, 0, SEEK_SET) == -1)
+ CU(FSL_ERR_SYS);
+ if ((fileread = (int)read(fd, buffer->base + buffer->used, (size_t)filesize)) == -1)
+ CU(FSL_ERR_SYS);
+ if (fileread != filesize)
+ CU(FSL_ERR_USE);
+
+ buffer->used += filesize;
+ CU(FSL_OK);
+CUS:
+ if (fd != -1)
+ close(fd);
+ return rc;
+}
+
+/* read a single file "fsl.xxx" into buffer */
+static fsl_rc_t readfile(buf_t *buffer, const char *ident)
+{
+ fsl_rc_t rc;
+ char *filename = NULL;
+
+ if (ident == NULL || buffer == NULL)
+ CU(FSL_ERR_ARG);
+ fsldebug(L2_LEVEL_TRACE, "readfile(buffer, ident=\"%s\")\n", ident);
+
+ if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 +
+ strlen(FSL_PREFIX) + strlen(ident) + 1)) == NULL)
+ CU(FSL_ERR_MEM);
+ filename[0] = '\0';
+ strcat(filename, FSL_CFGDIR);
+ strcat(filename, "/");
+ strcat(filename, FSL_PREFIX);
+ strcat(filename, ident);
+
+ CU(appendfiletobuffer(buffer, filename));
+CUS:
+ if (filename != NULL)
+ free(filename);
+ return rc;
+}
+
+/* read all possible files "fsl.*" into buffer */
+static fsl_rc_t readallfiles(buf_t *buffer)
+{
+ fsl_rc_t rc;
+ DIR *dp = NULL;
+ struct dirent *de;
+ char *filename = NULL;
+ int n;
+
+ if (buffer == NULL)
+ CU(FSL_ERR_ARG);
+ fsldebug(L2_LEVEL_TRACE, "readallfiles(buffer) globbing \"%s/%s*\"\n", FSL_CFGDIR, FSL_PREFIX);
+
+ if ((dp = opendir(FSL_CFGDIR)) == NULL)
+ CU(FSL_ERR_SYS);
+
+ rc = FSL_ERR_ARG;
+ while ((de = readdir(dp)) != NULL) {
+ n = strlen(de->d_name);
+ if ( (n >= strlen(FSL_PREFIX))
+ && (strncmp(de->d_name, FSL_PREFIX, strlen(FSL_PREFIX)) == 0)) {
+ if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + n + 1)) == NULL)
+ CU(FSL_ERR_MEM);
+ filename[0] = '\0';
+ strcat(filename, FSL_CFGDIR);
+ strcat(filename, "/");
+ strcat(filename, de->d_name);
+ if (appendfiletobuffer(buffer, filename) == FSL_OK)
+ rc = FSL_OK;
+ free(filename);
+ filename = NULL;
+ }
+ }
+ closedir(dp);
+ CU(rc);
+CUS:
+ if (dp != NULL)
+ closedir(dp);
+ if (filename != NULL)
+ free(filename);
+ return rc;
+}
+
+/* read a single or all possible files */
+static fsl_rc_t readfileorallfiles(buf_t *buffer, const char *ident)
+{
+ fsl_rc_t rv;
+
+ if (ident == NULL)
+ return FSL_ERR_ARG;
+ fsldebug(L2_LEVEL_TRACE, "readfileorallfiles(buffer, ident=\"%s\")\n", ident);
+
+ if ((rv = readfile(buffer, ident)) == FSL_OK)
+ return FSL_OK;
+ if (rv != FSL_ERR_SYS || errno != ENOENT)
+ return rv;
+ if ((rv = readallfiles(buffer)) != FSL_OK)
+ return rv;
+ return FSL_OK;
+}
+
+/* OSSP cfg node tree traversal function (recursive) */
static void traverse(cfg_t *cfg, cfg_node_t *cfgnode)
{
int rc;
@@ -213,25 +353,25 @@
while (cfgnode != NULL) {
if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TOKEN, &cp)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed: %s (%d)\n", cp, cfgrv); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_TYPE, &cfgtyp)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_TYPE) failed: %s (%d)\n", cp, cfgrv); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILDS, &cfgchilds)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
- fsldebug(L2_LEVEL_DEBUG, "cfgnode=0x%.8lx[%d], *cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, cp, cfgtyp);
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed: %s (%d)\n", cp, cfgrv); CU(1); }
+ fsldebug(L2_LEVEL_DEBUG, "traverse: cfgnode=0x%.8lx[%d], cp=\"%s\", type=%d\n", (unsigned long)cfgnode, cfgchilds, (cp != NULL ? cp : "<NULL>"), cfgtyp);
if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_CHILD1, &cfgchld)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed: %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgchld != NULL)
traverse(cfg, cfgchld);
if ((cfgrv = cfg_node_get(cfg, cfgnode, CFG_NODE_ATTR_RBROTH, &cfgnode)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "traverse: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed: %s (%d)\n", cp, cfgrv); CU(1); }
}
CU(0);
CUS:
return;
}
-/* Substitutes $[0-9] in inbuf[inlen] with captured strings passed through capary[nary].
+/* Substitute $[0-9] in inbuf[inlen] with captured strings passed through capary[nary].
* Returns the number of characters (to be) written to output. Output can be suppressed
* by passing a NULL outpbuf. The terminating NUL is not counted but will be written!
*/
@@ -251,7 +391,7 @@
if (c == '$') {
if (outbuf != NULL)
outbuf[n] = '$';
- i+=2;
+ i += 2;
n++;
}
else if ((c >= '0') && (c <= '9')) {
@@ -260,8 +400,8 @@
outbuf[n] = '\0';
strcat(&outbuf[n], ((m < nary) && (capary[m] != NULL)) ? capary[m] : "");
}
- i+=2;
- n+= ((m < nary) && (capary[m] != NULL)) ? strlen(capary[m]) : 0;
+ i += 2;
+ n += ((m < nary) && (capary[m] != NULL)) ? strlen(capary[m]) : 0;
}
else {
if (outbuf != NULL)
@@ -286,6 +426,7 @@
return n;
}
+/* POSIX API function openlog(3) */
void openlog(const char *ident, int logopt, int facility)
{
int rc;
@@ -315,6 +456,7 @@
l2_channel_t *ch; /* scratch variable */
l2_result_t l2rv;
+ /* initialization */
cfg = NULL;
buf.base = NULL;
buf.used = 0;
@@ -325,71 +467,75 @@
/* properly handle repeated execution */
closelog();
- /* create L2 environment for fsl itself */
- argl2spec = getenv("FSL_DEBUG");
- if (argl2spec == NULL)
+ /* create OSSP l2 environment for fsl itself (internal logging) */
+ if ((argl2spec = getenv("FSL_DEBUG")) == NULL)
argl2spec = FSL_DEBUG;
- if (strlen(argl2spec) != 0) {
+ if (strlen(argl2spec) > 0) {
if ((l2rv = l2_env_create(&ctx.l2_fslenv)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment (%d) for fsl\n", l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create L2 environment (%d) for fsl\n", l2rv); CU(1); }
if ((l2rv = l2_env_levels(ctx.l2_fslenv, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to set global logging level defaults %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'D', l2_util_fmt_dump, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register dump formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'S', l2_util_fmt_string, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register string formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_fslenv, 'm', l2_util_fmt_errno, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register errno formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_channel_create(&ctx.l2_fslnch, ctx.l2_fslenv, "noop")) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create noop channel; %s(%d)\n for fsl", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel; %s(%d)\n for fsl", cp, l2rv); CU(1); }
if ((l2rv = l2_spec(&ch, ctx.l2_fslenv, "%s", argl2spec)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create stream from spec %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_channel_link(ctx.l2_fslnch, L2_LINK_CHILD, ch, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to link child channel %s(%d) for fsl\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d) for fsl\n", cp, l2rv); CU(1); }
if ((l2rv = l2_channel_open(ctx.l2_fslnch)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) for fsl\n", cp, l2rv); CU(1); }
- fsldebug(L2_LEVEL_TRACE, "captured openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility);
+ cp = l2_env_strerror(ctx.l2_fslenv, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) for fsl\n", cp, l2rv); CU(1); }
}
+ /* tracing */
+ if (ctx.l2_fslnch != NULL)
+ fsldebug(L2_LEVEL_TRACE, "openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility);
+
/* remember logopt and handle unsupported values */
ctx.logopt = logopt;
if (logopt & LOG_CONS)
- fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_CONS");
+ fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_CONS");
#ifdef LOG_PERROR
if (logopt & LOG_PERROR)
- fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt LOG_PERROR, use l2spec channel \"fd(filedescriptor=2)\" to emulate");
+ fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_PERROR (use OSSP l2 channel \"fd(filedescriptor=2)\" to emulate)");
#endif
if (logopt & LOG_PID)
- fsldebug(L2_LEVEL_WARNING, "ignored unsupported logopt PID, use l2spec formatter %%P in prefix channel to emulate");
+ fsldebug(L2_LEVEL_WARNING, "openlog: ignore unsupported LOG_PID (use OSSP l2 formatter %%P in prefix channel to emulate)");
/* create default sysloglevel to l2_level mapping */
- fsldebug(L2_LEVEL_DEBUG, "create default sysloglevel to l2_level mapping\n");
- for (i = 0; sysloglevel2string[i].string != NULL; i++);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: create default syslog(3) to OSSP l2 level/priority mapping table\n");
+ for (i = 0; sysloglevel2string[i].string != NULL; i++)
+ ;
if ((ctx.levelmap = (levelmap_t *)malloc(i * sizeof(levelmap_t))) == NULL) {
- fsldebug(L2_LEVEL_ERROR, "Error: malloc() failed\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); }
for (i = 0; sysloglevel2string[i].string != NULL; i++) {
ctx.levelmap[i].syslog = sysloglevel2string[i].level;
ctx.levelmap[i].l2 = sysloglevel2string[i].deflevelmap;
- fsldebug(L2_LEVEL_DEBUG, "ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n",
+ i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
}
- /* create L2 environment for main application */
+ /* create OSSP l2 environment for main application */
if ((l2rv = l2_env_create(&ctx.l2_env)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "failed to create L2 environment: (%d)\n", l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: failed to create OSSP l2 environment: (%d)\n", l2rv); CU(1); }
if ((l2rv = l2_env_levels(ctx.l2_env, L2_LEVEL_ALL, L2_LEVEL_NONE)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to set global logging level defaults: %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to set global logging level defaults: %s(%d)\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_env, 'D', l2_util_fmt_dump, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register dump formatter: %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register dump formatter: %s(%d)\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_env, 'S', l2_util_fmt_string, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register string formatter: %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register string formatter: %s(%d)\n", cp, l2rv); CU(1); }
if ((l2rv = l2_env_formatter(ctx.l2_env, 'm', l2_util_fmt_errno, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to register errno formatter: %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to register errno formatter: %s(%d)\n", cp, l2rv); CU(1); }
if ((l2rv = l2_channel_create(&ctx.l2_nch, ctx.l2_env, "noop")) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create noop channel: %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create noop channel: %s(%d)\n", cp, l2rv); CU(1); }
/* create IdentSlashFacility */
if ((cpIdent = strdup((ident != NULL) ? ident : "unknown")) == NULL) {
- fsldebug(L2_LEVEL_ERROR, "strdup() failed\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: strdup() failed\n"); CU(1); }
cpFacility = "unknown";
for (i = 0; syslogfacility2string[i].string != NULL; i++) {
if (facility == syslogfacility2string[i].facility) {
@@ -398,58 +544,60 @@
}
}
if ((cpISF = (char *)malloc(strlen(cpIdent) + 1 + strlen(cpFacility) + 1)) == NULL) {
- fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); }
cpISF[0] = '\0';
strcat(cpISF, cpIdent);
strcat(cpISF, "/");
strcat(cpISF, cpFacility);
+ /* read in configuration file(s) */
if ((rv = readfileorallfiles(&buf, ident)) != FSL_OK) {
- fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); }
+ /* import configuration buffer into OSSP cfg node tree */
if ((cfgrv = cfg_create(&cfg)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_create() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if ((cfgrv = cfg_import(cfg, NULL, CFG_FMT_CFG, buf.base, buf.size)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_import() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
- /* find root and check if it is a sequence and has one or more directives below it */
+ /* find configuration root node and check if it is a sequence and has one or more directives below it */
if ((cfgrv = cfg_node_root(cfg, &cfgseq)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_root() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
traverse(cfg, cfgseq);
if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgtype != CFG_NODE_TYPE_SEQ) {
- fsldebug(L2_LEVEL_ERROR, "expected sequence\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: expected sequence\n"); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgnumc < 1) {
- fsldebug(L2_LEVEL_ERROR, "sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: sequence is missing directives, expected 1, got %d\n", cfgnumc); CU(1); }
/* get first directive below sequence */
if ((cfgrv = cfg_node_get(cfg, cfgseq, CFG_NODE_ATTR_CHILD1, &cfgdir)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
while (cfgdir != NULL) {
/* check if operating on a directive */
if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgtype != CFG_NODE_TYPE_DIR) {
- fsldebug(L2_LEVEL_ERROR, "expected directive\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: expected directive\n"); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILDS, &cfgnumc)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILDS) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
/* process first child of directive, check if it is an argument and has a valid token attached */
if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_CHILD1, &cfgarg)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_CHILD1) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgarg == NULL) {
- fsldebug(L2_LEVEL_ERROR, "first argument is NULL\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: first argument is NULL\n"); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgtype != CFG_NODE_TYPE_ARG) {
- fsldebug(L2_LEVEL_ERROR, "expected first argument, got %d\n", cfgtype); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: expected first argument, got %d\n", cfgtype); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgargtok == NULL) {
- fsldebug(L2_LEVEL_ERROR, "first argument has NULL data\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: first argument has NULL data\n"); CU(1); }
cfgargtoka[0] = cfgargtok;
cfgnume = 0;
@@ -460,36 +608,34 @@
if (strcmp(cfgargtoka[0], "map") == 0)
cfgnume = 3;
if (cfgnume == 0) {
- fsldebug(L2_LEVEL_ERROR, "syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: syntax error, invalid argument \"%s\"\n", cfgargtoka[0]); CU(1); }
if (cfgnume != cfgnumc) {
- fsldebug(L2_LEVEL_ERROR, "directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: directive missing arguments, expected %d, got %d\n", cfgnume, cfgnumc); CU(1); }
for (i = 1; i < cfgnume; i++) {
-
/* process right brother of argument, check if it is an argument and has a valid token attached */
if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_RBROTH, &cfgarg)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgarg == NULL) {
- fsldebug(L2_LEVEL_ERROR, "argument %d is NULL\n", i); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: argument %d is NULL\n", i); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TYPE, &cfgtype)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TYPE) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgtype != CFG_NODE_TYPE_ARG) {
- fsldebug(L2_LEVEL_ERROR, "expected argument %d\n", i); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: expected argument %d\n", i); CU(1); }
if ((cfgrv = cfg_node_get(cfg, cfgarg, CFG_NODE_ATTR_TOKEN, &cfgargtok)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_node_get(CFG_NODE_ATTR_TOKEN) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
if (cfgargtok == NULL) {
- fsldebug(L2_LEVEL_ERROR, "argument %d has NULL data\n", i); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: argument %d has NULL data\n", i); CU(1); }
cfgargtoka[i] = cfgargtok;
}
if ((strcmp(cfgargtoka[0], "ident") == 0) || (strcmp(cfgargtoka[0], "default") == 0)) { /*FIXME currently default and ident are identical*/
-
argident = cfgargtoka[0];
argmatch = cfgargtoka[1];
argl2spec = cfgargtoka[2];
/* process the directive using the three arguments found */
- fsldebug(L2_LEVEL_DEBUG, "argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
{
pcre *pcreRegex;
pcre_extra *pcreExtra;
@@ -499,37 +645,37 @@
/* compile regular expression into finite state machine and optimize */
if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) {
- fsldebug(L2_LEVEL_ERROR, "pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: pcre_compile() failed with error %s (%d)\n", cpError, iError); CU(1); }
pcreExtra = pcre_study(pcreRegex, 0, &cpError);
if (cpError != NULL) {
- fsldebug(L2_LEVEL_ERROR, "pcre_study() failed with error %s\n", cpError); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: pcre_study() failed with error %s\n", cpError); CU(1); }
nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE);
if (nMatch < 0)
- fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" failed.\n", cpISF, argmatch);
+ fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" failed.\n", cpISF, argmatch);
else
if (nMatch == 0)
- fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" succeeded, found $0\n", cpISF, argmatch);
+ fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0\n", cpISF, argmatch);
else
- fsldebug(L2_LEVEL_TRACE, "matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d\n", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1));
+ fsldebug(L2_LEVEL_TRACE, "openlog: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d\n", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1));
if (nMatch >= 1) {
pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch);
if (acpMatch != NULL)
for (i = 0; i < nMatch; i++)
- fsldebug(L2_LEVEL_DEBUG, "regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: regex reference[%d]=\'%s\'\n", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]);
n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL);
if ((cp = (char *)malloc(n + 1)) == NULL) {
- fsldebug(L2_LEVEL_ERROR, "malloc() failed\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: malloc() failed\n"); CU(1); }
if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) {
- fsldebug(L2_LEVEL_ERROR, "substcapture() failed\n"); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: substcapture() failed\n"); CU(1); }
argl2spec = cp;
- fsldebug(L2_LEVEL_DEBUG, "argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: argident=%s, argmatch=%s, argl2spec=%s\n", argident, argmatch, argl2spec);
/* create L2 channel throuh spec and link into root channel */
if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to create stream from spec %s(%d)\n", cp, l2rv); CU(1); }
if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); }
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to link child channel %s(%d)\n", cp, l2rv); CU(1); }
free(argl2spec);
}
@@ -545,33 +691,34 @@
mapfrom = i;
}
if (mapfrom == -1) {
- fsldebug(L2_LEVEL_ERROR, "trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: trying to map from unknown syslog level \"%s\"\n", cfgargtoka[1]); CU(1); }
for (i = 0, mapto = -1; (mapto == -1) && (l2level2string[i].string != NULL); i++) {
if (strcmp(l2level2string[i].string, cfgargtoka[2]) == 0)
mapto = i;
}
if (mapto == -1) {
- fsldebug(L2_LEVEL_ERROR, "trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: trying to map to unknown l2 level \"%s\"\n", cfgargtoka[2]); CU(1); }
ctx.levelmap[mapfrom].l2 = l2level2string[mapto].level;
- fsldebug(L2_LEVEL_DEBUG, "map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level);
+ fsldebug(L2_LEVEL_DEBUG, "openlog: map levelmap[%10s/%d].l2 = l2level2string[%10s/%d].level = 0x%.8lx\n", cfgargtoka[1], mapfrom, cfgargtoka[2], mapto, (unsigned long)l2level2string[mapto].level);
}
else {
- fsldebug(L2_LEVEL_ERROR, "internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "openlog: internal, argument \"%s\" not implemented\n", cfgargtoka[0]); CU(1); }
/* get right brother of current directive */
if ((cfgrv = cfg_node_get(cfg, cfgdir, CFG_NODE_ATTR_RBROTH, &cfgdir)) != CFG_OK) {
(void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_node_get(CFG_NODE_ATTR_RBROTH) failed with error %s (%d)\n", cp, cfgrv); CU(1); }
}
+
if (logopt & LOG_NDELAY) {
ctx.delayopen = TRUE;
- fsldebug(L2_LEVEL_TRACE, "logopt LOG_NDELAY delays open of L2 channel tree until first message is being logged");
+ fsldebug(L2_LEVEL_TRACE, "openlog: logopt LOG_NDELAY delays open of L2 channel tree until first message is being logged");
}
else {
if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) immediately\n", cp, l2rv); CU(1); }
- fsldebug(L2_LEVEL_TRACE, "logging succeeded to open channel stream immediately");
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "openlog: logging failed to open channel stream %s(%d) immediately\n", cp, l2rv); CU(1); }
+ fsldebug(L2_LEVEL_TRACE, "openlog: logging succeeded to open channel stream immediately");
}
CU(0);
@@ -580,10 +727,10 @@
free(cpISF);
if (cpIdent != NULL)
free(cpIdent);
-#if 0
+#if 0 /* FIXME */
if (cfg != NULL)
if ((cfgrv = cfg_destroy(cfg)) != CFG_OK) {
- (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
+ (void)cfg_error(cfg, cfgrv, &cp); fsldebug(L2_LEVEL_ERROR, "openlog: cfg_destroy() failed with error %s (%d)\n", cp, cfgrv); CU(1); }
#endif
if (buf.base != NULL)
free(buf.base);
@@ -592,10 +739,11 @@
return;
}
+/* faked POSIX API function closelog(3) */
void closelog(void)
{
if (ctx.l2_fslnch != NULL) {
- l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured closelog()");
+ l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "closelog()");
l2_channel_destroy(ctx.l2_fslnch);
ctx.l2_fslnch = NULL;
}
@@ -621,20 +769,20 @@
return;
}
+/* faked POSIX API function setlogmask(3) */
int setlogmask(int maskpri)
{
int oldmask;
if (ctx.l2_fslnch != NULL)
- l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(maskpri=0x%.8lx)", maskpri);
-
+ l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "setlogmask(maskpri=0x%.8lx)", maskpri);
oldmask = ctx.maskpri;
-
if (maskpri != 0)
ctx.maskpri = maskpri;
return oldmask;
}
+/* faked POSIX API function syslog(3) */
void syslog(int priority, const char *message, ...)
{
va_list args;
@@ -646,6 +794,7 @@
return;
}
+/* faked POSIX API function vsyslog(3) */
#ifdef HAVE_VSYSLOG_USVALIST
void vsyslog(int priority, const char *fmt, __va_list args)
#else
@@ -661,173 +810,45 @@
if (ctx.l2_nch == NULL)
return;
+#if 0
+ /* tracing */
+ if (ctx.l2_fslnch != NULL)
+ l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "vsyslog(priority=%d, fmt=\"%s\", ...)", priority, fmt);
+#endif
+
/* check for delayed open */
if ((ctx.logopt & LOG_NDELAY) && (ctx.delayopen == TRUE)) {
if ((l2rv = l2_channel_open(ctx.l2_nch)) != L2_OK) {
- cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "logging failed to open channel stream %s(%d) delayed\n", cp, l2rv);
+ cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "vsyslog: logging failed to open channel stream %s(%d) delayed\n", cp, l2rv);
closelog();
}
- fsldebug(L2_LEVEL_TRACE, "logging succeeded to open channel stream delayed");
+ fsldebug(L2_LEVEL_TRACE, "vsyslog: logging succeeded to open channel stream delayed");
ctx.delayopen = FALSE;
}
/* strip off facility */
priority &= LOG_PRIMASK;
- fsldebug(L2_LEVEL_DEBUG, "priority =0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri);
+ fsldebug(L2_LEVEL_DEBUG, "vsyslog: priority=0x%.8lx, ctx.maskpri=0x%.8lx ", (unsigned long)priority, (unsigned long)ctx.maskpri);
/* check against maskpri */
if ((LOG_MASK(priority) & ctx.maskpri) == 0) {
- fsldebug(L2_LEVEL_DEBUG, "short circuit maskpri\n");
+ fsldebug(L2_LEVEL_DEBUG, "vsyslog: short circuit maskpri\n");
return;
}
levelmask = 0;
for (i = 0; sysloglevel2string[i].string != NULL; i++) {
- fsldebug(L2_LEVEL_DEBUG, "ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
+ fsldebug(L2_LEVEL_DEBUG, "vsyslog: ctx.levelmap[%d].syslog = 0x%.8lx, ctx.levelmap[%d].l2 = 0x%.8lx\n", i, (unsigned long)ctx.levelmap[i].syslog, i, (unsigned long)ctx.levelmap[i].l2);
if (ctx.levelmap[i].syslog == priority) {
levelmask = ctx.levelmap[i].l2;
break;
}
}
- fsldebug(L2_LEVEL_DEBUG, "levelmask=0x%.8lx\n", (unsigned long)levelmask);
+ fsldebug(L2_LEVEL_DEBUG, "vsyslog: levelmask=0x%.8lx\n", (unsigned long)levelmask);
if ((l2rv = l2_channel_vlog(ctx.l2_nch, levelmask, fmt, args)) != L2_OK) {
cp = l2_env_strerror(ctx.l2_env, l2rv);
- fsldebug(L2_LEVEL_PANIC, "applicaion logging failed %s(%d)\n", cp, l2rv);
+ fsldebug(L2_LEVEL_PANIC, "vsyslog: application logging failed: %s (%d)\n", cp, l2rv);
}
return;
}
-fsl_rc_t readfileorallfiles(buf_t *buffer, const char *ident)
-{
- fsl_rc_t rv;
-
- if (ident == NULL)
- return FSL_ERR_ARG;
- fsldebug(L2_LEVEL_TRACE, "readfileorallfiles(buffer, ident=\"%s\")\n", ident);
-
- if ((rv = readfile(buffer, ident)) == FSL_OK)
- return FSL_OK;
-
- if (rv != FSL_ERR_SYS || errno != ENOENT)
- return rv;
-
- if ((rv = readallfiles(buffer)) != FSL_OK)
- return rv;
-
- return FSL_OK;
-}
-
-fsl_rc_t readfile(buf_t *buffer, const char *ident)
-{
- fsl_rc_t rc;
- char *filename = NULL;
-
- if (ident == NULL || buffer == NULL)
- CU(FSL_ERR_ARG);
- fsldebug(L2_LEVEL_TRACE, "readfile(buffer, ident=\"%s\")\n", ident);
-
- if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + strlen(FSL_PREFIX) + strlen(ident) + 1)) == NULL)
- CU(FSL_ERR_MEM);
- filename[0] = '\0';
- strcat(filename, FSL_CFGDIR);
- strcat(filename, "/");
- strcat(filename, FSL_PREFIX);
- strcat(filename, ident);
-
- CU(appendfiletobuffer(buffer, filename));
-CUS:
- if (filename != NULL)
- free(filename);
- return rc;
-}
-
-fsl_rc_t readallfiles(buf_t *buffer)
-{
- fsl_rc_t rc;
- DIR *dp;
- struct dirent *de;
- char *filename = NULL;
- int n;
-
- if (buffer == NULL)
- CU(FSL_ERR_ARG);
- fsldebug(L2_LEVEL_TRACE, "readallfiles(buffer) globbing \"%s/%s*\"\n", FSL_CFGDIR, FSL_PREFIX);
-
- if ((dp = opendir(FSL_CFGDIR)) == NULL)
- CU(FSL_ERR_SYS);
-
- rc = FSL_ERR_ARG;
- while ((de = readdir(dp)) != NULL) {
- n = strlen(de->d_name);
- if ( (n >= strlen(FSL_PREFIX))
- && (strncmp(de->d_name, FSL_PREFIX, strlen(FSL_PREFIX)) == 0)
- ) {
- if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + n + 1)) == NULL)
- CU(FSL_ERR_MEM);
- filename[0] = '\0';
- strcat(filename, FSL_CFGDIR);
- strcat(filename, "/");
- strcat(filename, de->d_name);
- if (appendfiletobuffer(buffer, filename) == FSL_OK)
- rc = FSL_OK;
- free(filename);
- filename = NULL;
- }
- }
- (void)closedir(dp);
- CU(rc);
-CUS:
- if (filename != NULL)
- free(filename);
- return rc;
-}
-
-fsl_rc_t appendfiletobuffer(buf_t *buffer, const char *filename)
-{
- fsl_rc_t rc;
- int fd = -1;
- int filesize;
- int fileread;
- int bufferneed;
-
- if (filename == NULL || buffer == NULL)
- CU(FSL_ERR_ARG);
- fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")\n", filename);
-
- if ((fd = open(filename, O_RDONLY)) == -1)
- CU(FSL_ERR_SYS);
-
- if ((filesize = (int)lseek(fd, 0, SEEK_END)) == -1)
- CU(FSL_ERR_SYS);
-
- bufferneed = buffer->used + filesize;
- if (bufferneed > buffer->size) {
- if (buffer->base == NULL) {
- if ((buffer->base = (char *)malloc(bufferneed)) == NULL)
- CU(FSL_ERR_MEM);
- buffer->size = bufferneed;
- buffer->used = 0;
- }
- else {
- if ((buffer->base = (char *)realloc(buffer->base, bufferneed)) == NULL)
- CU(FSL_ERR_MEM);
- buffer->size = bufferneed;
- }
- }
-
- if (lseek(fd, 0, SEEK_SET) == -1)
- CU(FSL_ERR_SYS);
-
- if ((fileread = (int)read(fd, buffer->base + buffer->used, (size_t)filesize)) == -1)
- CU(FSL_ERR_SYS);
-
- if (fileread != filesize)
- CU(FSL_ERR_USE);
-
- buffer->used += filesize;
- CU(FSL_OK);
-CUS:
- if (fd != -1)
- close(fd);
- return rc;
-}
|