diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-10-25 17:52:14 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-10-25 17:52:14 +0000 |
commit | 049f6c01310006e9c30fedd46ecda44b7d1d5570 (patch) | |
tree | caf005ba74ea6df0d52b1cd8740c080483979cb5 /src/or/hibernate.c | |
parent | 7a9774eff0e8f05c1adb65f90a539986d50c40bd (diff) | |
download | tor-049f6c01310006e9c30fedd46ecda44b7d1d5570.tar.gz tor-049f6c01310006e9c30fedd46ecda44b7d1d5570.zip |
Switch remaining files to new log interface.
svn:r5315
Diffstat (limited to 'src/or/hibernate.c')
-rw-r--r-- | src/or/hibernate.c | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/or/hibernate.c b/src/or/hibernate.c index cf7cacc3f4..337b16b9db 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -22,6 +22,7 @@ hibernating, phase 2: - close all OR/AP/exit conns) */ +#define NEW_LOG_INTERFACE #include "or.h" #define HIBERNATE_STATE_LIVE 1 @@ -128,7 +129,7 @@ accounting_parse_options(or_options_t *options, int validate_only) smartlist_split_string(items, v, NULL, SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK,0); if (smartlist_len(items)<2) { - log_fn(LOG_WARN, "Too few arguments to AccountingStart"); + warn(LD_CONFIG, "Too few arguments to AccountingStart"); goto err; } s = smartlist_get(items,0); @@ -139,7 +140,7 @@ accounting_parse_options(or_options_t *options, int validate_only) } else if (0==strcasecmp(s, "day")) { unit = UNIT_DAY; } else { - log_fn(LOG_WARN, "Unrecognized accounting unit '%s': only 'month', 'week', and 'day' are supported.", s); + warn(LD_CONFIG, "Unrecognized accounting unit '%s': only 'month', 'week', and 'day' are supported.", s); goto err; } @@ -147,14 +148,14 @@ accounting_parse_options(or_options_t *options, int validate_only) case UNIT_WEEK: d = tor_parse_long(smartlist_get(items,1), 10, 1, 7, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Weekly accounting must start begin on a day between 1(Monday) and 7 (Sunday)"); + warn(LD_CONFIG, "Weekly accounting must start begin on a day between 1(Monday) and 7 (Sunday)"); goto err; } break; case UNIT_MONTH: d = tor_parse_long(smartlist_get(items,1), 10, 1, 28, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Monthly accounting must start begin on a day between 1 and 28"); + warn(LD_CONFIG, "Monthly accounting must start begin on a day between 1 and 28"); goto err; } break; @@ -167,27 +168,27 @@ accounting_parse_options(or_options_t *options, int validate_only) idx = unit==UNIT_DAY?1:2; if (smartlist_len(items) != (idx+1)) { - log_fn(LOG_WARN, "Accounting unit '%s' requires %d arguments", + warn(LD_CONFIG,"Accounting unit '%s' requires %d arguments", s, idx+1); goto err; } s = smartlist_get(items, idx); h = tor_parse_long(s, 10, 0, 23, &ok, &cp); if (!ok) { - log_fn(LOG_WARN, "Accounting start time not parseable: bad hour."); + warn(LD_CONFIG,"Accounting start time not parseable: bad hour."); goto err; } if (!cp || *cp!=':') { - log_fn(LOG_WARN,"Accounting start time not parseable: not in HH:MM format"); + warn(LD_CONFIG,"Accounting start time not parseable: not in HH:MM format"); goto err; } m = tor_parse_long(cp+1, 10, 0, 59, &ok, &cp); if (!ok) { - log_fn(LOG_WARN, "Accounting start time not parseable: bad minute"); + warn(LD_CONFIG, "Accounting start time not parseable: bad minute"); goto err; } if (!cp || *cp!='\0') { - log_fn(LOG_WARN,"Accounting start time not parseable: not in HH:MM format"); + warn(LD_CONFIG,"Accounting start time not parseable: not in HH:MM format"); goto err; } @@ -321,15 +322,15 @@ configure_accounting(time_t now) start_of_accounting_period_after(interval_start_time) <= now) { /* We didn't have recorded usage, or we don't have recorded usage * for this interval. Start a new interval. */ - log_fn(LOG_INFO, "Starting new accounting interval."); + info(LD_ACCT, "Starting new accounting interval."); reset_accounting(now); } else if (interval_start_time == start_of_accounting_period_containing(interval_start_time)) { - log_fn(LOG_INFO, "Continuing accounting interval."); + info(LD_ACCT, "Continuing accounting interval."); /* We are in the interval we thought we were in. Do nothing.*/ interval_end_time = start_of_accounting_period_after(interval_start_time); } else { - log_fn(LOG_WARN, "Mismatched accounting interval; starting a fresh one."); + warn(LD_ACCT, "Mismatched accounting interval; starting a fresh one."); reset_accounting(now); } accounting_set_wakeup_time(); @@ -370,7 +371,7 @@ update_expected_bandwidth(void) static void reset_accounting(time_t now) { - log_fn(LOG_INFO, "Starting new accounting interval."); + info(LD_ACCT, "Starting new accounting interval."); update_expected_bandwidth(); interval_start_time = start_of_accounting_period_containing(now); interval_end_time = start_of_accounting_period_after(interval_start_time); @@ -413,7 +414,7 @@ accounting_run_housekeeping(time_t now) } if (time_to_record_bandwidth_usage(now)) { if (accounting_record_bandwidth_usage(now)) { - log_fn(LOG_ERR, "Couldn't record bandwidth usage to disk; exiting."); + err(LD_FS, "Couldn't record bandwidth usage to disk; exiting."); /* This can fail when we're out of fd's, causing a crash. * The current answer is to reserve 32 more than we need, in * set_max_file_descriptors(). */ @@ -436,7 +437,7 @@ accounting_set_wakeup_time(void) if (! identity_key_is_set()) { if (init_keys() < 0) { - log_fn(LOG_ERR, "Error initializing keys"); + err(LD_BUG, "Error initializing keys"); tor_assert(0); } } @@ -458,7 +459,7 @@ accounting_set_wakeup_time(void) time_to_exhaust_bw = 24*60*60; interval_wakeup_time = interval_start_time; - log_fn(LOG_NOTICE, "Configured hibernation. This interval begins at %s " + notice(LD_ACCT, "Configured hibernation. This interval begins at %s " "and ends at %s. We have no prior estimate for bandwidth, so " "we will start out awake and hibernate when we exhaust our quota.", buf1, buf2); @@ -500,7 +501,7 @@ accounting_set_wakeup_time(void) down_time<interval_end_time?down_time:interval_end_time); format_local_iso_time(buf4, interval_end_time); - log_fn(LOG_NOTICE, "Configured hibernation. This interval began at %s; " + notice(LD_ACCT, "Configured hibernation. This interval began at %s; " "the scheduled wake-up time %s %s; " "we expect%s to exhaust our quota for this interval around %s; " "the next interval begins at %s (all times local)", @@ -566,45 +567,45 @@ read_bandwidth_usage(void) if (smartlist_len(elts)<1 || atoi(smartlist_get(elts,0)) != BW_ACCOUNTING_VERSION) { - log_fn(LOG_WARN, "Unrecognized bw_accounting file version: %s", + warn(LD_ACCT, "Unrecognized bw_accounting file version: %s", (const char*)smartlist_get(elts,0)); goto err; } if (smartlist_len(elts) < 7) { - log_fn(LOG_WARN, "Corrupted bw_accounting file: %d lines", + warn(LD_ACCT, "Corrupted bw_accounting file: %d lines", smartlist_len(elts)); goto err; } if (parse_iso_time(smartlist_get(elts,1), &t1)) { - log_fn(LOG_WARN, "Error parsing bandwidth usage start time."); + warn(LD_ACCT, "Error parsing bandwidth usage start time."); goto err; } if (parse_iso_time(smartlist_get(elts,2), &t2)) { - log_fn(LOG_WARN, "Error parsing bandwidth usage last-written time"); + warn(LD_ACCT, "Error parsing bandwidth usage last-written time"); goto err; } n_read = tor_parse_uint64(smartlist_get(elts,3), 10, 0, UINT64_MAX, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Error parsing number of bytes read"); + warn(LD_ACCT, "Error parsing number of bytes read"); goto err; } n_written = tor_parse_uint64(smartlist_get(elts,4), 10, 0, UINT64_MAX, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Error parsing number of bytes read"); + warn(LD_ACCT, "Error parsing number of bytes read"); goto err; } n_seconds = (uint32_t)tor_parse_ulong(smartlist_get(elts,5), 10,0,ULONG_MAX, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Error parsing number of seconds live"); + warn(LD_ACCT, "Error parsing number of seconds live"); goto err; } expected_bw =(uint32_t)tor_parse_ulong(smartlist_get(elts,6), 10,0,ULONG_MAX, &ok, NULL); if (!ok) { - log_fn(LOG_WARN, "Error parsing expected bandwidth"); + warn(LD_ACCT, "Error parsing expected bandwidth"); goto err; } @@ -614,7 +615,7 @@ read_bandwidth_usage(void) interval_start_time = t1; expected_bandwidth_usage = expected_bw; - log_fn(LOG_INFO, "Successfully read bandwidth accounting file written at %s for interval starting at %s. We have been active for %lu seconds in this interval. At the start of the interval, we expected to use about %lu KB per second. ("U64_FORMAT" bytes read so far, "U64_FORMAT" bytes written so far)", + info(LD_ACCT, "Successfully read bandwidth accounting file written at %s for interval starting at %s. We have been active for %lu seconds in this interval. At the start of the interval, we expected to use about %lu KB per second. ("U64_FORMAT" bytes read so far, "U64_FORMAT" bytes written so far)", (char*)smartlist_get(elts,2), (char*)smartlist_get(elts,1), (unsigned long)n_seconds_active_in_interval, @@ -666,7 +667,7 @@ hibernate_begin(int new_state, time_t now) if (new_state == HIBERNATE_STATE_EXITING && hibernate_state != HIBERNATE_STATE_LIVE) { - log(LOG_NOTICE,"Sigint received %s; exiting now.", + notice(LD_GENERAL,"Sigint received %s; exiting now.", hibernate_state == HIBERNATE_STATE_EXITING ? "a second time" : "while hibernating"); tor_cleanup(); @@ -677,7 +678,7 @@ hibernate_begin(int new_state, time_t now) while ((conn = connection_get_by_type(CONN_TYPE_OR_LISTENER)) || (conn = connection_get_by_type(CONN_TYPE_AP_LISTENER)) || (conn = connection_get_by_type(CONN_TYPE_DIR_LISTENER))) { - log_fn(LOG_INFO,"Closing listener type %d", conn->type); + info(LD_NET,"Closing listener type %d", conn->type); connection_mark_for_close(conn); } @@ -685,7 +686,7 @@ hibernate_begin(int new_state, time_t now) /* XXX upload rendezvous service descriptors with no intro points */ if (new_state == HIBERNATE_STATE_EXITING) { - log(LOG_NOTICE,"Interrupt: will shut down in %d seconds. Interrupt again to exit now.", options->ShutdownWaitLength); + notice(LD_GENERAL,"Interrupt: will shut down in %d seconds. Interrupt again to exit now.", options->ShutdownWaitLength); hibernate_end_time = time(NULL) + options->ShutdownWaitLength; } else { /* soft limit reached */ hibernate_end_time = interval_end_time; @@ -703,7 +704,7 @@ hibernate_end(int new_state) hibernate_state == HIBERNATE_STATE_DORMANT); /* listeners will be relaunched in run_scheduled_events() in main.c */ - log_fn(LOG_NOTICE,"Hibernation period ended. Resuming normal activity."); + notice(LD_ACCT,"Hibernation period ended. Resuming normal activity."); hibernate_state = new_state; hibernate_end_time = 0; /* no longer hibernating */ @@ -738,7 +739,7 @@ hibernate_go_dormant(time_t now) else hibernate_begin(HIBERNATE_STATE_DORMANT, now); - log_fn(LOG_NOTICE,"Going dormant. Blowing away remaining connections."); + notice(LD_ACCT,"Going dormant. Blowing away remaining connections."); /* Close all OR/AP/exit conns. Leave dir conns because we still want * to be able to upload server descriptors so people know we're still @@ -751,7 +752,7 @@ hibernate_go_dormant(time_t now) if (CONN_IS_EDGE(conn)) connection_edge_end(conn, END_STREAM_REASON_HIBERNATING, conn->cpath_layer); - log_fn(LOG_INFO,"Closing conn type %d", conn->type); + info(LD_NET,"Closing conn type %d", conn->type); if (conn->type == CONN_TYPE_AP) /* send socks failure if needed */ connection_mark_unattached_ap(conn, END_STREAM_REASON_HIBERNATING); else @@ -780,10 +781,10 @@ hibernate_end_time_elapsed(time_t now) format_iso_time(buf,interval_wakeup_time); if (hibernate_state != HIBERNATE_STATE_DORMANT) { /* We weren't sleeping before; we should sleep now. */ - log_fn(LOG_NOTICE, "Accounting period ended. Commencing hibernation until %s GMT",buf); + notice(LD_ACCT, "Accounting period ended. Commencing hibernation until %s GMT",buf); hibernate_go_dormant(now); } else { - log_fn(LOG_NOTICE, "Accounting period ended. This period, we will hibernate until %s GMT",buf); + notice(LD_ACCT, "Accounting period ended. This period, we will hibernate until %s GMT",buf); } } } @@ -802,7 +803,7 @@ consider_hibernation(time_t now) if (hibernate_state == HIBERNATE_STATE_EXITING) { tor_assert(hibernate_end_time); if (hibernate_end_time <= now) { - log(LOG_NOTICE,"Clean shutdown finished. Exiting."); + notice(LD_GENERAL, "Clean shutdown finished. Exiting."); tor_cleanup(); exit(0); } @@ -825,11 +826,11 @@ consider_hibernation(time_t now) * go dormant. */ if (hibernate_state == HIBERNATE_STATE_LIVE) { if (hibernate_soft_limit_reached()) { - log_fn(LOG_NOTICE,"Bandwidth soft limit reached; commencing hibernation."); + notice(LD_ACCT,"Bandwidth soft limit reached; commencing hibernation."); hibernate_begin(HIBERNATE_STATE_LOWBANDWIDTH, now); } else if (accounting_enabled && now < interval_wakeup_time) { format_iso_time(buf,interval_wakeup_time); - log_fn(LOG_NOTICE, "Commencing hibernation. We will wake up at %s GMT",buf); + notice(LD_ACCT,"Commencing hibernation. We will wake up at %s GMT",buf); hibernate_go_dormant(now); } } |