From e8fe20fa24eb01dd853f9b84ae7b9fc14cab2eae Mon Sep 17 00:00:00 2001 From: Tolga Cakir Date: Thu, 9 Jun 2016 21:55:39 +0200 Subject: [PATCH] wait until encrypted drive become available Signed-off-by: Tolga Cakir --- src/main.cpp | 2 +- src/process.cpp | 16 +++++++++++++--- src/process.hpp | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 75c85ea..9ede206 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) { workdir = config.lookup("workdir").c_str(); } - if (process.createWorkdir(workdir)) { + if (process.createWorkdir(workdir, config.lookup("encrypted_workdir"))) { return EXIT_FAILURE; } diff --git a/src/process.cpp b/src/process.cpp index f55301d..421f6dc 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -5,8 +5,10 @@ * MIT License. For more information, see LICENSE file. */ +#include #include #include +#include #include #include @@ -18,7 +20,8 @@ #include "process.hpp" /* constants */ -constexpr auto version = "0.3.1"; +constexpr auto version = "0.3.1"; +constexpr auto wait = 1; std::atomic Process::isActive_; @@ -123,7 +126,7 @@ void Process::applyUser(std::string user) { seteuid(pw_->pw_uid); } -int Process::createWorkdir(std::string directory) { +int Process::createWorkdir(std::string directory, bool isEncrypted) { if (user_.empty()) { return 1; } @@ -148,11 +151,18 @@ int Process::createWorkdir(std::string directory) { workdir.append(xdgData); } + // wait until encrypted drive becomes available + if (isEncrypted) { + while (access(workdir.c_str(), F_OK)) { + std::this_thread::sleep_for(std::chrono::seconds(wait)); + } + } + workdir.append("/sidewinderd"); mkdir(workdir.c_str(), S_IRWXU); if (chdir(workdir.c_str())) { - std::cerr << "Error accessing working directory." << std::endl; + std::cerr << "Error accessing " << workdir << "." << std::endl; return -1; } diff --git a/src/process.hpp b/src/process.hpp index fd699dc..fdeab5d 100644 --- a/src/process.hpp +++ b/src/process.hpp @@ -23,7 +23,7 @@ class Process { int createPid(std::string pidPath); void destroyPid(); void applyUser(std::string user); - int createWorkdir(std::string directory); + int createWorkdir(std::string directory, bool isEncrypted); void privilege(); void unprivilege(); std::string getVersion();