]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_signal.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / rgw_signal.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2022 Red Hat, Inc
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16 #include "rgw_signal.h"
17 #include "global/signal_handler.h"
18 #include "common/safe_io.h"
19 #include "common/errno.h"
20 #include "rgw_main.h"
21 #include "rgw_log.h"
22
23 #ifdef HAVE_SYS_PRCTL_H
24 #include <sys/prctl.h>
25 #endif
26
27 #define dout_subsys ceph_subsys_rgw
28 #define dout_context g_ceph_context
29
30
31 static int signal_fd[2] = {0, 0};
32
33 namespace rgw {
34 namespace signal {
35
36 void sighup_handler(int signum) {
37 if (rgw::AppMain::ops_log_file != nullptr) {
38 rgw::AppMain::ops_log_file->reopen();
39 }
40 g_ceph_context->reopen_logs();
41 } /* sighup_handler */
42
43 void signal_shutdown()
44 {
45 int val = 0;
46 int ret = write(signal_fd[0], (char *)&val, sizeof(val));
47 if (ret < 0) {
48 derr << "ERROR: " << __func__ << ": write() returned "
49 << cpp_strerror(errno) << dendl;
50 }
51 } /* signal_shutdown */
52
53 void wait_shutdown()
54 {
55 int val;
56 int r = safe_read_exact(signal_fd[1], &val, sizeof(val));
57 if (r < 0) {
58 derr << "safe_read_exact returned with error" << dendl;
59 }
60 } /* wait_shutdown */
61
62 int signal_fd_init()
63 {
64 return socketpair(AF_UNIX, SOCK_STREAM, 0, signal_fd);
65 } /* signal_fd_init */
66
67 void signal_fd_finalize()
68 {
69 close(signal_fd[0]);
70 close(signal_fd[1]);
71 } /* signal_fd_finalize */
72
73 void handle_sigterm(int signum)
74 {
75 dout(1) << __func__ << dendl;
76
77 // send a signal to make fcgi's accept(2) wake up. unfortunately the
78 // initial signal often isn't sufficient because we race with accept's
79 // check of the flag wet by ShutdownPending() above.
80 if (signum != SIGUSR1) {
81 signal_shutdown();
82
83 // safety net in case we get stuck doing an orderly shutdown.
84 uint64_t secs = g_ceph_context->_conf->rgw_exit_timeout_secs;
85 if (secs)
86 alarm(secs);
87 dout(1) << __func__ << " set alarm for " << secs << dendl;
88 }
89 } /* handle_sigterm */
90
91 }} /* namespace rgw::signal */