-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the PrCtl data structure into a separate header file that can be
included where needed in the future. Also, to avoid potential naming conflicts with ceph's PrCtl.h, prefix the filename with "dmc". Signed-off-by: J. Eric Ivancich <[email protected]>
- Loading branch information
Showing
2 changed files
with
45 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters