X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcross_linux.cc;h=c001cbf353fab9129ba9d5b9bf79b0f5d155c196;hb=a5d004b0773f633401528392fc28e66d70e13ac8;hp=95bd975f8bdad0063f43c2d508271c93f231a741;hpb=4c804a0d92ebd03b70bfc7f736fcaf5f77cb3bb7;p=dcpomatic.git diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index 95bd975f8..c001cbf35 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -31,7 +31,6 @@ extern "C" { #include } #include -#include #include #if BOOST_VERSION >= 106100 #include @@ -57,7 +56,7 @@ using std::vector; using std::cerr; using std::cout; using std::runtime_error; -using boost::shared_ptr; +using std::shared_ptr; using boost::optional; using boost::function; @@ -99,27 +98,26 @@ cpu_info () } boost::filesystem::path -shared_path () +resources_path () { - char const * p = getenv ("DCPOMATIC_LINUX_SHARE_PREFIX"); - if (p) { - return boost::filesystem::path(p) / "dcpomatic2"; - } - return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "dcpomatic2"; + return directory_containing_executable().parent_path() / "share" / "dcpomatic2"; } boost::filesystem::path xsd_path () { - char const * p = getenv ("DCPOMATIC_LINUX_SHARE_PREFIX"); - if (p) { - return boost::filesystem::path(p) / "libdcp" / "xsd"; - } return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "xsd"; } +boost::filesystem::path +tags_path () +{ + return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "tags"; +} + + void run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) { @@ -269,29 +267,6 @@ home_directory () return getenv("HOME"); } -string -command_and_read (string cmd) -{ - FILE* pipe = popen (cmd.c_str(), "r"); - if (!pipe) { - throw runtime_error ("popen failed"); - } - - string result; - char buffer[128]; - try { - while (fgets(buffer, sizeof(buffer), pipe)) { - result += buffer; - } - } catch (...) { - pclose (pipe); - throw; - } - - pclose (pipe); - return result; -} - /** @return true if this process is a 32-bit one running on a 64-bit-capable OS */ bool running_32_on_64 () @@ -374,7 +349,7 @@ Drive::get () bool Drive::unmount () { - BOOST_FOREACH (boost::filesystem::path i, _mount_points) { + for (auto i: _mount_points) { int const r = umount(i.string().c_str()); LOG_DISK("Tried to unmount %1 and got %2 and %3", i.string(), r, errno); if (r == -1) { @@ -397,16 +372,23 @@ unprivileged () } } + +bool PrivilegeEscalator::test = false; + PrivilegeEscalator::~PrivilegeEscalator () { - unprivileged (); + if (!test) { + unprivileged (); + } } PrivilegeEscalator::PrivilegeEscalator () { - int const r = seteuid(0); - if (r < 0) { - throw PrivilegeError (String::compose("seteuid() call failed with %1", errno)); + if (!test) { + int const r = seteuid(0); + if (r < 0) { + throw PrivilegeError (String::compose("seteuid() call failed with %1", errno)); + } } } @@ -426,3 +408,8 @@ disk_write_finished () } +string +dcpomatic::get_process_id () +{ + return dcp::raw_convert(getpid()); +}