Skip to content

Commit

Permalink
Use GCC by default, fix compat w/ GCC 11 & Clang 12
Browse files Browse the repository at this point in the history
SDK 21.08 only has GCC, not Clang, so we need to make sure Zypak is
compatible with it.
  • Loading branch information
refi64 committed Sep 3, 2021
1 parent 89dd114 commit e09f37c
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LIBSYSTEMD_LDLIBS := $(shell pkg-config --libs libsystemd)
DBUS_CFLAGS := $(shell pkg-config --cflags dbus-1)
DBUS_LDLIBS := $(shell pkg-config --libs dbus-1)

CXX := clang++
CXX := g++
CXXFLAGS := \
-fstack-protector-all -fstack-clash-protection -Wall -Werror \
-std=c++17 -g -pthread \
Expand Down
1 change: 0 additions & 1 deletion src/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using namespace std::literals::string_literals;
using namespace std::literals::string_view_literals;

#define ATTR_NO_WARN_UNUSED __attribute__((unused))
#define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))

// Inspired by the macro in base/posix/eintr_wrapper.h
#define HANDLE_EINTR(expr) \
Expand Down
5 changes: 3 additions & 2 deletions src/base/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ssize_t Socket::Read(int fd, std::byte* buffer, size_t size, ReadOptions options
size_t nfds = GetCMsgSize(cmsg) / sizeof(int);
options.fds->reserve(nfds);
int* cmsg_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
for (int i = 0; i < nfds; i++) {
for (size_t i = 0; i < nfds; i++) {
options.fds->emplace_back(cmsg_fds[i]);
}
} else if (cmsg->cmsg_type == SCM_CREDENTIALS) {
Expand Down Expand Up @@ -149,7 +149,8 @@ bool Socket::Write(int fd, const std::byte* buffer, size_t size, WriteOptions op
std::copy(options.fds->begin(), options.fds->end(), it);
}

return HANDLE_EINTR(sendmsg(fd, &msg, MSG_NOSIGNAL)) == size;
ssize_t sent = HANDLE_EINTR(sendmsg(fd, &msg, MSG_NOSIGNAL));
return sent != -1 ? static_cast<size_t>(sent) == size : false;
}

// static
Expand Down
1 change: 1 addition & 0 deletions src/base/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include <array>
#include <optional>
#include <vector>

#include "base/base.h"
Expand Down
2 changes: 1 addition & 1 deletion src/base/unique_fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class unique_fd {
bool invalid() const { return fd_ == kInvalidFd; }
int get() const { return fd_; }

__attribute__((warn_unused_result)) int release() {
[[nodiscard]] int release() {
int tmp = fd_;
fd_ = kInvalidFd;
return tmp;
Expand Down
4 changes: 2 additions & 2 deletions src/dbus/bus_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ std::string_view Error::message() const {
return error_.message;
}

} // namespace zypak::dbus

std::ostream& operator<<(std::ostream& os, const zypak::dbus::Error& error) {
if (error) {
os << "[" << error.name() << "] " << error.message();
Expand All @@ -47,3 +45,5 @@ std::ostream& operator<<(std::ostream& os, const zypak::dbus::Error& error) {

return os;
}

} // namespace zypak::dbus
4 changes: 2 additions & 2 deletions src/dbus/bus_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class Error {
DBusError error_;
};

} // namespace zypak::dbus

std::ostream& operator<<(std::ostream& os, const zypak::dbus::Error& error);

} // namespace zypak::dbus
4 changes: 2 additions & 2 deletions src/dbus/bus_readable_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ bool Signal::Test(std::string_view iface, std::string_view signal) const {
return dbus_message_is_signal(message(), iface.data(), signal.data());
}

} // namespace zypak::dbus

std::ostream& operator<<(std::ostream& os, const zypak::dbus::InvocationError& error) {
os << error.name().value_or("<unknown>") << ": " << error.message().value_or("<unknown>");
return os;
}

} // namespace zypak::dbus
6 changes: 4 additions & 2 deletions src/dbus/bus_readable_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include <optional>

