std::shared_ptr
[dcpomatic.git] / src / lib / cross_linux.cc
index 95bd975f8bdad0063f43c2d508271c93f231a741..247bf4aabc3f6addcffb7d821a483c467de273d9 100644 (file)
@@ -57,7 +57,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 +99,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 +268,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 ()
@@ -397,16 +373,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 +409,8 @@ disk_write_finished ()
 
 }
 
+string
+dcpomatic::get_process_id ()
+{
+       return dcp::raw_convert<string>(getpid());
+}