--- /dev/null
+#ifdef HAVE_SYS_PRCTL_H
+#include <iostream>
+#include <sys/prctl.h>
+#include "common/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: " << cpp_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: " << cpp_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
#include "log/Log.h"
#include "common/Clock.h"
#include "common/PrebufferedStreambuf.h"
+#include "include/coredumpctl.h"
#include "SubsystemMap.h"
using namespace ceph::logging;
log.inject_segv();
Entry *e = new Entry(ceph_clock_now(), pthread_self(), 10, 1);
- log.submit_entry(e); // this should segv
+ {
+ PrCtl unset_dumpable;
+ log.submit_entry(e); // this should segv
+ }
log.flush();
log.stop();
#include "include/buffer.h"
#include "include/utime.h"
+#include "include/coredumpctl.h"
#include "include/encoding.h"
#include "common/environment.h"
#include "common/Clock.h"
EXPECT_EQ(original.get_raw(), ptr.get_raw());
EXPECT_EQ(2, ptr.raw_nref());
EXPECT_EQ(0, ::memcmp(original.c_str(), ptr.c_str(), len));
+ PrCtl unset_dumpable;
EXPECT_DEATH(bufferptr(original, 0, original.length() + 1), "");
EXPECT_DEATH(bufferptr(bufferptr(), 0, 0), "");
}
EXPECT_EQ('X', ptr.c_str()[0]);
{
bufferptr ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(ptr.c_str(), "");
EXPECT_DEATH(ptr[0], "");
}
EXPECT_EQ('X', const_ptr.c_str()[0]);
{
const bufferptr const_ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(const_ptr.c_str(), "");
EXPECT_DEATH(const_ptr[0], "");
}
bufferptr ptr;
EXPECT_EQ((unsigned)0, ptr.unused_tail_length());
}
- EXPECT_DEATH(ptr[len], "");
- EXPECT_DEATH(const_ptr[len], "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(ptr[len], "");
+ EXPECT_DEATH(const_ptr[len], "");
+ }
{
const bufferptr const_ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(const_ptr.raw_c_str(), "");
EXPECT_DEATH(const_ptr.raw_length(), "");
EXPECT_DEATH(const_ptr.raw_nref(), "");
TEST(BufferPtr, copy_out) {
{
const bufferptr ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(ptr.copy_out((unsigned)0, (unsigned)0, NULL), "");
}
{
TEST(BufferPtr, copy_in) {
{
bufferptr ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(ptr.copy_in((unsigned)0, (unsigned)0, NULL), "");
}
{
char in[] = "ABCD";
bufferptr ptr(2);
- EXPECT_DEATH(ptr.copy_in((unsigned)0, strlen(in) + 1, NULL), "");
- EXPECT_DEATH(ptr.copy_in(strlen(in) + 1, (unsigned)0, NULL), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(ptr.copy_in((unsigned)0, strlen(in) + 1, NULL), "");
+ EXPECT_DEATH(ptr.copy_in(strlen(in) + 1, (unsigned)0, NULL), "");
+ }
ptr.copy_in((unsigned)0, (unsigned)2, in);
EXPECT_EQ(in[0], ptr[0]);
EXPECT_EQ(in[1], ptr[1]);
TEST(BufferPtr, append) {
{
bufferptr ptr;
+ PrCtl unset_dumpable;
EXPECT_DEATH(ptr.append('A'), "");
EXPECT_DEATH(ptr.append("B", (unsigned)1), "");
}
{
bufferptr ptr(2);
- EXPECT_DEATH(ptr.append('A'), "");
- EXPECT_DEATH(ptr.append("B", (unsigned)1), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(ptr.append('A'), "");
+ EXPECT_DEATH(ptr.append("B", (unsigned)1), "");
+ }
ptr.set_length(0);
ptr.append('A');
EXPECT_EQ((unsigned)1, ptr.length());
TEST(BufferPtr, zero) {
char str[] = "XXXX";
bufferptr ptr(buffer::create_static(strlen(str), str));
- EXPECT_DEATH(ptr.zero(ptr.length() + 1, 0), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(ptr.zero(ptr.length() + 1, 0), "");
+ }
ptr.zero(1, 1);
EXPECT_EQ('X', ptr[0]);
EXPECT_EQ('\0', ptr[1]);
bufferptr in(back);
EXPECT_EQ((unsigned)1, bl.get_num_buffers());
EXPECT_EQ((unsigned)1, bl.length());
- EXPECT_DEATH(bl.append(in, (unsigned)100, (unsigned)100), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(bl.append(in, (unsigned)100, (unsigned)100), "");
+ }
EXPECT_LT((unsigned)0, in.unused_tail_length());
in.append('B');
bl.append(in, back.end(), 1);
bufferptr ptr(s[i], strlen(s[i]));
bl.push_back(ptr);
}
- EXPECT_DEATH(bl.zero((unsigned)0, (unsigned)2000), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(bl.zero((unsigned)0, (unsigned)2000), "");
+ }
bl.zero((unsigned)2, (unsigned)5);
EXPECT_EQ(0, ::memcmp("AB\0\0\0\0\0HIKLM", bl.c_str(), 9));
}
#include "include/types.h"
#include "include/compat.h"
+#include "include/coredumpctl.h"
//#undef assert
//#define assert(foo) if (!(foo)) abort();
CompatSet::FeatureSet ro;
CompatSet::FeatureSet incompat;
- EXPECT_DEATH(compat.insert(CompatSet::Feature(0, "test")), "");
- EXPECT_DEATH(compat.insert(CompatSet::Feature(64, "test")), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(compat.insert(CompatSet::Feature(0, "test")), "");
+ EXPECT_DEATH(compat.insert(CompatSet::Feature(64, "test")), "");
+ }
for (int i = 1; i < 64; i++) {
stringstream cname;
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 &smarttab
+// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
#include "gtest/gtest.h"
#include "common/ceph_context.h"
#include "common/config.h"
+#include "include/coredumpctl.h"
/*
* Override normal ceph assert.
TEST(Mutex, DeleteLocked) {
Mutex* m = new Mutex("Recursive3",false);
m->Lock();
+ PrCtl unset_dumpable;
EXPECT_DEATH(delete m,".*");
}
#include <signal.h>
#include "os/filestore/chain_xattr.h"
#include "include/Context.h"
+#include "include/coredumpctl.h"
#include "common/errno.h"
#include "common/ceph_argparse.h"
#include "global/global_init.h"
{
int x;
const string name = user + string(CHAIN_XATTR_MAX_NAME_LEN * 2, '@');
+ PrCtl unset_dumpable;
ASSERT_DEATH(chain_setxattr(file, name.c_str(), &x, sizeof(x)), "");
ASSERT_DEATH(chain_fsetxattr(fd, name.c_str(), &x, sizeof(x)), "");
}
#include "common/Cond.h"
#include "common/errno.h"
#include "include/stringify.h"
+#include "include/coredumpctl.h"
#include "include/unordered_map.h"
#include "store_test_fixture.h"
ObjectStore::Transaction t;
t.remove_collection(cid);
cerr << "Invalid rm coll" << std::endl;
+ PrCtl unset_dumpable;
EXPECT_DEATH(apply_transaction(store, &osr, std::move(t)), ".*Directory not empty.*");
-
}
{
ObjectStore::Transaction t;
t.remove(cid, hoid);
t.remove(cid, hoid2);
t.remove_collection(cid);
+ PrCtl unset_dumpable;
EXPECT_DEATH(apply_transaction(store, &osr, std::move(t)), ".*Directory not empty.*");
}
{
#include "gtest/gtest.h"
#include "osd/PGLog.h"
#include "osd/OSDMap.h"
+#include "include/coredumpctl.h"
class PGLogTest : public ::testing::Test, protected PGLog {
public:
olog.tail = eversion_t(1, 1);
TestHandler h(remove_snap);
+ PrCtl unset_dumpable;
ASSERT_DEATH(merge_log(oinfo, olog, fromosd, info, &h,
dirty_info, dirty_big_info), "");
}
#include "osd/osd_types.h"
#include "osd/OSDMap.h"
#include "gtest/gtest.h"
+#include "include/coredumpctl.h"
#include "common/Thread.h"
#include "include/stringify.h"
#include "osd/ReplicatedBackend.h"
EXPECT_TRUE(e.object_is_indexed());
EXPECT_FALSE(e.reqid_is_indexed());
EXPECT_FALSE(missing.is_missing(oid));
+ PrCtl unset_dumpable;
EXPECT_DEATH(missing.add_next_event(e), "");
}
hobject_t oid(object_t("objname"), "key", 123, 456, 0, "");
pg_missing_t missing;
// assert if the oid does not exist
- EXPECT_DEATH(missing.got(oid, eversion_t()), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(missing.got(oid, eversion_t()), "");
+ }
EXPECT_FALSE(missing.is_missing(oid));
epoch_t epoch = 10;
eversion_t need(epoch,10);
missing.add(oid, need, eversion_t());
EXPECT_TRUE(missing.is_missing(oid));
// assert if that the version to be removed is lower than the version of the object
- EXPECT_DEATH(missing.got(oid, eversion_t(epoch / 2,20)), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(missing.got(oid, eversion_t(epoch / 2,20)), "");
+ }
// remove of a later version removes the object
missing.got(oid, eversion_t(epoch * 2,20));
EXPECT_FALSE(missing.is_missing(oid));
TEST(pool_opts_t, invalid_opt) {
EXPECT_FALSE(pool_opts_t::is_opt_name("INVALID_OPT"));
+ PrCtl unset_dumpable;
EXPECT_DEATH(pool_opts_t::get_opt_desc("INVALID_OPT"), "");
}
pool_opts_t opts;
EXPECT_FALSE(opts.is_set(pool_opts_t::SCRUB_MIN_INTERVAL));
- EXPECT_DEATH(opts.get(pool_opts_t::SCRUB_MIN_INTERVAL), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(opts.get(pool_opts_t::SCRUB_MIN_INTERVAL), "");
+ }
double val;
EXPECT_FALSE(opts.get(pool_opts_t::SCRUB_MIN_INTERVAL, &val));
opts.set(pool_opts_t::SCRUB_MIN_INTERVAL, static_cast<double>(2015));
pool_opts_t opts;
EXPECT_FALSE(opts.is_set(pool_opts_t::SCRUB_MAX_INTERVAL));
- EXPECT_DEATH(opts.get(pool_opts_t::SCRUB_MAX_INTERVAL), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(opts.get(pool_opts_t::SCRUB_MAX_INTERVAL), "");
+ }
double val;
EXPECT_FALSE(opts.get(pool_opts_t::SCRUB_MAX_INTERVAL, &val));
opts.set(pool_opts_t::SCRUB_MAX_INTERVAL, static_cast<double>(2015));
pool_opts_t opts;
EXPECT_FALSE(opts.is_set(pool_opts_t::DEEP_SCRUB_INTERVAL));
- EXPECT_DEATH(opts.get(pool_opts_t::DEEP_SCRUB_INTERVAL), "");
+ {
+ PrCtl unset_dumpable;
+ EXPECT_DEATH(opts.get(pool_opts_t::DEEP_SCRUB_INTERVAL), "");
+ }
double val;
EXPECT_FALSE(opts.get(pool_opts_t::DEEP_SCRUB_INTERVAL, &val));
opts.set(pool_opts_t::DEEP_SCRUB_INTERVAL, static_cast<double>(2015));
#include "common/signal.h"
#include "global/signal_handler.h"
#include "common/debug.h"
+#include "include/coredumpctl.h"
#include "gtest/gtest.h"
TEST(SignalHandler, LogInternal)
{
g_ceph_context->_log->inject_segv();
- ASSERT_DEATH(derr << "foo" << dendl, ".*");
+ {
+ PrCtl unset_dumpable;
+ ASSERT_DEATH(derr << "foo" << dendl, ".*");
+ }
g_ceph_context->_log->reset_segv();
}
#include "common/TextTable.h"
#include <iostream>
#include "gtest/gtest.h"
+#include "include/coredumpctl.h"
TEST(TextTable, Alignment) {
TextTable t;
t.define_column("3", TextTable::LEFT, TextTable::LEFT);
// expect assertion failure on this, which throws FailedAssertion
+ PrCtl unset_dumpable;
ASSERT_DEATH((t << "1" << "2" << "3" << "4" << TextTable::endrow), "");
}