diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-10 23:03:58 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-04-10 23:03:58 +0300 |
commit | 7f978a28b1f5f0d4cc27e53b6ab27ee381e543ae (patch) | |
tree | b3e6b0564822cd07575635d695108c6c41f21a03 | |
parent | ff698797be85d53705306b7f0311fcd09e3072d7 (diff) | |
download | mqrd-master.tar.gz mqrd-master.tar.bz2 |
* mqrd.c: New option -d. Add more debugging output.
* mqrd.8: Document -d
-rw-r--r-- | mqrd.8 | 3 | ||||
-rw-r--r-- | mqrd.c | 54 |
2 files changed, 34 insertions, 23 deletions
@@ -41,6 +41,9 @@ most one request. See the section for a detailed description of the interaction protocol. .SH OPTIONS .TP +\fB\-d\fR +Increase debugging level. +.TP \fB\-f\fR Remain in the foreground. .TP @@ -34,6 +34,9 @@ int dry_run; int single_process; int terminate; long timeout_option = 5; +int debug_level; + +#define dbg(n) (debug_level>=(n)) #ifndef SYSLOG_FACILITY # define SYSLOG_FACILITY LOG_MAIL @@ -154,6 +157,9 @@ deliver_message(const char *id) struct timeval tv; long ttl; + if (dbg(1)) + syslog(LOG_DEBUG, "delivering %s", id); + if (!buf) { syslog(LOG_ERR, "not enough memory"); return -1; @@ -311,7 +317,7 @@ static const char qabc[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; /* stem of a queue file (globbing pattern) */ -#define QFSTEMGLOB "[dqtx]f" +#define QFSTEMGLOB "[dqtxh]f" static int valid_qid(const char *qid) @@ -343,7 +349,9 @@ drop_msg(const char *id) switch (glob(pat, 0, globerrfunc, &g)) { case 0: for (i = 0; i < g.gl_pathc; i++) { - syslog(LOG_DEBUG, "removing %s", g.gl_pathv[i]); + if (dbg(1)) + syslog(LOG_DEBUG, "removing %s", + g.gl_pathv[i]); if (!dry_run && unlink(g.gl_pathv[i])) { syslog(LOG_ERR, "can't remove %s: %m", g.gl_pathv[i]); @@ -373,17 +381,14 @@ process(FILE *fp) size_t len; char *p; int rc; + char *repl; if (!fgets(inbuf, sizeof(inbuf), fp)) { syslog(LOG_ERR, "fgets: %m"); return; } - - if (inbuf[0] == 0) { - fprintf(fp, "-ERR syntax error\r\n"); - syslog(LOG_INFO, "ignoring empty line"); - return; - } + if (dbg(2)) + syslog(LOG_DEBUG, "rcvd: %s", inbuf); if (trimcrlf(inbuf)) { syslog(LOG_INFO, "input line too long"); if (!single_process) { @@ -395,16 +400,23 @@ process(FILE *fp) fprintf(fp, "-ERR input too long\r\n"); return; } + if (inbuf[0] == 0) { + syslog(LOG_INFO, "ignoring empty line"); + fprintf(fp, "-ERR syntax error\r\n"); + return; + } for (p = inbuf; *p && *p != ' '; p++) ; + if (*p) + *p++ = 0; + if (!*p) { syslog(LOG_ERR, "invalid input line: %s", inbuf); fprintf(fp, "-ERR syntax error\r\n"); return; } - *p++ = 0; if (!valid_qid(p)) { syslog(LOG_ERR, "invalid QID: %s", p); @@ -421,9 +433,12 @@ process(FILE *fp) } if (rc) - fprintf(fp, "-ERR command failed\r\n"); + repl = "-ERR command failed"; else - fprintf(fp, "+OK\r\n"); + repl = "+OK"; + if (dbg(2)) + syslog(LOG_DEBUG, "sent: %s", repl); + fprintf(fp, "%s\r\n", repl); } int @@ -485,12 +500,14 @@ main(int argc, char **argv) progname = argv[0]; - while ((rc = getopt(argc, argv, "fg:hm:M:nrp:st:v")) != EOF) { + while ((rc = getopt(argc, argv, "dfg:hm:M:nrp:st:v")) != EOF) { switch (rc) { + case 'd': + debug_level++; + break; case 'f': foreground = 1; break; - case 'g': gr = getgrnam(optarg); if (!gr) { @@ -501,43 +518,34 @@ main(int argc, char **argv) } grid = gr->gr_gid; break; - case 'h': usage(stdout); exit(0); - case 'n': dry_run++; + debug_level++; break; - case 'm': maxchildren = strtoul(optarg, NULL, 10); break; - case 'M': socket_mode = strtoul(optarg, NULL, 8) & 0777; break; - case 'p': pidfile = optarg; break; - case 'r': remove = 1; break; - case 's': single_process++; break; - case 't': timeout_option = strtol(optarg, NULL, 10); break; - case 'v': version(); exit(0); - default: exit(EX_USAGE); } |