mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Revise control spec and implementation to allow all log messages to be sent to controller with their severities intact.
svn:r4010
This commit is contained in:
parent
46be0fa999
commit
4991290935
@ -215,11 +215,22 @@ the message.
|
||||
|
||||
Message [NUL-terminated]
|
||||
|
||||
<obsolete: use 0x0007-0x000B instead.>
|
||||
|
||||
0x0006 -- New descriptors available
|
||||
|
||||
OR List [NUL-terminated, comma-delimited list of
|
||||
OR identity]
|
||||
|
||||
0x0007 -- Debug message occurred
|
||||
0x0008 -- Info message occurred
|
||||
0x0009 -- Notice message occurred
|
||||
0x000A -- Warning message occurred
|
||||
0x000B -- Error message occurred
|
||||
|
||||
Message [NUL-terminated]
|
||||
|
||||
|
||||
3.8. AUTHENTICATE (Type 0x0007)
|
||||
|
||||
Sent from the client to the server. Contains a 'magic cookie' to prove
|
||||
|
@ -373,6 +373,18 @@ int add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void change_callback_log_severity(int loglevelMin, int loglevelMax,
|
||||
log_callback cb)
|
||||
{
|
||||
logfile_t *lf;
|
||||
for (lf = logfiles; lf; lf = lf->next) {
|
||||
if (lf->callback == cb) {
|
||||
lf->loglevel = loglevelMin;
|
||||
lf->max_loglevel = loglevelMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Close any log handlers added by add_temp_log or marked by mark_logs_temp */
|
||||
void close_temp_logs(void)
|
||||
{
|
||||
|
@ -69,6 +69,8 @@ void close_temp_logs(void);
|
||||
void mark_logs_temp(void);
|
||||
void configure_libevent_logging(void);
|
||||
void suppress_libevent_log_msg(const char *msg);
|
||||
void change_callback_log_severity(int loglevelMin, int loglevelMax,
|
||||
log_callback cb);
|
||||
|
||||
/* Outputs a message to stdout */
|
||||
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
|
||||
|
@ -324,7 +324,8 @@ options_act(void) {
|
||||
/* Close the temporary log we used while starting up, if it isn't already
|
||||
* gone. */
|
||||
close_temp_logs();
|
||||
add_callback_log(LOG_NOTICE, LOG_ERR, control_event_logmsg);
|
||||
add_callback_log(LOG_ERR, LOG_ERR, control_event_logmsg);
|
||||
adjust_event_log_severity();
|
||||
|
||||
options->_ConnLimit =
|
||||
set_max_file_descriptors((unsigned)options->ConnLimit, MAXCONNECTIONS);
|
||||
|
@ -74,9 +74,14 @@ const char control_c_id[] = "$Id$";
|
||||
#define EVENT_STREAM_STATUS 0x0002
|
||||
#define EVENT_OR_CONN_STATUS 0x0003
|
||||
#define EVENT_BANDWIDTH_USED 0x0004
|
||||
#define EVENT_WARNING 0x0005
|
||||
#define EVENT_LOG_OBSOLETE 0x0005
|
||||
#define EVENT_NEW_DESC 0x0006
|
||||
#define _EVENT_MAX 0x0006
|
||||
#define EVENT_DEBUG_MSG 0x0007
|
||||
#define EVENT_INFO_MSG 0x0008
|
||||
#define EVENT_NOTICE_MSG 0x0009
|
||||
#define EVENT_WARN_MSG 0x000A
|
||||
#define EVENT_ERR_MSG 0x000B
|
||||
#define _EVENT_MAX 0x000B
|
||||
|
||||
/** Array mapping from message type codes to human-readable message
|
||||
* type names. */
|
||||
@ -167,13 +172,38 @@ control_cmd_to_string(uint16_t cmd)
|
||||
return (cmd<=_CONTROL_CMD_MAX_RECOGNIZED) ? CONTROL_COMMANDS[cmd] : "Unknown";
|
||||
}
|
||||
|
||||
static INLINE int
|
||||
event_to_log_severity(int event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVENT_DEBUG_MSG: return LOG_DEBUG;
|
||||
case EVENT_INFO_MSG: return LOG_INFO;
|
||||
case EVENT_NOTICE_MSG: return LOG_NOTICE;
|
||||
case EVENT_WARN_MSG: return LOG_WARN;
|
||||
case EVENT_ERR_MSG: return LOG_ERR;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE int
|
||||
log_severity_to_event(int severity)
|
||||
{
|
||||
switch (severity) {
|
||||
case LOG_DEBUG: return EVENT_DEBUG_MSG;
|
||||
case LOG_INFO: return EVENT_INFO_MSG;
|
||||
case LOG_NOTICE: return EVENT_NOTICE_MSG;
|
||||
case LOG_WARN: return EVENT_WARN_MSG;
|
||||
case LOG_ERR: return EVENT_ERR_MSG;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** Set <b>global_event_mask</b> to the bitwise OR of each live control
|
||||
* connection's event_mask field. */
|
||||
static void update_global_event_mask(void)
|
||||
{
|
||||
connection_t **conns;
|
||||
int n_conns, i;
|
||||
|
||||
global_event_mask = 0;
|
||||
get_connection_array(&conns, &n_conns);
|
||||
for (i = 0; i < n_conns; ++i) {
|
||||
@ -182,6 +212,35 @@ static void update_global_event_mask(void)
|
||||
global_event_mask |= conns[i]->event_mask;
|
||||
}
|
||||
}
|
||||
|
||||
adjust_event_log_severity();
|
||||
}
|
||||
|
||||
void adjust_event_log_severity(void) {
|
||||
int i;
|
||||
int min_log_event=EVENT_ERR_MSG, max_log_event=EVENT_DEBUG_MSG;
|
||||
|
||||
for (i = EVENT_DEBUG_MSG; i <= EVENT_ERR_MSG; ++i) {
|
||||
if (EVENT_IS_INTERESTING(i)) {
|
||||
min_log_event = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = EVENT_ERR_MSG; i >= EVENT_DEBUG_MSG; --i) {
|
||||
if (EVENT_IS_INTERESTING(i)) {
|
||||
max_log_event = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (EVENT_IS_INTERESTING(EVENT_LOG_OBSOLETE)) {
|
||||
if (min_log_event > EVENT_NOTICE_MSG)
|
||||
min_log_event = EVENT_NOTICE_MSG;
|
||||
if (max_log_event < EVENT_ERR_MSG)
|
||||
max_log_event = EVENT_ERR_MSG;
|
||||
}
|
||||
change_callback_log_severity(event_to_log_severity(min_log_event),
|
||||
event_to_log_severity(max_log_event),
|
||||
control_event_logmsg);
|
||||
}
|
||||
|
||||
/** Send a message of type <b>type</b> containing <b>len</b> bytes
|
||||
@ -1098,14 +1157,20 @@ control_event_bandwidth_used(uint32_t n_read, uint32_t n_written)
|
||||
void
|
||||
control_event_logmsg(int severity, const char *msg)
|
||||
{
|
||||
size_t len;
|
||||
if (severity > LOG_NOTICE) /* Less important than notice? ignore for now. */
|
||||
return;
|
||||
if (!EVENT_IS_INTERESTING(EVENT_WARNING))
|
||||
return;
|
||||
int oldlog = EVENT_IS_INTERESTING(EVENT_LOG_OBSOLETE) &&
|
||||
(severity == LOG_NOTICE || severity == LOG_WARN || severity == LOG_ERR);
|
||||
int event = log_severity_to_event(severity);
|
||||
|
||||
len = strlen(msg);
|
||||
send_control_event(EVENT_WARNING, (uint32_t)(len+1), msg);
|
||||
if (event<0 || !EVENT_IS_INTERESTING(event))
|
||||
event = 0;
|
||||
|
||||
if (oldlog || event) {
|
||||
size_t len = strlen(msg);
|
||||
if (event)
|
||||
send_control_event(event, (uint32_t)(len+1), msg);
|
||||
if (oldlog)
|
||||
send_control_event(EVENT_LOG_OBSOLETE, (uint32_t)(len+1), msg);
|
||||
}
|
||||
}
|
||||
|
||||
/** Called whenever we receive new router descriptors: tell any
|
||||
|
@ -1407,6 +1407,7 @@ typedef enum or_conn_status_event_t {
|
||||
OR_CONN_EVENT_CLOSED = 3,
|
||||
} or_conn_status_event_t;
|
||||
|
||||
void adjust_event_log_severity(void);
|
||||
int connection_control_finished_flushing(connection_t *conn);
|
||||
int connection_control_reached_eof(connection_t *conn);
|
||||
int connection_control_process_inbuf(connection_t *conn);
|
||||
|
Loading…
Reference in New Issue
Block a user