Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a pipe and open files with the close-on-exec flag #2071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libdnf5-plugins/rhsm/rhsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Rhsm::setup_enrollments() {
bool same_content = false;
do {
int fd;
if ((fd = open(repofname, O_RDONLY)) == -1) {
if ((fd = open(repofname, O_RDONLY | O_CLOEXEC)) == -1) {
break;
}
gsize length;
Expand Down
3 changes: 2 additions & 1 deletion libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/utils/format.hpp"
#include "libdnf5/utils/locker.hpp"

#include <fcntl.h>
#include <fmt/format.h>
#include <unistd.h>

Expand Down Expand Up @@ -1081,7 +1082,7 @@ Transaction::TransactionRunResult Transaction::Impl::_run(
#endif

int pipe_out_from_scriptlets[2];
if (pipe(pipe_out_from_scriptlets) == -1) {
if (pipe2(pipe_out_from_scriptlets, O_CLOEXEC) == -1) {
logger->error("Transaction::Run: Cannot create pipe: {}", std::strerror(errno));
return TransactionRunResult::ERROR_RPM_RUN;
}
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/rpm/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ bool Package::is_available_locally() const {

bool Package::is_cached() const {
gboolean cached{FALSE};
if (auto fd = ::open(get_package_path().c_str(), O_RDONLY); fd != -1) {
if (auto fd = ::open(get_package_path().c_str(), O_RDONLY | O_CLOEXEC); fd != -1) {
utils::OnScopeExit close_fd([fd]() noexcept { ::close(fd); });
auto length = static_cast<unsigned long long>(lseek(fd, 0, SEEK_END));
if (length == get_download_size()) {
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/utils/locker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool Locker::write_lock() {
}

bool Locker::lock(short int type) {
lock_fd = open(path.c_str(), O_CREAT | O_RDWR, 0660);
lock_fd = open(path.c_str(), O_CREAT | O_RDWR | O_CLOEXEC, 0660);
if (lock_fd == -1) {
throw SystemError(errno, M_("Failed to open lock file \"{}\""), path);
}
Expand Down