--- fsl.c 2002/07/24 09:45:12 1.20
+++ fsl.c 2002/07/24 15:29:01 1.21
@@ -41,7 +41,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
-#include <syslimits.h>
/* standard include we re-implement */
#include <syslog.h>
@@ -51,11 +50,6 @@
#include "cfg.h"
#include "pcre.h"
-/* default for the dedicated logfile */
-#ifndef LOGFILE
-#define LOGFILE "/tmp/syslog"
-#endif
-
#ifndef LOG_PRIMASK
#define LOG_PRIMASK (LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG)
#endif
@@ -100,19 +94,18 @@
char *string;
} syslogfacility2string[] = {
{ LOG_AUTH, "auth" },
+#ifdef LOG_AUTHPRIV
{ LOG_AUTHPRIV, "authpriv" },
+#endif
+#ifdef LOG_CONSOLE
{ LOG_CONSOLE, "console" },
+#endif
{ LOG_CRON, "cron" },
{ LOG_DAEMON, "daemon" },
+#ifdef LOG_FTP
{ LOG_FTP, "ftp" },
+#endif
{ LOG_KERN, "kern" },
- { LOG_LPR, "lpr" },
- { LOG_MAIL, "mail" },
- { LOG_NEWS, "news" },
- { LOG_SECURITY, "security" },
- { LOG_SYSLOG, "syslog" },
- { LOG_USER, "user" },
- { LOG_UUCP, "uucp" },
{ LOG_LOCAL0, "local0" },
{ LOG_LOCAL1, "local1" },
{ LOG_LOCAL2, "local2" },
@@ -121,7 +114,19 @@
{ LOG_LOCAL5, "local5" },
{ LOG_LOCAL6, "local6" },
{ LOG_LOCAL7, "local7" },
- { 0, NULL }
+ { LOG_LPR, "lpr" },
+ { LOG_MAIL, "mail" },
+ { LOG_NEWS, "news" },
+#ifdef LOG_NTP
+ { LOG_NTP, "ntp" },
+#endif
+#ifdef LOG_SECURITY
+ { LOG_SECURITY, "security" },
+#endif
+ { LOG_SYSLOG, "syslog" },
+ { LOG_USER, "user" },
+ { LOG_UUCP, "uucp" },
+ { -1, NULL }
};
static struct {
@@ -137,7 +142,7 @@
{ "notice", LOG_NOTICE, L2_LEVEL_NOTICE },
{ "info", LOG_INFO, L2_LEVEL_INFO },
{ "debug", LOG_DEBUG, L2_LEVEL_DEBUG },
- { NULL, 0, 0 }
+ { NULL, -1, -1 }
};
static struct {
@@ -153,7 +158,7 @@
{ "info", L2_LEVEL_INFO, },
{ "trace", L2_LEVEL_TRACE, },
{ "debug", L2_LEVEL_DEBUG, },
- { NULL, 0 }
+ { NULL, -1 }
};
typedef struct {
int syslog;
@@ -184,6 +189,8 @@
va_start(args, message);
if (ctx.l2_fslnch != NULL)
l2_channel_vlog(ctx.l2_fslnch, level, message, args);
+ else
+ vfprintf(stderr, message, args);
va_end(args);
return;
}
@@ -337,7 +344,7 @@
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); }
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(%s, 0x%.8lx, 0x%.8lx)", ident, logopt, facility);
+ fsldebug(L2_LEVEL_TRACE, "captured openlog(ident=\"%s\", logopt=0x%.8lx, facility=0x%.8lx)", ident, logopt, facility);
}
/*FIXME currently we completely ignore logopt LOG_CONS, LOG_NDELAY, LOG_PERROR, LOG_PID
@@ -388,7 +395,7 @@
strcat(cpISF, cpFacility);
if ((rv = readfileorallfiles(&buf, ident)) != FSL_OK) {
- fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, %s) returned %d, system %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); }
+ fsldebug(L2_LEVEL_ERROR, "readfileorallfiles(buf, \"%s\") returned %d, system error: %s(%d)\n", ident, rv, strerror(errno), errno); CU(1); }
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); }
@@ -488,7 +495,7 @@
fsldebug(L2_LEVEL_ERROR, "pcre_study() failed with error %s\n", cpError); CU(1); }
nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE);
- fsldebug(L2_LEVEL_TRACE, "nMatch=%d when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF);
+ fsldebug(L2_LEVEL_TRACE, "found %2d matches when \"%s\" is used against \"%s\"\n", nMatch, argmatch, cpISF);
if (nMatch >= 1) {
pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch);
if (acpMatch != NULL)
@@ -594,7 +601,7 @@
int oldmask;
if (ctx.l2_fslnch != NULL)
- l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(0x%.8lx)", maskpri);
+ l2_channel_log(ctx.l2_fslnch, L2_LEVEL_TRACE, "captured setlogmask(maskpri=0x%.8lx)", maskpri);
oldmask = ctx.maskpri;
@@ -659,6 +666,10 @@
{
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;
@@ -678,6 +689,7 @@
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);
@@ -700,31 +712,35 @@
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) {
- if ( (de->d_type == DT_REG)
- && (de->d_namlen >= strlen(FSL_PREFIX))
+ 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 + de->d_namlen + 1)) == NULL)
+ if ((filename = (char *)malloc(strlen(FSL_CFGDIR) + 1 + n + 1)) == NULL)
CU(FSL_ERR_MEM);
filename[0] = '\0';
strcat(filename, FSL_CFGDIR);
strcat(filename, "/");
- strncat(filename, de->d_name, de->d_namlen);
- (void /*FIXME*/)appendfiletobuffer(buffer, filename);
+ strcat(filename, de->d_name);
+ if (appendfiletobuffer(buffer, filename) == FSL_OK)
+ rc = FSL_OK;
free(filename);
filename = NULL;
}
}
(void)closedir(dp);
- CU(FSL_OK);
+ CU(rc);
CUS:
if (filename != NULL)
free(filename);
@@ -741,7 +757,7 @@
if (filename == NULL || buffer == NULL)
CU(FSL_ERR_ARG);
- fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(), filename=%s)\n", filename);
+ fsldebug(L2_LEVEL_TRACE, "appendfiletobuffer(buffer, filename=\"%s\")\n", filename);
if ((fd = open(filename, O_RDONLY)) == -1)
CU(FSL_ERR_SYS);
|