]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/signal.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / signal.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
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.
12 *
13 */
14
15#include "common/BackTrace.h"
16#include "common/perf_counters.h"
17#include "global/pidfile.h"
18#include "common/debug.h"
19#include "common/signal.h"
20#include "common/config.h"
21
22#include <signal.h>
23#include <sstream>
24#include <stdlib.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27
28std::string signal_mask_to_str()
29{
30 sigset_t old_sigset;
31 if (pthread_sigmask(SIG_SETMASK, NULL, &old_sigset)) {
32 return "(pthread_signmask failed)";
33 }
34
35 ostringstream oss;
36 oss << "show_signal_mask: { ";
37 string sep("");
38 for (int signum = 0; signum < NSIG; ++signum) {
39 if (sigismember(&old_sigset, signum) == 1) {
40 oss << sep << signum;
41 sep = ", ";
42 }
43 }
44 oss << " }";
45 return oss.str();
46}
47
48/* Block the signals in 'siglist'. If siglist == NULL, block all signals. */
49void block_signals(const int *siglist, sigset_t *old_sigset)
50{
51 sigset_t sigset;
52 if (!siglist) {
53 sigfillset(&sigset);
54 }
55 else {
56 int i = 0;
57 sigemptyset(&sigset);
58 while (siglist[i]) {
59 sigaddset(&sigset, siglist[i]);
60 ++i;
61 }
62 }
63 int ret = pthread_sigmask(SIG_BLOCK, &sigset, old_sigset);
11fdf7f2 64 ceph_assert(ret == 0);
7c673cae
FG
65}
66
67void restore_sigset(const sigset_t *old_sigset)
68{
69 int ret = pthread_sigmask(SIG_SETMASK, old_sigset, NULL);
11fdf7f2 70 ceph_assert(ret == 0);
7c673cae
FG
71}
72
73void unblock_all_signals(sigset_t *old_sigset)
74{
75 sigset_t sigset;
76 sigfillset(&sigset);
77 sigdelset(&sigset, SIGKILL);
78 int ret = pthread_sigmask(SIG_UNBLOCK, &sigset, old_sigset);
11fdf7f2 79 ceph_assert(ret == 0);
7c673cae 80}