1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-02 12:02:47 -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

@ -412,7 +412,7 @@ static 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);
}
@ -549,10 +549,3 @@ int console_get_userpass_input(prompts_t *p)
return 1; /* success */
}
static const LogPolicyVtable default_logpolicy_vt = {
console_eventlog,
console_askappend,
console_logging_error,
};
LogPolicy default_logpolicy[1] = {{ &default_logpolicy_vt }};

View File

@ -995,12 +995,13 @@ static int win_gui_askappend(LogPolicy *lp, Filename *filename,
return 0;
}
static const LogPolicyVtable default_logpolicy_vt = {
static const LogPolicyVtable win_gui_logpolicy_vt = {
win_gui_eventlog,
win_gui_askappend,
win_gui_logging_error,
null_lp_verbose_yes,
};
LogPolicy default_logpolicy[1] = {{ &default_logpolicy_vt }};
LogPolicy win_gui_logpolicy[1] = {{ &win_gui_logpolicy_vt }};
/*
* Warn about the obsolescent key file format.

View File

@ -360,6 +360,7 @@ static const SeatVtable win_seat_vt = {
win_seat_get_window_pixel_size,
win_seat_stripctrl_new,
win_seat_set_trust_status,
nullseat_verbose_yes,
};
static Seat win_seat_impl = { &win_seat_vt };
Seat *const win_seat = &win_seat_impl;
@ -471,6 +472,8 @@ static void close_session(void *ignored_context)
}
}
extern LogPolicy win_gui_logpolicy[1]; /* defined in windlg.c */
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
{
MSG msg;
@ -481,8 +484,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
hinst = inst;
hwnd = NULL;
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;
sk_init();
@ -760,7 +764,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
wintw->vt = &windows_termwin_vt;
term = term_init(conf, &ucsdata, wintw);
setup_clipboards(term, conf);
logctx = log_init(default_logpolicy, conf);
logctx = log_init(win_gui_logpolicy, conf);
term_provide_logctx(term, logctx);
term_size(term, conf_get_int(conf, CONF_height),
conf_get_int(conf, CONF_width),
@ -868,7 +872,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
}
if (restricted_acl) {
lp_eventlog(default_logpolicy, "Running with restricted process ACL");
lp_eventlog(win_gui_logpolicy, "Running with restricted process ACL");
}
winselgui_set_hwnd(hwnd);
@ -2299,7 +2303,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break;
case IDM_RESTART:
if (!backend) {
lp_eventlog(default_logpolicy,
lp_eventlog(win_gui_logpolicy,
"----- Session restarted -----");
term_pwron(term, false);
start_backend();

View File

@ -101,6 +101,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 }};
@ -407,7 +408,7 @@ int main(int argc, char **argv)
!conf_get_str_nthstrkey(conf, CONF_portfwd, 0))
conf_set_bool(conf, CONF_ssh_simple, true);
logctx = log_init(default_logpolicy, conf);
logctx = log_init(console_cli_logpolicy, conf);
if (just_test_share_exists) {
if (!vt->test_for_upstream) {
@ -423,7 +424,8 @@ int main(int argc, char **argv)
}
if (restricted_acl) {
lp_eventlog(default_logpolicy, "Running with restricted process ACL");
lp_eventlog(console_cli_logpolicy,
"Running with restricted process ACL");
}
inhandle = GetStdHandle(STD_INPUT_HANDLE);

View File

@ -712,10 +712,10 @@ char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok)
return ctx->line;
}
void platform_psftp_pre_conn_setup(void)
void platform_psftp_pre_conn_setup(LogPolicy *lp)
{
if (restricted_acl) {
lp_eventlog(default_logpolicy, "Running with restricted process ACL");
lp_eventlog(lp, "Running with restricted process ACL");
}
}