Skip to content

Commit

Permalink
Make dbus file descriptor check dynamic
Browse files Browse the repository at this point in the history
Without this change cros builds from outside the chroot can't run
tracing code.

BUG=None
TEST=None

Review URL: https://chromiumcodereview.appspot.com/10815083

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148351 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
davemoore@chromium.org committed Jul 25, 2012
1 parent 9a30138 commit 49cdf6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
27 changes: 18 additions & 9 deletions dbus/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@ namespace {

// Appends the header name and the value to |output|, if the value is
// not empty.
static void AppendStringHeader(const std::string& header_name,
const std::string& header_value,
std::string* output) {
void AppendStringHeader(const std::string& header_name,
const std::string& header_value,
std::string* output) {
if (!header_value.empty()) {
*output += header_name + ": " + header_value + "\n";
}
}

// Appends the header name and the value to |output|, if the value is
// nonzero.
static void AppendUint32Header(const std::string& header_name,
uint32 header_value,
std::string* output) {
void AppendUint32Header(const std::string& header_name,
uint32 header_value,
std::string* output) {
if (header_value != 0) {
*output += (header_name + ": " + base::StringPrintf("%u", header_value) +
"\n");
}
}

// Returns true if Unix FD passing is supported in libdbus.
// The check is done runtime rather than compile time as the libdbus
// version used at runtime may be different from the one used at compile time.
bool IsDBusTypeUnixFdSupported() {
int major = 0, minor = 0, micro = 0;
dbus_get_version(&major, &minor, &micro);
return major >= 1 && minor >= 4;
}

} // namespace

namespace dbus {
Expand Down Expand Up @@ -211,7 +220,7 @@ std::string Message::ToStringInternal(const std::string& indent,
break;
}
case UNIX_FD: {
CHECK(kDBusTypeUnixFdIsSupported);
CHECK(IsDBusTypeUnixFdSupported());

FileDescriptor file_descriptor;
if (!reader->PopFileDescriptor(&file_descriptor))
Expand Down Expand Up @@ -690,7 +699,7 @@ void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
}

void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
CHECK(kDBusTypeUnixFdIsSupported);
CHECK(IsDBusTypeUnixFdSupported());

if (!value.is_valid()) {
// NB: sending a directory potentially enables sandbox escape
Expand Down Expand Up @@ -960,7 +969,7 @@ bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
}

bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
CHECK(kDBusTypeUnixFdIsSupported);
CHECK(IsDBusTypeUnixFdSupported());

int fd = -1;
const bool success = PopBasic(DBUS_TYPE_UNIX_FD, &fd);
Expand Down
5 changes: 1 addition & 4 deletions dbus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class MessageWriter;
class MessageReader;

// DBUS_TYPE_UNIX_FD was added in D-Bus version 1.4
#if defined(DBUS_TYPE_UNIX_FD)
const bool kDBusTypeUnixFdIsSupported = true;
#else
const bool kDBusTypeUnixFdIsSupported = false;
#if !defined(DBUS_TYPE_UNIX_FD)
#define DBUS_TYPE_UNIX_FD ((int) 'h')
#endif

Expand Down

0 comments on commit 49cdf6e

Please sign in to comment.