Skip to content

Commit

Permalink
wait until encrypted drive become available
Browse files Browse the repository at this point in the history
Signed-off-by: Tolga Cakir <[email protected]>
  • Loading branch information
tolga9009 committed Jun 9, 2016
1 parent 2fb4bbb commit e8fe20f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 13 additions & 3 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* MIT License. For more information, see LICENSE file.
*/

#include <chrono>
#include <csignal>
#include <iostream>
#include <thread>

#include <fcntl.h>
#include <unistd.h>
Expand All @@ -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<bool> Process::isActive_;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e8fe20f

Please sign in to comment.