Skip to content

Commit

Permalink
Move the PrCtl data structure into a separate header file that can be
Browse files Browse the repository at this point in the history
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
ivancich committed Jun 9, 2017
1 parent 1b227bf commit bad581a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
42 changes: 42 additions & 0 deletions test/dmcPrCtl.h
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
43 changes: 3 additions & 40 deletions test/test_dmclock_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,9 @@
#include "dmclock_util.h"
#include "gtest/gtest.h"

#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
// process control to prevent core dumps during gtest death tests
#include "dmcPrCtl.h"


namespace dmc = crimson::dmclock;

Expand Down

0 comments on commit bad581a

Please sign in to comment.