Add some possibly-useful markers for debugging threads from coredumps.
[dcpomatic.git] / src / lib / cross_linux.cc
index 0f31c108cda69327f5c7e3a7c2d999afe14aebb7..7e026b9a67032971daf0299890c458ebe8c54794 100644 (file)
@@ -31,7 +31,6 @@ extern "C" {
 #include <libavformat/avio.h>
 }
 #include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
 #include <boost/function.hpp>
 #if BOOST_VERSION >= 106100
 #include <boost/dll/runtime_symbol_info.hpp>
@@ -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;
 
@@ -101,11 +100,6 @@ cpu_info ()
 boost::filesystem::path
 resources_path ()
 {
-       char* prefix = getenv ("DCPOMATIC_SHARE_PREFIX");
-       if (prefix) {
-               return boost::filesystem::path(prefix) / "dcpomatic2";
-       }
-
        return directory_containing_executable().parent_path() / "share" / "dcpomatic2";
 }
 
@@ -113,6 +107,9 @@ resources_path ()
 boost::filesystem::path
 xsd_path ()
 {
+       if (auto appdir = getenv("APPDIR")) {
+               return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp" / "xsd";
+       }
        return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "xsd";
 }
 
@@ -120,6 +117,9 @@ xsd_path ()
 boost::filesystem::path
 tags_path ()
 {
+       if (auto appdir = getenv("APPDIR")) {
+               return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp" / "tags";
+       }
        return boost::filesystem::canonical(LINUX_SHARE_PREFIX) / "libdcp" / "tags";
 }
 
@@ -273,29 +273,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 ()
@@ -378,7 +355,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) {
@@ -401,16 +378,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));
+               }
        }
 }
 
@@ -430,3 +414,8 @@ disk_write_finished ()
 
 }
 
+string
+dcpomatic::get_process_id ()
+{
+       return dcp::raw_convert<string>(getpid());
+}