1 /* 2 * run_tlsdate.c - events for running tlsdate 3 * Copyright (c) 2013 The Chromium Authors. All rights reserved. 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "config.h" 9 10 #include <event2/event.h> 11 12 #include "src/conf.h" 13 #include "src/dbus.h" 14 #include "src/util.h" 15 #include "src/tlsdate.h" 16 17 /* TODO(wad) split out backoff logic to make this testable */ 18 void action_run_tlsdate (evutil_socket_t fd, short what, void *arg) 19 { 20 struct state *state = arg; 21 verb_debug ("[event:%s] fired", __func__); 22 if (state->last_sync_type == SYNC_TYPE_NET) 23 { 24 verb ("[event:%s] called, but network time isn't needed", 25 __func__); 26 return; 27 } 28 state->resolving = 0; 29 if (state->running) 30 { 31 /* It's possible that a network or proxy change occurred during a call. If 32 * the call succeeded, it doesn't matter. If the call fails, reissuing 33 * the attempt with the new configuration has a chance of succeeding. To 34 * avoid missing a retry, we decrement the try count and reset the 35 * backoff. 36 */ 37 if (state->tries > 0) 38 { 39 state->tries--; 40 /* TODO(wad) Make a shorter retry constant for this. */ 41 state->backoff = state->opts.wait_between_tries; 42 } 43 info ("[event:%s] requested re-run of tlsdate while tlsdate is running", 44 __func__); 45 return; 46 } 47 /* Enforce maximum retries here instead of in sigchld.c */ 48 if (state->tries < state->opts.max_tries) 49 { 50 state->tries++; 51 } 52 else 53 { 54 state->tries = 0; 55 state->backoff = state->opts.wait_between_tries; 56 error ("[event:%s] tlsdate tried and failed to get the time", __func__); 57 return; 58 } 59 state->running = 1; 60 verb ("[event:%s] attempt %d backoff %d", __func__, 61 state->tries, state->backoff); 62 /* Setup a timeout before killing tlsdate */ 63 trigger_event (state, E_TLSDATE_TIMEOUT, 64 state->opts.subprocess_wait_between_tries); 65 /* Add the response listener event */ 66 trigger_event (state, E_TLSDATE_STATUS, -1); 67 /* Fire off the child process now! */ 68 if (tlsdate (state)) 69 { 70 /* TODO(wad) Should this be fatal? */ 71 error ("[event:%s] tlsdate failed to launch!", __func__); 72 state->running = 0; 73 state->tries = 0; 74 event_del (state->events[E_TLSDATE_TIMEOUT]); 75 return; 76 } 77 } 78