#include "base/base.h"
#include "base/debug.h"
#include "dbus/bus_message.h"
Expand Down Expand Up @@ -113,6 +115,6 @@ class Signal : public ReadableMessage {
bool Test(std::string_view iface, std::string_view signal) const;
};

} // namespace zypak::dbus

std::ostream& operator<<(std::ostream& os, const zypak::dbus::InvocationError& error);

} // namespace zypak::dbus
2 changes: 2 additions & 0 deletions src/dbus/bus_writable_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include <optional>

#include "base/base.h"
#include "base/debug.h"
#include "dbus/bus_message.h"
Expand Down
4 changes: 2 additions & 2 deletions src/helper/chroot_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace zypak {

namespace {

ATTR_NO_WARN_UNUSED constexpr std::string_view kSandboxHelperFdVar = "SBX_D";
ATTR_NO_WARN_UNUSED constexpr std::string_view kSandboxHelperPidVar = "SBX_HELPER_PID";
ATTR_NO_WARN_UNUSED inline constexpr std::string_view kSandboxHelperFdVar = "SBX_D";
ATTR_NO_WARN_UNUSED inline constexpr std::string_view kSandboxHelperPidVar = "SBX_HELPER_PID";

} // namespace

Expand Down
7 changes: 4 additions & 3 deletions src/preload/host/spawn_strategy/supervisor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Supervisor::Result Supervisor::GetExitStatus(pid_t stub_pid, int* status) {
return Result::kNotFound;
}

if (data->exit_status == -1) {
if (!data->exit_status.has_value()) {
Debug() << "Still running, try later for " << stub_pid;
return Result::kTryLater;
}
Expand All @@ -90,7 +90,7 @@ Supervisor::Result Supervisor::WaitForExitStatus(pid_t stub_pid, int* status) {
auto stub_pids_data =
stub_pids_data_.AcquireWhen([this, stub_pid, &data](auto* stub_pids_data) {
data = FindStubPidData(StubPid(stub_pid), *stub_pids_data);
return data == nullptr || data->exit_status != -1;
return data == nullptr || data->exit_status.has_value();
});

if (data == nullptr) {
Expand Down Expand Up @@ -165,7 +165,8 @@ Supervisor::FindStubPidData(StubPid stub,
void Supervisor::ReapProcess(StubPid stub, StubPidData* data, int* status) {
Debug() << "Reaping " << stub.pid;

*status = data->exit_status;
ZYPAK_ASSERT(data->exit_status.has_value());
*status = data->exit_status.value();

if (!Socket::Write(data->notify_exit.get(), kZypakSupervisorExitReply)) {
Errno() << "Failed to let stub process " << stub.pid << " know of exit";
Expand Down
2 changes: 1 addition & 1 deletion src/preload/host/spawn_strategy/supervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Supervisor {
struct StubPidData {
supervisor_internal::ExternalPid external = -1;
supervisor_internal::InternalPid internal = -1;
std::uint32_t exit_status = -1;
std::optional<std::uint32_t> exit_status;
unique_fd notify_exit;
};

Expand Down
6 changes: 3 additions & 3 deletions src/sandbox/mimic_strategy/fork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ std::optional<pid_t> HandleFork(nickle::Reader* reader, const unique_fd& sandbox
if (!reader->Read<nickle::codecs::Int>(&desired_fd_count)) {
Log() << "Failed to read fd count";
return {};
} else if (desired_fd_count != fds.size()) {
Log() << "Given " << fds.size() << " fds, but pickle wants " << desired_fd_count;
return {};
} else if (desired_fd_count < 1) {
Log() << "Too few FDs " << fds.size();
return {};
} else if (static_cast<size_t>(desired_fd_count) != fds.size()) {
Log() << "Given " << fds.size() << " fds, but pickle wants " << desired_fd_count;
return {};
}

unique_fd pid_oracle(std::move(fds[0]));
Expand Down

0 comments on commit e09f37c

Please sign in to comment.