File descriptor fixes for XDPOpenWithDialog

- Open it with O_CLOEXEC
- Remove unneseccary std::array complication
- Rely on Gio::UnixFDList to close it
This commit is contained in:
Ilya Fedin 2024-06-03 17:47:00 +04:00 committed by John Preston
parent a6fcc6d51d
commit 88e742927f
2 changed files with 4 additions and 5 deletions

View file

@ -44,14 +44,12 @@ bool UnsafeShowOpenWith(const QString &filepath) {
const auto fd = open(
QFile::encodeName(filepath).constData(),
O_RDONLY);
O_RDONLY | O_CLOEXEC);
if (fd == -1) {
return false;
}
const auto fdGuard = gsl::finally([&] { close(fd); });
const auto handleToken = "tdesktop"
+ std::to_string(base::RandomValue<uint>());
@ -73,6 +71,7 @@ bool UnsafeShowOpenWith(const QString &filepath) {
nullptr));
if (!request) {
close(fd);
return false;
}
@ -107,7 +106,7 @@ bool UnsafeShowOpenWith(const QString &filepath) {
GLib::Variant::new_variant(
GLib::Variant::new_boolean(true))),
}),
Gio::UnixFDList::new_from_array((std::array{ fd }).data(), 1),
Gio::UnixFDList::new_from_array(&fd, 1),
nullptr);
if (!result) {

@ -1 +1 @@
Subproject commit e2c62ef0b4581d84e4ff79623a7e5e9ed315bad7
Subproject commit 4d56f8b4bba52b46844f46fafa5f9b6b2704429e