1 /* 2 * sigterm.c - handler for SIGTERM 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 <sys/time.h> 11 12 #include <event2/event.h> 13 14 #include "src/conf.h" 15 #include "src/util.h" 16 #include "src/tlsdate.h" 17 18 /* On sigterm, grab the system clock and write it before terminating */ 19 void action_sigterm (evutil_socket_t fd, short what, void *arg) 20 { 21 struct state *state = arg; 22 struct timeval tv; 23 info ("[event:%s] starting graceful shutdown . . .", __func__); 24 state->exitting = 1; 25 if (platform->time_get (&tv)) 26 { 27 pfatal ("[event:%s] couldn't gettimeofday to exit gracefully", __func__); 28 } 29 /* Don't change the last sync_type */ 30 state->last_time = tv.tv_sec; 31 /* Immediately save and exit. */ 32 trigger_event (state, E_SAVE, -1); 33 } 34