void log_stop(void *handle, Config *cfg) { struct LogContext *ctx = (struct LogContext *)handle; ctx->cfg.logtype = LGTYP_NONE; logfclose(ctx); }
/* * Internal wrapper function which must be called for _all_ output * to the log file. It takes care of opening the log file if it * isn't open, buffering data if it's in the process of being * opened asynchronously, etc. */ static void logwrite(struct LogContext *ctx, void *data, int len) { /* * In state L_CLOSED, we call logfopen, which will set the state * to one of L_OPENING, L_OPEN or L_ERROR. Hence we process all of * those three _after_ processing L_CLOSED. */ if (ctx->state == L_CLOSED) logfopen(ctx); if (ctx->state == L_OPENING) { bufchain_add(&ctx->queue, data, len); } else if (ctx->state == L_OPEN) { assert(ctx->lgfp); #ifdef PERSOPORT if( !get_param("PUTTY") ) { if( timestamp_switch ) { log_writetimestamp( ctx ) ; timestamp_switch = 0 ; } char * c = (char*)(data+len-1) ; if( c[0]=='\n' ) timestamp_switch = 1 ; } #endif if (fwrite(data, 1, len, ctx->lgfp) < (size_t)len) { logfclose(ctx); ctx->state = L_ERROR; /* Log state is L_ERROR so this won't cause a loop */ logevent(ctx->frontend, "Disabled writing session log due to error while writing"); } } /* else L_ERROR, so ignore the write */ }
void log_free(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; logfclose(ctx); sfree(ctx); }
void log_free(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; logfclose(ctx); bufchain_clear(&ctx->queue); sfree(ctx); }
void log_restart(void *handle, Config *cfg) { struct LogContext *ctx = (struct LogContext *)handle; logfclose(ctx); ctx->cfg = *cfg; /* STRUCTURE COPY */ ctx->cfg.logtype = LGTYP_ASCII; logfopen(ctx); }
void log_free(void *handle) { struct LogContext *ctx = (struct LogContext *)handle; logfclose(ctx); bufchain_clear(&ctx->queue); if (ctx->currlogfilename) filename_free(ctx->currlogfilename); conf_free(ctx->conf); sfree(ctx); }
static int logfile_reopen(char *name, int wantfd, Log *l) { int got_fd; close(wantfd); if (((got_fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) || lf_move_fd(got_fd, wantfd) < 0) { logfclose(l); return -1; } changed_logfile(l); l->st->st_ino = l->st->st_dev = 0; return 0; }
static int logfile_reopen(char *name, int wantfd, struct logfile *l) { int got_fd; close(wantfd); if (((got_fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) || lf_move_fd(got_fd, wantfd) < 0) { logfclose(l); debug("logfile_reopen: failed for %s\n", name); return -1; } changed_logfile(l); l->st->st_ino = l->st->st_dev = 0; debug("logfile_reopen: %d = %s\n", wantfd, name); return 0; }
void log_reconfig(void *handle, Config *cfg) { struct LogContext *ctx = (struct LogContext *)handle; int reset_logging; if (!filename_equal(ctx->cfg.logfilename, cfg->logfilename) || ctx->cfg.logtype != cfg->logtype) reset_logging = TRUE; else reset_logging = FALSE; if (reset_logging) logfclose(ctx); ctx->cfg = *cfg; /* STRUCTURE COPY */ if (reset_logging) logfopen(ctx); }
/* * Internal wrapper function which must be called for _all_ output * to the log file. It takes care of opening the log file if it * isn't open, buffering data if it's in the process of being * opened asynchronously, etc. */ static void logwrite(struct LogContext *ctx, void *data, int len) { /* * In state L_CLOSED, we call logfopen, which will set the state * to one of L_OPENING, L_OPEN or L_ERROR. Hence we process all of * those three _after_ processing L_CLOSED. */ if (ctx->state == L_CLOSED) logfopen(ctx); if (ctx->state == L_OPENING) { bufchain_add(&ctx->queue, data, len); } else if (ctx->state == L_OPEN) { assert(ctx->lgfp); if (fwrite(data, 1, len, ctx->lgfp) < len) { logfclose(ctx); ctx->state = L_ERROR; /* Log state is L_ERROR so this won't cause a loop */ logevent(ctx->frontend, "Disabled writing session log due to error while writing"); } } /* else L_ERROR, so ignore the write */ }
void log_reconfig(void *handle, Conf *conf) { struct LogContext *ctx = (struct LogContext *)handle; int reset_logging; if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename), conf_get_filename(conf, CONF_logfilename)) || conf_get_int(ctx->conf, CONF_logtype) != conf_get_int(conf, CONF_logtype)) reset_logging = TRUE; else reset_logging = FALSE; if (reset_logging) logfclose(ctx); conf_free(ctx->conf); ctx->conf = conf_copy(conf); ctx->logtype = conf_get_int(ctx->conf, CONF_logtype); if (reset_logging) logfopen(ctx); }