mirror of
https://github.com/moparisthebest/imapfilter
synced 2024-12-21 23:28:49 -05:00
Change debug option to take filename as argument
Don't create a debug file in ~/.imapfilter, but instead create the specified file.
This commit is contained in:
parent
a3021cca36
commit
5c1f83f7c0
@ -32,8 +32,7 @@ send_command(session *ssn, char *cmd, char *alt)
|
||||
if (ssn->socket == -1)
|
||||
return -1;
|
||||
|
||||
debug("sending command (%d):\n\n%s\n", ssn->socket,
|
||||
(opts.debug == 1 && alt ? alt : cmd));
|
||||
debug("sending command (%d):\n\n%s\n", ssn->socket, alt ? alt : cmd);
|
||||
|
||||
verbose("C (%d): %s", ssn->socket, (alt ? alt : cmd));
|
||||
|
||||
@ -85,7 +84,7 @@ imap_continuation(session *ssn, const char *cont, size_t len)
|
||||
socket_write(ssn, "\r\n", strlen("\r\n")) == -1)
|
||||
return -1;
|
||||
|
||||
if (opts.debug > 0) {
|
||||
if (opts.debug) {
|
||||
unsigned int i;
|
||||
|
||||
debug("sending continuation data (%d):\n\n", ssn->socket);
|
||||
|
@ -43,17 +43,17 @@ main(int argc, char *argv[])
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
opts.debug = 0;
|
||||
opts.verbose = 0;
|
||||
opts.interactive = 0;
|
||||
opts.log = NULL;
|
||||
opts.config = NULL;
|
||||
opts.oneline = NULL;
|
||||
opts.debug = NULL;
|
||||
|
||||
env.home = getenv("HOME");
|
||||
env.pathmax = -1;
|
||||
|
||||
while ((c = getopt(argc, argv, "Vc:de:il:v?")) != -1) {
|
||||
while ((c = getopt(argc, argv, "Vc:d:e:il:v?")) != -1) {
|
||||
switch (c) {
|
||||
case 'V':
|
||||
version();
|
||||
@ -63,8 +63,7 @@ main(int argc, char *argv[])
|
||||
opts.config = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
if (opts.debug < 2)
|
||||
opts.debug++;
|
||||
opts.debug = optarg;
|
||||
break;
|
||||
case 'e':
|
||||
opts.oneline = optarg;
|
||||
@ -166,8 +165,8 @@ void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
fprintf(stderr, "usage: imapfilter [-diVv] [-c configfile] "
|
||||
"[-e 'command'] [-l logfile]\n");
|
||||
fprintf(stderr, "usage: imapfilter [-iVv] [-c configfile] "
|
||||
"[-e 'command'] [-l logfile] [-d debugfile]\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -63,12 +63,12 @@
|
||||
|
||||
/* Program's options. */
|
||||
typedef struct options {
|
||||
int debug; /* Debugging level (0..2). */
|
||||
int verbose; /* Verbose mode. */
|
||||
int interactive; /* Act as an interpreter. */
|
||||
char *log; /* Log file for error messages. */
|
||||
char *config; /* Configuration file. */
|
||||
char *oneline; /* One line of program/configuration. */
|
||||
char *debug; /* Debug file. */
|
||||
} options;
|
||||
|
||||
/* Environment variables. */
|
||||
|
27
src/log.c
27
src/log.c
@ -139,32 +139,17 @@ fatal(unsigned int errnum, const char *fmt,...)
|
||||
int
|
||||
open_debug(void)
|
||||
{
|
||||
int n;
|
||||
char b;
|
||||
char *dt;
|
||||
int fd;
|
||||
|
||||
if (!opts.debug)
|
||||
return 0;
|
||||
|
||||
n = snprintf(&b, 1, "%s/%s", env.home, PATHNAME_DEBUG);
|
||||
if (create_file(opts.debug, S_IRUSR | S_IWUSR))
|
||||
return 1;
|
||||
|
||||
if (env.pathmax != -1 && n > env.pathmax)
|
||||
fatal(ERROR_PATHNAME,
|
||||
"pathname limit %ld exceeded: %d\n", env.pathmax, n);
|
||||
|
||||
dt = (char *)xmalloc((n + 1) * sizeof(char));
|
||||
snprintf(dt, n + 1, "%s/%s", env.home, PATHNAME_DEBUG);
|
||||
|
||||
fd = mkstemp(dt);
|
||||
|
||||
if (fd != -1) {
|
||||
debugfp = fdopen(fd, "w");
|
||||
if (debugfp == NULL) {
|
||||
error("opening debug file %s: %s\n", dt,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
debugfp = fopen(opts.debug, "w");
|
||||
if (logfp == NULL) {
|
||||
error("opening debug file %s: %s\n", opts.debug, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ request_login(const char *server, const char *port, const char *ssl,
|
||||
if ((rg = response_greeting(s)) == -1)
|
||||
goto fail;
|
||||
|
||||
if (opts.debug > 0)
|
||||
if (opts.debug)
|
||||
if (response_generic(s, imap_noop(s)) == -1)
|
||||
goto fail;
|
||||
|
||||
|
@ -87,7 +87,7 @@ receive_response(session *ssn, char *buf, long timeout, int timeoutfail)
|
||||
return -1;
|
||||
|
||||
|
||||
if (opts.debug > 0) {
|
||||
if (opts.debug) {
|
||||
int i;
|
||||
|
||||
debug("getting response (%d):\n\n", ssn->socket);
|
||||
|
Loading…
Reference in New Issue
Block a user