1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

Remove FLAG_VERBOSE.

The global 'int flags' has always been an ugly feature of this code
base, and I suddenly thought that perhaps it's time to start throwing
it out, one flag at a time, until it's totally unused.

My first target is FLAG_VERBOSE. This was usually set by cmdline.c
when it saw a -v option on the program's command line, except that GUI
PuTTY itself sets it unconditionally on startup. And then various bits
of the code would check it in order to decide whether to print a given
message.

In the current system of front-end abstraction traits, there's no
_one_ place that I can move it to. But there are two: every place that
checked FLAG_VERBOSE has access to either a Seat or a LogPolicy. So
now each of those traits has a query method for 'do I want verbose
messages?'.

A good effect of this is that subsidiary Seats, like the ones used in
Uppity for the main SSH server module itself and the server end of
shell channels, now get to have their own verbosity setting instead of
inheriting the one global one. In fact I don't expect any code using
those Seats to be generating any messages at all, but if that changes
later, we'll have a way to control it. (Who knows, perhaps logging in
Uppity might become a thing.)

As part of this cleanup, I've added a new flag to cmdline_tooltype,
called TOOLTYPE_NO_VERBOSE_OPTION. The unconditionally-verbose tools
now set that, and it has the effect of making cmdline.c disallow -v
completely. So where 'putty -v' would previously have been silently
ignored ("I was already verbose"), it's now an error, reminding you
that that option doesn't actually do anything.

Finally, the 'default_logpolicy' provided by uxcons.c and wincons.c
(with identical definitions) has had to move into a new file of its
own, because now it has to ask cmdline.c for the verbosity setting as
well as asking console.c for the rest of its methods. So there's a new
file clicons.c which can only be included by programs that link
against both cmdline.c _and_ one of the *cons.c, and I've renamed the
logpolicy to reflect that.
This commit is contained in:
Simon Tatham
2020-01-30 06:40:21 +00:00
parent 06e9f71153
commit d20d3b20fd
24 changed files with 118 additions and 66 deletions

View File

@ -399,6 +399,7 @@ static const SeatVtable gtk_seat_vt = {
gtk_seat_get_window_pixel_size,
gtk_seat_stripctrl_new,
gtk_seat_set_trust_status,
nullseat_verbose_yes,
};
static void gtk_eventlog(LogPolicy *lp, const char *string)
@ -428,6 +429,7 @@ static const LogPolicyVtable gtk_logpolicy_vt = {
gtk_eventlog,
gtk_askappend,
gtk_logging_error,
null_lp_verbose_yes,
};
/*

View File

@ -366,9 +366,8 @@ int console_confirm_weak_cached_hostkey(
* Ask whether to wipe a session log file before writing to it.
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
*/
static int console_askappend(LogPolicy *lp, Filename *filename,
void (*callback)(void *ctx, int result),
void *ctx)
int console_askappend(LogPolicy *lp, Filename *filename,
void (*callback)(void *ctx, int result), void *ctx)
{
static const char msgtemplate[] =
"The session log file \"%.*s\" already exists.\n"
@ -468,7 +467,7 @@ void old_keyfile_warning(void)
postmsg(&cf);
}
static void console_logging_error(LogPolicy *lp, const char *string)
void console_logging_error(LogPolicy *lp, const char *string)
{
/* Errors setting up logging are considered important, so they're
* displayed to standard error even when not in verbose mode */
@ -480,11 +479,11 @@ static void console_logging_error(LogPolicy *lp, const char *string)
}
static void console_eventlog(LogPolicy *lp, const char *string)
void console_eventlog(LogPolicy *lp, const char *string)
{
/* Ordinary Event Log entries are displayed in the same way as
* logging errors, but only in verbose mode */
if (flags & FLAG_VERBOSE)
if (lp_verbose(lp))
console_logging_error(lp, string);
}
@ -624,10 +623,3 @@ bool is_interactive(void)
char *platform_get_x_display(void) {
return dupstr(getenv("DISPLAY"));
}
static const LogPolicyVtable default_logpolicy_vt = {
console_eventlog,
console_askappend,
console_logging_error,
};
LogPolicy default_logpolicy[1] = {{ &default_logpolicy_vt }};

View File

@ -399,6 +399,7 @@ static const SeatVtable plink_seat_vt = {
nullseat_get_window_pixel_size,
console_stripctrl_new,
console_set_trust_status,
cmdline_seat_verbose,
};
static Seat plink_seat[1] = {{ &plink_seat_vt }};
@ -840,7 +841,7 @@ int main(int argc, char **argv)
/*
* Start up the connection.
*/
logctx = log_init(default_logpolicy, conf);
logctx = log_init(console_cli_logpolicy, conf);
{
const char *error;
char *realhost;

View File

@ -80,8 +80,9 @@ const bool share_can_be_upstream = true;
void setup(bool single)
{
sk_init();
flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG;
flags = FLAG_INTERACTIVE;
cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG |
TOOLTYPE_NO_VERBOSE_OPTION;
default_protocol = be_default_protocol;
/* Find the appropriate default port. */
{

View File

@ -163,6 +163,7 @@ static const LogPolicyVtable server_logpolicy_vt = {
server_eventlog,
server_askappend,
server_logging_error,
null_lp_verbose_no,
};
struct AuthPolicy_ssh1_pubkey {

View File

@ -631,7 +631,7 @@ char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok)
void frontend_net_error_pending(void) {}
void platform_psftp_pre_conn_setup(void) {}
void platform_psftp_pre_conn_setup(LogPolicy *lp) {}
const bool buildinfo_gtk_relevant = false;