-
Notifications
You must be signed in to change notification settings - Fork 54
/
dmcPrCtl.h
42 lines (40 loc) · 972 Bytes
/
dmcPrCtl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// essentially the same as ceph's PrCtl.h, copied into the dmclock library
#include <dmtest-config.h>
#ifdef HAVE_SYS_PRCTL_H
#include <iostream>
#include <sys/prctl.h>
#include <errno.h>
struct PrCtl {
int saved_state = -1;
int set_dumpable(int new_state) {
int r = prctl(PR_SET_DUMPABLE, new_state);
if (r) {
r = -errno;
std::cerr << "warning: unable to " << (new_state ? "set" : "unset")
<< " dumpable flag: " << strerror(r)
<< std::endl;
}
return r;
}
PrCtl(int new_state = 0) {
int r = prctl(PR_GET_DUMPABLE);
if (r == -1) {
r = errno;
std::cerr << "warning: unable to get dumpable flag: " << strerror(r)
<< std::endl;
} else if (r != new_state) {
if (!set_dumpable(new_state)) {
saved_state = r;
}
}
}
~PrCtl() {
if (saved_state < 0) {
return;
}
set_dumpable(saved_state);
}
};
#else
struct PrCtl {};
#endif