mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05:00
Shout more loudly if we can't open a log file.
A user points out that logging fopen failures to the Event Log is a bit obscure, and it's possible to proceed for months in the assumption that your sessions are being correctly logged when in fact the partition was full or you were aiming them at the wrong directory. Now we produce output visibly in the PuTTY window. (cherry picked from commit e1628105163135ca21abb6a841d109969d7979ec)
This commit is contained in:
parent
31c5784d4b
commit
fbea11f44b
24
logging.c
24
logging.c
@ -88,16 +88,19 @@ static void logfopen_callback(void *handle, int mode)
|
|||||||
char buf[256], *event;
|
char buf[256], *event;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
const char *fmode;
|
const char *fmode;
|
||||||
|
int shout = FALSE;
|
||||||
|
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
ctx->state = L_ERROR; /* disable logging */
|
ctx->state = L_ERROR; /* disable logging */
|
||||||
} else {
|
} else {
|
||||||
fmode = (mode == 1 ? "ab" : "wb");
|
fmode = (mode == 1 ? "ab" : "wb");
|
||||||
ctx->lgfp = f_open(ctx->currlogfilename, fmode, FALSE);
|
ctx->lgfp = f_open(ctx->currlogfilename, fmode, FALSE);
|
||||||
if (ctx->lgfp)
|
if (ctx->lgfp) {
|
||||||
ctx->state = L_OPEN;
|
ctx->state = L_OPEN;
|
||||||
else
|
} else {
|
||||||
ctx->state = L_ERROR;
|
ctx->state = L_ERROR;
|
||||||
|
shout = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->state == L_OPEN) {
|
if (ctx->state == L_OPEN) {
|
||||||
@ -119,6 +122,23 @@ static void logfopen_callback(void *handle, int mode)
|
|||||||
"unknown"),
|
"unknown"),
|
||||||
filename_to_str(ctx->currlogfilename));
|
filename_to_str(ctx->currlogfilename));
|
||||||
logevent(ctx->frontend, event);
|
logevent(ctx->frontend, event);
|
||||||
|
if (shout) {
|
||||||
|
/*
|
||||||
|
* If we failed to open the log file due to filesystem error
|
||||||
|
* (as opposed to user action such as clicking Cancel in the
|
||||||
|
* askappend box), we should log it more prominently. We do
|
||||||
|
* this by sending it to the same place that stderr output
|
||||||
|
* from the main session goes (so, either a console tool's
|
||||||
|
* actual stderr, or a terminal window).
|
||||||
|
*
|
||||||
|
* Of course this is one case in which that policy won't cause
|
||||||
|
* it to turn up embarrassingly in a log file of real server
|
||||||
|
* output, because the whole point is that we haven't managed
|
||||||
|
* to open any such log file :-)
|
||||||
|
*/
|
||||||
|
from_backend(ctx->frontend, 1, event, strlen(event));
|
||||||
|
from_backend(ctx->frontend, 1, "\r\n", 2);
|
||||||
|
}
|
||||||
sfree(event);
|
sfree(event);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user