summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-04-21 09:51:06 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-04-21 09:51:06 (GMT)
commit91a346f09d45106a61737705b35883e91ff53cfb (patch) (side-by-side diff)
treeb25f16e3a89cf485d6a2746de1c0b512143490e5 /src/main.c
parentaf130503bdad65b41bd9e40d6cd142b3b864c18a (diff)
downloadmailfromd-91a346f09d45106a61737705b35883e91ff53cfb.tar.gz
mailfromd-91a346f09d45106a61737705b35883e91ff53cfb.tar.bz2
Reimplement debugging macros and supporting functions
git-svn-id: file:///svnroot/mailfromd/trunk@1371 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c173
1 files changed, 9 insertions, 164 deletions
diff --git a/src/main.c b/src/main.c
index d9871ce..190b084 100644
--- a/src/main.c
+++ b/src/main.c
@@ -16,6 +16,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
+#define MF_SOURCE_NAME MF_SOURCE_MAIN
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
@@ -56,7 +58,6 @@ int script_dump_macros; /* Dump used Sendmail macros */
int script_dump_xref; /* Dump cross-reference */
int do_transcript; /* Enable session transript */
int do_trace; /* Enable tracing configuration */
-int debug_level; /* Debugging level */
unsigned optimization_level = 1; /* Optimization level */
int log_to_stderr; /* Use stderr for logging */
char *portspec = DEFAULT_SOCKET; /* Communication socket specification */
@@ -206,7 +207,9 @@ debug_log(char *fmt, ...)
void
log_status(sfsistat status, SMFICTX *ctx)
{
- if (debug_level >= 1 && status != SMFIS_CONTINUE) {
+ int lev;
+ debug_module_level(NULL, &lev);
+ if (lev >= 1 && status != SMFIS_CONTINUE) {
const char *str = sfsistat_str(status);
if (str)
logmsg(LOG_INFO,
@@ -218,165 +221,6 @@ log_status(sfsistat status, SMFICTX *ctx)
}
}
-struct file_debug_level {
- struct file_debug_level *next;
- char *name;
- size_t namelen;
- int level;
-};
-
-struct file_debug_level *debug_level_list;
-
-#define FILE_TO_MODULE_NAME(s,p,l) do { \
- char *q; \
- p = strrchr(s, '/'); \
- if (p) \
- p++; \
- else \
- p = s; \
- q = strrchr(p, '.'); \
- if (q) \
- l = q - s; \
- else \
- l = strlen(p); \
- if (l > 3 && memcmp(p, "bi_", 3) == 0) { \
- p += 3; \
- l -= 3; \
- } \
-} while (0);
-
-int
-debug_level_p(const char *file, int level)
-{
- struct file_debug_level *dlev;
- const char *name;
- size_t len;
-
- if (debug_level >= level)
- return 1;
-
- FILE_TO_MODULE_NAME(file, name, len);
- for (dlev = debug_level_list; dlev; dlev = dlev->next)
- if (dlev->namelen == len
- && memcmp(dlev->name, name, len) == 0
- && dlev->level >= level)
- return 1;
- return 0;
-}
-
-void
-enable_debug(const char *file)
-{
- struct file_debug_level *dlev;
- const char *p, *spec;
- char *q;
- size_t len;
- int level = 100;
-
- if (isdigit(*file)) {
- debug_level = strtoul(file, &q, 0);
- if (*q)
- mu_error("%s: wrong debug spec near %s", file, q);
- if (debug_level >= 100)
- enable_prog_trace("all");
- return;
- }
-
- FILE_TO_MODULE_NAME(file, spec, len);
- p = strchr(spec, '=');
- if (p) {
- len -= strlen(p);
- level = strtoul(p + 1, &q, 0);
- if (*q) {
- mu_error("%s: wrong debug spec near %s", file, q);
- return;
- }
- }
-
- dlev = xmalloc(sizeof *dlev);
- dlev->name = xmalloc(len + 1);
- memcpy(dlev->name, spec, len);
- dlev->name[len] = 0;
- dlev->namelen = len;
- dlev->next = debug_level_list;
- dlev->level = level;
- if (level == 100)
- enable_prog_trace(dlev->name);
- debug_level_list = dlev;
-}
-
-void
-disable_debug(const char *file)
-{
- struct file_debug_level *dlev, *prev;
- const char *p, *spec;
- char *q;
- size_t len;
- int level = 100;
-
- if (isdigit(*file)) {
- debug_level = strtoul(file, &q, 0);
- if (*q)
- mu_error("%s: wrong debug spec near %s", file, q);
- return;
- }
-
- FILE_TO_MODULE_NAME(file, spec, len);
- p = strchr(spec, '=');
- if (p) {
- len -= strlen(p);
- level = strtoul(p + 1, &q, 0);
- if (*q) {
- mu_error("%s: wrong debug spec near %s", file, q);
- return;
- }
- }
-
- dlev = debug_level_list;
- prev = NULL;
- while (dlev) {
- struct file_debug_level *next = dlev->next;
- if (dlev->namelen == len
- && memcmp(dlev->name, spec, len) == 0
- && dlev->level == level) {
- if (prev)
- prev->next = next;
- else
- debug_level_list = next;
- if (level == 100)
- disable_prog_trace(dlev->name);
- free(dlev->name);
- free(dlev);
- break;
- }
- prev = dlev;
- dlev = next;
- }
- debug_level_list = dlev;
-}
-
-void
-enable_debug_list(const char *spec)
-{
- char *copy = xstrdup(spec);
- char *s;
-
- for (s = strtok(copy,","); s; s = strtok(NULL, ","))
- enable_debug(s);
- free(copy);
-}
-
-void
-disable_debug_list(const char *spec)
-{
- char *copy = xstrdup(spec);
- char *s;
-
- for (s = strtok(copy,","); s; s = strtok(NULL, ","))
- disable_debug(s);
- free(copy);
-}
-
/* Sendmail class file support */
@@ -568,7 +412,7 @@ set_mailfrom(void *value)
static void
set_debug(void *value)
{
- enable_debug_list(value);
+ debug_parse_spec(value);
}
static void
@@ -1040,12 +884,13 @@ static struct argp_option options[] = {
"available databases"), GRP+1 },
{ "time-format", OPTION_TIME_FORMAT, N_("FMT"), 0,
N_("Output timestamps using given format (default \"%c\")"), GRP+1 },
- { "state-directory", OPTION_STATE_DIRECTORY, N_("DIR"), 0,
- N_("Set new program state directory"), GRP+1 },
+
#undef GRP
#define GRP 20
{ NULL, 0, NULL, 0,
N_("General options"), GRP },
+ { "state-directory", OPTION_STATE_DIRECTORY, N_("DIR"), 0,
+ N_("Set new program state directory"), GRP+1 },
{ "config-file", OPTION_CONFIG_FILE, N_("FILE"), OPTION_HIDDEN,
N_("Read configuration from FILE"), GRP+1 },
{ "include", 'I', N_("DIR"), 0,

Return to:

Send suggestions and report system problems to the System administrator.