-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule aosp_fd_utils
added at
303bcb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "fd_reopener.hpp" | ||
#include <fd_utils.h> | ||
#include <string> | ||
#include <utility> | ||
#include "logging.hpp" | ||
|
||
FDReopener::ScopedRegularReopener::ScopedRegularReopener() | ||
{ | ||
auto pFdSet = GetOpenFds([](const std::string &error) | ||
{ LOGE("GetOpenFds: %s", error.c_str()); }); | ||
if (pFdSet) | ||
{ | ||
for (const auto &fd : *pFdSet) | ||
{ | ||
auto pFDI = FileDescriptorInfo::CreateFromFd(fd, [fd](const std::string &error) | ||
{ LOGE("CreateFromFd(%d): %s", fd, error.c_str()); }); | ||
|
||
// Only process regular files that are not memfds | ||
if (pFDI && !pFDI->is_sock && !pFDI->file_path.starts_with("/memfd:")) | ||
fdi_vector.emplace_back(std::move(pFDI)); | ||
} | ||
} | ||
} | ||
|
||
FDReopener::ScopedRegularReopener::~ScopedRegularReopener() | ||
{ | ||
for (const auto &pFDI : fdi_vector) | ||
{ | ||
LOGD("Reopening FD %d with %s", pFDI->fd, pFDI->file_path.c_str()); | ||
pFDI->ReopenOrDetach([fd = pFDI->fd](const std::string &error) | ||
{ LOGE("ReopenOrDetach(%d): %s", fd, error.c_str()); }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#include "fd_utils.h" | ||
#include <vector> | ||
#include <memory> | ||
|
||
namespace FDReopener | ||
{ | ||
class ScopedRegularReopener | ||
{ | ||
public: | ||
ScopedRegularReopener(); | ||
~ScopedRegularReopener(); | ||
|
||
private: | ||
ScopedRegularReopener(const ScopedRegularReopener &); | ||
void operator=(const ScopedRegularReopener &); | ||
std::vector<std::unique_ptr<FileDescriptorInfo>> fdi_vector; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters