Try to start _writer on-demand on macOS (#1739).
[dcpomatic.git] / src / tools / dcpomatic_disk_writer.cc
index 3cd286fd8582d5b842ed908afcecc071707cffa3..d5599f25b5af2d15dd65c15fcfe47b9e03d894fa 100644 (file)
@@ -18,6 +18,7 @@
 
 */
 
+#include "lib/version.h"
 #include "lib/disk_writer_messages.h"
 #include "lib/compose.hpp"
 #include "lib/exceptions.h"
@@ -47,6 +48,7 @@ extern "C" {
 extern "C" {
 #include <lwext4/file_dev.h>
 }
+#include <xpc/xpc.h>
 #endif
 
 #ifdef DCPOMATIC_LINUX
@@ -243,7 +245,7 @@ void
 write (boost::filesystem::path dcp_path, string device)
 try
 {
-//     ext4_dmask_set (DEBUG_ALL);
+       ext4_dmask_set (DEBUG_ALL);
 
        /* We rely on static initialization for these */
        static struct ext4_fs fs;
@@ -277,7 +279,6 @@ try
 
        /* XXX: not sure if disk_id matters */
        int r = ext4_mbr_write (bd, &parts, 0);
-
        if (r) {
                throw CopyError ("Failed to write MBR", r);
        }
@@ -439,7 +440,7 @@ try
                /* Do some basic sanity checks; this is a bit belt-and-braces but it can't hurt... */
 
 #ifdef DCPOMATIC_OSX
-               if (!starts_with(*device, "/dev/rdisk")) {
+               if (!starts_with(*device, "/dev/disk")) {
                        LOG_DISK ("Will not write to %1", *device);
                        nanomsg->send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
                        return true;
@@ -511,7 +512,7 @@ main ()
         * redirect this to a file in /var/log
         */
        dcpomatic_log.reset(new StdoutLog(LogEntry::TYPE_DISK));
-       LOG_DISK_NC("dcpomatic_disk_writer started");
+       LOG_DISK("dcpomatic_disk_writer %1 started", dcpomatic_git_commit);
 #else
        /* XXX: this is a hack, but I expect we'll need logs and I'm not sure if there's
         * a better place to put them.
@@ -520,6 +521,13 @@ main ()
        LOG_DISK_NC("dcpomatic_disk_writer started");
 #endif
 
+#ifdef DCPOMATIC_OSX
+       /* I *think* this confumes the notifyd event that we used to start the process, so we only
+        * get started once per notification.
+        */
+        xpc_set_event_stream_handler("com.apple.notifyd.matching", DISPATCH_TARGET_QUEUE_DEFAULT, ^(xpc_object_t event) {});
+#endif
+
        try {
                nanomsg = new Nanomsg (false);
        } catch (runtime_error& e) {