Browse Source

revamp console output options

- the old meaning of -V[V] was moved to -D{n|N}, as these are really
  debugging options.
- don't print the info messages by default; this can be re-enabled with
  the -V switch, and is implied by most debug options (it was really
  kind of stupid that verbose/debug operation disabled these).
- the sync algo/state debugging can be separately enabled with -Ds now.
wip/server-refactor
Oswald Buddenhagen 10 years ago
parent
commit
0e1f8f9a3f
  1. 3
      NEWS
  2. 26
      src/common.h
  3. 12
      src/drv_imap.c
  4. 18
      src/drv_maildir.c
  5. 73
      src/main.c
  6. 27
      src/mbsync.1
  7. 26
      src/sync.c
  8. 39
      src/util.c

3
NEWS

@ -5,6 +5,9 @@ The 'isync' compatibility wrapper is now deprecated.
An IMAP Path/NAMESPACE rooted in INBOX won't be handled specially any more. An IMAP Path/NAMESPACE rooted in INBOX won't be handled specially any more.
This means that some Patterns may need adjustment. This means that some Patterns may need adjustment.
The default output is a lot less verbose now.
The meanings of the -V and -D options changed significantly.
The SSL/TLS configuration has been re-designed. The SSL/TLS configuration has been re-designed.
SSL is now explicitly enabled or disabled - "use SSL if available" is gone. SSL is now explicitly enabled or disabled - "use SSL if available" is gone.
Notice: Tunnels are assumed to be secure and thus default to no SSL. Notice: Tunnels are assumed to be secure and thus default to no SSL.

26
src/common.h

@ -59,14 +59,18 @@ typedef unsigned int uint;
/* main.c */ /* main.c */
#define DEBUG 1 #define DEBUG_CRASH 0x01
#define VERBOSE 2 #define DEBUG_MAILDIR 0x02
#define XVERBOSE 4 #define DEBUG_NET 0x04
#define QUIET 8 #define DEBUG_NET_ALL 0x08
#define VERYQUIET 16 #define DEBUG_SYNC 0x10
#define KEEPJOURNAL 32 #define DEBUG_ALL (0xFF & ~DEBUG_NET_ALL)
#define ZERODELAY 64 #define QUIET 0x100
#define CRASHDEBUG 128 #define VERYQUIET 0x200
#define PROGRESS 0x400
#define VERBOSE 0x800
#define KEEPJOURNAL 0x1000
#define ZERODELAY 0x2000
extern int DFlags; extern int DFlags;
extern int UseFSync; extern int UseFSync;
@ -86,10 +90,12 @@ void stats( void );
/* util.c */ /* util.c */
void ATTR_PRINTFLIKE(1, 2) debug( const char *, ... ); void vdebug( int, const char *, va_list va );
void ATTR_PRINTFLIKE(1, 2) debugn( const char *, ... ); void vdebugn( int, const char *, va_list va );
void ATTR_PRINTFLIKE(1, 2) info( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) info( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) progress( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) notice( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) warn( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) warn( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) error( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) error( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... );

12
src/drv_imap.c

