summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kms++/inc/kms++/card.h1
-rw-r--r--kms++/src/card.cpp14
2 files changed, 15 insertions, 0 deletions
diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
index e561ffc..9ca06b2 100644
--- a/kms++/inc/kms++/card.h
+++ b/kms++/inc/kms++/card.h
@@ -26,6 +26,7 @@ class Card
public:
Card(const std::string& dev_path = "");
Card(const std::string& driver, uint32_t idx);
+ Card(int fd, bool take_ownership);
virtual ~Card();
Card(const Card& other) = delete;
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 5b3d69e..062645a 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -148,6 +148,20 @@ Card::Card(const std::string& driver, uint32_t idx)
setup();
}
+Card::Card(int fd, bool take_ownership)
+{
+ if (take_ownership) {
+ m_fd = fd;
+ } else {
+ m_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+
+ if (m_fd < 0)
+ throw invalid_argument(string(strerror(errno)) + " duplicating fd");
+ }
+
+ setup();
+}
+
void Card::setup()
{
drmVersionPtr ver = drmGetVersion(m_fd);