]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/signal.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
19 #include <sys/types.h>
23 #include "common/BackTrace.h"
24 #include "common/config.h"
25 #include "common/debug.h"
26 #include "common/signal.h"
27 #include "common/perf_counters.h"
29 #include "global/pidfile.h"
31 using namespace std::literals
;
34 std::string
signal_mask_to_str()
37 if (pthread_sigmask(SIG_SETMASK
, NULL
, &old_sigset
)) {
38 return "(pthread_signmask failed)";
41 std::ostringstream oss
;
42 oss
<< "show_signal_mask: { ";
44 for (int signum
= 0; signum
< NSIG
; ++signum
) {
45 if (sigismember(&old_sigset
, signum
) == 1) {
54 /* Block the signals in 'siglist'. If siglist == NULL, block all signals. */
55 void block_signals(const int *siglist
, sigset_t
*old_sigset
)
65 sigaddset(&sigset
, siglist
[i
]);
69 int ret
= pthread_sigmask(SIG_BLOCK
, &sigset
, old_sigset
);
70 ceph_assert(ret
== 0);
73 void restore_sigset(const sigset_t
*old_sigset
)
75 int ret
= pthread_sigmask(SIG_SETMASK
, old_sigset
, NULL
);
76 ceph_assert(ret
== 0);
79 void unblock_all_signals(sigset_t
*old_sigset
)
83 sigdelset(&sigset
, SIGKILL
);
84 int ret
= pthread_sigmask(SIG_UNBLOCK
, &sigset
, old_sigset
);
85 ceph_assert(ret
== 0);
88 std::string
signal_mask_to_str()
90 return "(unsupported signal)";
93 // Windows provides limited signal functionality.
94 void block_signals(const int *siglist
, sigset_t
*old_sigset
) {}
95 void restore_sigset(const sigset_t
*old_sigset
) {}
96 void unblock_all_signals(sigset_t
*old_sigset
) {}