@ -286,7 +286,7 @@ send_imap_cmd( imap_store_t *ctx, struct imap_cmd *cmd )
} }
bufl = nfsnprintf( buf, sizeof(buf), buffmt, bufl = nfsnprintf( buf, sizeof(buf), buffmt,
cmd->tag, cmd->cmd, cmd->param.data_len ); cmd->tag, cmd->cmd, cmd->param.data_len );
if (DFlags & VERBOSE) { if (DFlags & DEBUG_NET) {
if (ctx->num_in_progress) if (ctx->num_in_progress)
printf( "(%d in progress) ", ctx->num_in_progress ); printf( "(%d in progress) ", ctx->num_in_progress );
if (starts_with( cmd->cmd, -1, "LOGIN", 5 )) if (starts_with( cmd->cmd, -1, "LOGIN", 5 ))
@ -743,7 +743,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
if (bytes > 0) if (bytes > 0)
goto postpone; goto postpone;
if (DFlags & XVERBOSE) { if (DFlags & DEBUG_NET_ALL) {
printf( "%s=========\n", ctx->label ); printf( "%s=========\n", ctx->label );
fwrite( cur->val, cur->len, 1, stdout ); fwrite( cur->val, cur->len, 1, stdout );
printf( "%s=========\n", ctx->label ); printf( "%s=========\n", ctx->label );
@ -755,7 +755,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
goto postpone; goto postpone;
if (s == (void *)~0) if (s == (void *)~0)
goto badeof; goto badeof;
if (DFlags & VERBOSE) { if (DFlags & DEBUG_NET) {
printf( "%s%s\n", ctx->label, s ); printf( "%s%s\n", ctx->label, s );
fflush( stdout ); fflush( stdout );
} }
@ -1243,7 +1243,7 @@ imap_socket_read( void *aux )
/* A clean shutdown sequence ends with bad_callback as well (see imap_cleanup()). */ /* A clean shutdown sequence ends with bad_callback as well (see imap_cleanup()). */
break; break;
} }
if (DFlags & VERBOSE) { if (DFlags & DEBUG_NET) {
printf( "%s%s\n", ctx->label, cmd ); printf( "%s%s\n", ctx->label, cmd );
fflush( stdout ); fflush( stdout );
} }
@ -1895,12 +1895,12 @@ do_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmdp ATTR_UNUSED, const char *
iov[0].takeOwn = GiveOwn; iov[0].takeOwn = GiveOwn;
iovcnt = 1; iovcnt = 1;
if (DFlags & VERBOSE) { if (DFlags & DEBUG_NET) {
printf( "%s>+> %s\n", ctx->label, enc ); printf( "%s>+> %s\n", ctx->label, enc );
fflush( stdout ); fflush( stdout );
} }
} else { } else {
if (DFlags & VERBOSE) { if (DFlags & DEBUG_NET) {
printf( "%s>+>\n", ctx->label ); printf( "%s>+>\n", ctx->label );
fflush( stdout ); fflush( stdout );
} }

18
src/drv_maildir.c

@ -85,6 +85,16 @@ static struct flock lck;
static int MaildirCount; static int MaildirCount;
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_SYNC, msg, va );
va_end( va );
}
static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' }; static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
static uchar static uchar
@ -371,7 +381,7 @@ maildir_clear_tmp( char *buf, int bufsz, int bl )
/* This should happen infrequently enough that it won't be /* This should happen infrequently enough that it won't be
* bothersome to the user to display when it occurs. * bothersome to the user to display when it occurs.
*/ */
info( "Maildir notice: removing stale file %s\n", buf ); notice( "Maildir notice: removing stale file %s\n", buf );
if (unlink( buf ) && errno != ENOENT) if (unlink( buf ) && errno != ENOENT)
sys_error( "Maildir error: cannot remove %s", buf ); sys_error( "Maildir error: cannot remove %s", buf );
} }
@ -515,7 +525,7 @@ maildir_init_uidval( maildir_store_t *ctx )
static int static int
maildir_init_uidval_new( maildir_store_t *ctx ) maildir_init_uidval_new( maildir_store_t *ctx )
{ {
info( "Maildir notice: no UIDVALIDITY, creating new.\n" ); notice( "Maildir notice: no UIDVALIDITY, creating new.\n" );
return maildir_init_uidval( ctx ); return maildir_init_uidval( ctx );
} }
@ -768,7 +778,7 @@ maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
* tell if there were further modifications during this second. So wait. * tell if there were further modifications during this second. So wait.
* This has the nice side effect that we wait for "batches" of changes to * This has the nice side effect that we wait for "batches" of changes to
* complete. On the downside, it can potentially block indefinitely. */ * complete. On the downside, it can potentially block indefinitely. */
info( "Maildir notice: sleeping due to recent directory modification.\n" ); notice( "Maildir notice: sleeping due to recent directory modification.\n" );
sleep( 1 ); /* FIXME: should make this async */ sleep( 1 ); /* FIXME: should make this async */
goto restat; goto restat;
} }
@ -900,7 +910,7 @@ maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
maildir_free_scan( msglist ); maildir_free_scan( msglist );
return DRV_BOX_BAD; return DRV_BOX_BAD;
#else #else
info( "Maildir notice: duplicate UID; changing UIDVALIDITY.\n"); notice( "Maildir notice: duplicate UID; changing UIDVALIDITY.\n");
if ((ret = maildir_init_uid( ctx )) != DRV_OK) { if ((ret = maildir_init_uid( ctx )) != DRV_OK) {
maildir_free_scan( msglist ); maildir_free_scan( msglist );
return ret; return ret;

73
src/main.c

@ -79,9 +79,9 @@ PACKAGE " " VERSION " - mailbox synchronizer\n"
" -C, --create create mailboxes if nonexistent\n" " -C, --create create mailboxes if nonexistent\n"
" -X, --expunge expunge deleted messages\n" " -X, --expunge expunge deleted messages\n"
" -c, --config CONFIG read an alternate config file (default: ~/." EXE "rc)\n" " -c, --config CONFIG read an alternate config file (default: ~/." EXE "rc)\n"
" -D, --debug print debugging messages\n" " -D, --debug debugging modes (see manual)\n"
" -V, --verbose verbose mode (display network traffic)\n" " -V, --verbose display what is happening\n"
" -q, --quiet don't display progress info\n" " -q, --quiet don't display progress counters\n"
" -v, --version display version\n" " -v, --version display version\n"
" -h, --help display this help message\n" " -h, --help display this help message\n"
"\nIf neither --pull nor --push are specified, both are active.\n" "\nIf neither --pull nor --push are specified, both are active.\n"
@ -137,7 +137,7 @@ stats( void )
int t, l, ll, cls; int t, l, ll, cls;
static int cols = -1; static int cols = -1;
if (DFlags & QUIET) if (!(DFlags & PROGRESS))
return; return;
if (cols < 0 && (!(cs = getenv( "COLUMNS" )) || !(cols = atoi( cs )))) if (cols < 0 && (!(cs = getenv( "COLUMNS" )) || !(cols = atoi( cs ))))
@ -152,7 +152,7 @@ stats( void )
if (l > cls) if (l > cls)
buf[t][cls - 1] = '~'; buf[t][cls - 1] = '~';
} }
infon( "\v\r%s M: %.*s S: %.*s", buf[2], cls, buf[0], cls, buf[1] ); progress( "\r%s M: %.*s S: %.*s", buf[2], cls, buf[0], cls, buf[1] );
} }
static int static int
@ -424,13 +424,25 @@ main( int argc, char **argv )
else else
DFlags |= QUIET; DFlags |= QUIET;
} else if (!strcmp( opt, "verbose" )) { } else if (!strcmp( opt, "verbose" )) {
if (DFlags & VERBOSE) DFlags |= VERBOSE;
DFlags |= XVERBOSE; } else if (starts_with( opt, -1, "debug", 5 )) {
opt += 5;
if (!*opt)
op = VERBOSE | DEBUG_ALL;
else if (!strcmp( opt, "-crash" ))
op = DEBUG_CRASH;
else if (!strcmp( opt, "-maildir" ))
op = VERBOSE | DEBUG_MAILDIR;
else if (!strcmp( opt, "-net" ))
op = VERBOSE | DEBUG_NET;
else if (!strcmp( opt, "-net-all" ))
op = VERBOSE | DEBUG_NET_ALL;
else if (!strcmp( opt, "-sync" ))
op = VERBOSE | DEBUG_SYNC;
else else
DFlags |= VERBOSE | QUIET; goto badopt;
} else if (!strcmp( opt, "debug" )) DFlags |= op;
DFlags |= DEBUG | QUIET; } else if (!strcmp( opt, "pull" ))
else if (!strcmp( opt, "pull" ))
cops |= XOP_PULL, ops[M] |= XOP_HAVE_TYPE; cops |= XOP_PULL, ops[M] |= XOP_HAVE_TYPE;
else if (!strcmp( opt, "push" )) else if (!strcmp( opt, "push" ))
cops |= XOP_PUSH, ops[M] |= XOP_HAVE_TYPE; cops |= XOP_PUSH, ops[M] |= XOP_HAVE_TYPE;
@ -595,16 +607,34 @@ main( int argc, char **argv )
DFlags |= QUIET; DFlags |= QUIET;
break; break;
case 'V': case 'V':
if (DFlags & VERBOSE) DFlags |= VERBOSE;
DFlags |= XVERBOSE;
else
DFlags |= VERBOSE | QUIET;
break; break;
case 'D': case 'D':
if (*ochar == 'C') for (op = 0; *ochar; ochar++) {
DFlags |= CRASHDEBUG, ochar++; switch (*ochar) {
else case 'C':
DFlags |= CRASHDEBUG | DEBUG | QUIET; op |= DEBUG_CRASH;
break;
case 'm':
op |= DEBUG_MAILDIR | VERBOSE;
break;
case 'n':
op |= DEBUG_NET | VERBOSE;
break;
case 'N':
op |= DEBUG_NET_ALL | VERBOSE;
break;
case 's':
op |= DEBUG_SYNC | VERBOSE;
break;
default:
error( "Unknown -D flag '%c'\n", *ochar );
return 1;
}
}
if (!op)
op = DEBUG_ALL | VERBOSE;
DFlags |= op;
break; break;
case 'J': case 'J':
DFlags |= KEEPJOURNAL; DFlags |= KEEPJOURNAL;
@ -622,8 +652,11 @@ main( int argc, char **argv )
} }
} }
if (!(DFlags & (QUIET | DEBUG_ALL)) && isatty( 1 ))
DFlags |= PROGRESS;
#ifdef __linux__ #ifdef __linux__
if (DFlags & CRASHDEBUG) { if (DFlags & DEBUG_CRASH) {
signal( SIGSEGV, crashHandler ); signal( SIGSEGV, crashHandler );
signal( SIGBUS, crashHandler ); signal( SIGBUS, crashHandler );
signal( SIGILL, crashHandler ); signal( SIGILL, crashHandler );

27
src/mbsync.1

@ -1,7 +1,7 @@
.ig .ig
\" mbsync - mailbox synchronizer \" mbsync - mailbox synchronizer
\" Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org> \" Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
\" Copyright (C) 2002-2004,2011-2013 Oswald Buddenhagen <ossi@users.sf.net> \" Copyright (C) 2002-2004,2011-2015 Oswald Buddenhagen <ossi@users.sf.net>
\" Copyright (C) 2004 Theodore Y. Ts'o <tytso@mit.edu> \" Copyright (C) 2004 Theodore Y. Ts'o <tytso@mit.edu>
\" \"
\" This program is free software; you can redistribute it and/or modify \" This program is free software; you can redistribute it and/or modify
@ -20,7 +20,7 @@
\" As a special exception, mbsync may be linked with the OpenSSL library, \" As a special exception, mbsync may be linked with the OpenSSL library,
\" despite that library's more restrictive license. \" despite that library's more restrictive license.
.. ..
.TH mbsync 1 "2013 Dec 14" .TH mbsync 1 "2015 Mar 22"
.. ..
.SH NAME .SH NAME
mbsync - synchronize IMAP4 and Maildir mailboxes mbsync - synchronize IMAP4 and Maildir mailboxes
@ -78,13 +78,28 @@ Display a summary of command line options.
Display version information. Display version information.
.TP .TP
\fB-V\fR, \fB--verbose\fR \fB-V\fR, \fB--verbose\fR
Enable \fIverbose\fR mode, which displays the IMAP4 network traffic. Enable \fIverbose\fR mode, which displays what is currently happening.
.TP .TP
\fB-D\fR, \fB--debug\fR \fB-D\fR[\fBC\fR][\fBm\fR][\fBn\fR|\fBN\fR][\fBs\fR]\fR]\fR,\
Enable printing \fIdebug\fR information. \fB--debug\fR[\fB-crash\fR|\fB-maildir\fR|\fB-net\fR|\fB-net-all\fR|\fB-sync\fR]
Enable debugging categories:
.in +4
\fBC\fR, \fBcrash\fR - use built-in crash handler
.br
\fBm\fR, \fBmaildir\fR - print maildir debug info
.br
\fBn\fR, \fBnet\fR - print network traffic (protocol only)
.br
\fBN\fR, \fBnet-all\fR - print network traffic (including payloads)
.br
\fBs\fR, \fBsync\fR - print synchronization debug info
.in -4
All categories except \fBcrash\fR implictly enable \fIverbose\fR mode.
Without category specification, all categories except net-all are enabled.
.TP .TP
\fB-q\fR, \fB--quiet\fR \fB-q\fR, \fB--quiet\fR
Suppress informational messages. Suppress progress counters (this is implicit if stdout is no TTY,
or any debugging categories are enabled) and notices.
If specified twice, suppress warning messages as well. If specified twice, suppress warning messages as well.
.. ..
.SH CONFIGURATION .SH CONFIGURATION

26
src/sync.c

@ -45,6 +45,26 @@ group_conf_t *groups;
const char *str_ms[] = { "master", "slave" }, *str_hl[] = { "push", "pull" }; const char *str_ms[] = { "master", "slave" }, *str_hl[] = { "push", "pull" };
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_SYNC, msg, va );
va_end( va );
}
static void ATTR_PRINTFLIKE(1, 2)
debugn( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebugn( DEBUG_SYNC, msg, va );
va_end( va );
}
void void
Fclose( FILE *f, int safe ) Fclose( FILE *f, int safe )
{ {
@ -1347,7 +1367,7 @@ box_loaded( int sts, void *aux )
if (tmsg->srec) /* found by TUID */ if (tmsg->srec) /* found by TUID */
continue; continue;
uid = tmsg->uid; uid = tmsg->uid;
if (DFlags & DEBUG) { if (DFlags & DEBUG_SYNC) {
make_flags( tmsg->flags, fbuf ); make_flags( tmsg->flags, fbuf );
printf( svars->ctx[t]->opts & OPEN_SIZE ? " message %5d, %-4s, %6lu: " : " message %5d, %-4s: ", uid, fbuf, tmsg->size ); printf( svars->ctx[t]->opts & OPEN_SIZE ? " message %5d, %-4s, %6lu: " : " message %5d, %-4s: ", uid, fbuf, tmsg->size );
} }
@ -1413,7 +1433,7 @@ box_loaded( int sts, void *aux )
srec->uid[S] = 0; srec->uid[S] = 0;
} else { } else {
if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS) && srec->msg[t]->flags != srec->flags) if (srec->msg[t] && (srec->msg[t]->status & M_FLAGS) && srec->msg[t]->flags != srec->flags)
info( "Info: conflicting changes in (%d,%d)\n", srec->uid[M], srec->uid[S] ); notice( "Notice: conflicting changes in (%d,%d)\n", srec->uid[M], srec->uid[S] );
if (svars->chan->ops[t] & OP_DELETE) { if (svars->chan->ops[t] & OP_DELETE) {
debug( " %sing delete\n", str_hl[t] ); debug( " %sing delete\n", str_hl[t] );
srec->aflags[t] = F_DELETED; srec->aflags[t] = F_DELETED;
@ -1439,7 +1459,7 @@ box_loaded( int sts, void *aux )
} }
srec->aflags[t] = sflags & ~srec->flags; srec->aflags[t] = sflags & ~srec->flags;
srec->dflags[t] = ~sflags & srec->flags; srec->dflags[t] = ~sflags & srec->flags;
if (DFlags & DEBUG) { if (DFlags & DEBUG_SYNC) {
char afbuf[16], dfbuf[16]; /* enlarge when support for keywords is added */ char afbuf[16], dfbuf[16]; /* enlarge when support for keywords is added */
make_flags( srec->aflags[t], afbuf ); make_flags( srec->aflags[t], afbuf );
make_flags( srec->dflags[t], dfbuf ); make_flags( srec->dflags[t], dfbuf );

39
src/util.c

@ -53,39 +53,43 @@ printn( const char *msg, va_list va )
} }
void void
debug( const char *msg, ... ) vdebug( int cat, const char *msg, va_list va )
{ {
va_list va; if (DFlags & cat) {
if (DFlags & DEBUG) {
va_start( va, msg );
vprintf( msg, va ); vprintf( msg, va );
va_end( va );
fflush( stdout ); fflush( stdout );
need_nl = 0; need_nl = 0;
} }
} }
void void
debugn( const char *msg, ... ) vdebugn( int cat, const char *msg, va_list va )
{
if (DFlags & cat) {
vprintf( msg, va );
fflush( stdout );
need_nl = 1;
}
}
void
progress( const char *msg, ... )
{ {
va_list va; va_list va;
if (DFlags & DEBUG) {
va_start( va, msg ); va_start( va, msg );
vprintf( msg, va ); vprintf( msg, va );
va_end( va ); va_end( va );
fflush( stdout ); fflush( stdout );
need_nl = 1; need_nl = 1;
} }
}
void void
info( const char *msg, ... ) info( const char *msg, ... )
{ {
va_list va; va_list va;
if (!(DFlags & QUIET)) { if (DFlags & VERBOSE) {
va_start( va, msg ); va_start( va, msg );
printn( msg, va ); printn( msg, va );
va_end( va ); va_end( va );
@ -98,7 +102,7 @@ infon( const char *msg, ... )
{ {
va_list va; va_list va;
if (!(DFlags & QUIET)) { if (DFlags & VERBOSE) {
va_start( va, msg ); va_start( va, msg );
printn( msg, va ); printn( msg, va );
va_end( va ); va_end( va );
@ -106,6 +110,19 @@ infon( const char *msg, ... )
} }
} }
void
notice( const char *msg, ... )
{
va_list va;
if (!(DFlags & QUIET)) {
va_start( va, msg );
printn( msg, va );
va_end( va );
need_nl = 0;
}
}
void void
warn( const char *msg, ... ) warn( const char *msg, ... )
{ {

Loading…
Cancel
Save