[rygel/rygel-0-28] media-export: Remove Unix signal handling



commit 73d63d103983381679fdce0d4f88613b243e24f7
Author: Jens Georg <mail jensge org>
Date:   Fri Feb 12 23:03:33 2016 +0100

    media-export: Remove Unix signal handling
    
    Propagating the URI didn't work and we have the knowledge in MetadataExtractor
    anyway, no need to things with signal handlers and writing things to fd's.
    
    Signed-off-by: Jens Georg <mail jensge org>

 .../media-export/rygel-media-export-extract.vala   |   33 +-------------------
 .../rygel-media-export-metadata-extractor.vala     |   33 +-------------------
 2 files changed, 2 insertions(+), 64 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-extract.vala 
b/src/plugins/media-export/rygel-media-export-extract.vala
index 2ff25da..09cc74b 100644
--- a/src/plugins/media-export/rygel-media-export-extract.vala
+++ b/src/plugins/media-export/rygel-media-export-extract.vala
@@ -24,11 +24,6 @@ using Gst.PbUtils;
 using GUPnPDLNA;
 using Gst;
 
-struct UriBuffer {
-    uint8 data[4096];
-    size_t length;
-}
-
 const string UPNP_CLASS_PHOTO = "object.item.imageItem.photo";
 const string UPNP_CLASS_MUSIC = "object.item.audioItem.musicTrack";
 const string UPNP_CLASS_VIDEO = "object.item.videoItem";
@@ -37,22 +32,16 @@ const string UPNP_CLASS_PLAYLIST = "object.item.playlistItem";
 const string STATUS_LINE_TEMPLATE = "RESULT|%s|%" + size_t.FORMAT + "|%s\n";
 const string ERROR_LINE_TEMPLATE = "ERROR|%s|%d|%s\n";
 
-const string FATAL_ERROR_PREFIX = "FATAL_ERROR|";
-const string FATAL_ERROR_SUFFIX = "\n"; //|0|Killed by signal\n";
-
 static int in_fd = 0;
 static int out_fd = 1;
-static int err_fd = 2;
 static bool metadata = false;
 static MainLoop loop;
 static DataInputStream input_stream;
 static OutputStream output_stream;
-static OutputStream error_stream;
 static Rygel.InfoSerializer serializer;
 static MediaArt.Process media_art;
 static Discoverer discoverer;
 static ProfileGuesser guesser;
-static UriBuffer last_uri;
 
 public errordomain MetadataExtractorError {
     GENERAL
@@ -61,20 +50,11 @@ public errordomain MetadataExtractorError {
 static const OptionEntry[] options = {
     { "input-fd", 'i', 0, OptionArg.INT, ref in_fd, "File descriptor used for input", null },
     { "output-fd", 'o', 0, OptionArg.INT, ref out_fd, "File descriptor used for output", null },
-    { "error-fd", 'e', 0, OptionArg.INT, ref err_fd, "File descriptor used for severe errors", null },
     { "extract-metadata", 'm', 0, OptionArg.NONE, ref metadata,
         "Whether to extract all metadata from the files or just basic information", null },
     { null }
 };
 
-static void segv_handler (int signal) {
-    Posix.write (err_fd, (void *) last_uri.data, last_uri.length);
-    Posix.write (err_fd, (void *) FATAL_ERROR_SUFFIX, 1);
-    Posix.fsync (err_fd);
-
-    Posix.exit(-1);
-}
-
 async void run () {
     while (true) {
         try {
@@ -96,11 +76,6 @@ async void run () {
                 try {
                     // Copy current URI to statically allocated memory area to
                     // dump to fd in the signal handler
-                    last_uri.length = parts[0].length;
-                    GLib.Memory.set (last_uri.data, 0, 4096);
-                    GLib.Memory.copy (last_uri.data,
-                                      (void *) parts[0],
-                                      parts[0].length);
                     var is_text = parts[1].has_prefix ("text/") ||
                                   parts[1].has_suffix ("xml");
                     if (metadata && !is_text) {
@@ -241,16 +216,10 @@ int main (string[] args) {
     serializer = new Rygel.InfoSerializer (media_art);
     Posix.nice (19);
 
-    var action = new Posix.sigaction_t ();
-    action.sa_handler = segv_handler;
-    Posix.sigaction (Posix.SIGSEGV, action, null);
-    Posix.sigaction (Posix.SIGABRT, action, null);
-
-    message ("Started with descriptors %d %d %d", in_fd, out_fd, err_fd);
+    message ("Started with descriptors %d (in) %d (out)", in_fd, out_fd);
 
     input_stream = new DataInputStream (new UnixInputStream (in_fd, true));
     output_stream = new UnixOutputStream (out_fd, true);
-    error_stream = new UnixOutputStream (err_fd, true);
 
     loop = new MainLoop ();
     try {
diff --git a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala 
b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
index 68cc398..28f7e7d 100644
--- a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
@@ -59,9 +59,6 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     /// Stream for receiving normal input from the child
     private DataInputStream output_stream;
 
-    /// Stream for receiving exception events from the child
-    private DataInputStream error_stream;
-
     /// Cancellable for cancelling child I/O
     private Cancellable child_io_cancellable;
 
@@ -93,7 +90,6 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
         MX_EXTRACT_PATH,
         "--input-fd=3",
         "--output-fd=4",
-        "--error-fd=5",
         "--extract-metadata",
         null
     };
@@ -118,7 +114,6 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
 
         int[] pipe_in = { 0, 0 };
         int[] pipe_out = { 0, 0 };
-        int[] pipe_err = { 0, 0 };
 
         bool restart = false;
         do {
@@ -126,30 +121,21 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
             try {
                 open_pipe (pipe_in, Posix.FD_CLOEXEC);
                 open_pipe (pipe_out, Posix.FD_CLOEXEC);
-                open_pipe (pipe_err, Posix.FD_CLOEXEC);
 
                 this.launcher = new SubprocessLauncher (SubprocessFlags.NONE);
                 this.launcher.take_fd (pipe_in[0], 3);
                 this.launcher.take_fd (pipe_out[1], 4);
-                this.launcher.take_fd (pipe_err[1], 5);
 
                 this.input_stream = new UnixOutputStream (pipe_in[1], true);
                 this.output_stream = new DataInputStream (
                                                 new UnixInputStream (pipe_out[0],
                                                                      true));
-                this.error_stream = new DataInputStream (
-                                                new UnixInputStream (pipe_err[0],
-                                                                     true));
-
                 this.child_io_cancellable = new Cancellable ();
 
                 this.output_stream.read_line_async.begin (Priority.DEFAULT,
                                                           this.child_io_cancellable,
                                                           this.on_input);
                 this.error_uri = null;
-                this.error_stream.read_line_async.begin (Priority.DEFAULT,
-                                                         this.child_io_cancellable,
-                                                         this.on_child_error);
 
                 if (this.extract_metadata) {
                     MX_EXTRACT_ARGV[4] = "--extract-metadata";
@@ -183,24 +169,6 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
         debug ("Metadata extractor finished.");
     }
 
-    private void on_child_error (GLib.Object? object, AsyncResult result) {
-        var stream = object as DataInputStream;
-        if (stream != null) {
-            try {
-                this.error_uri = stream.read_line_async.end (result);
-                warning (_("Child failed fatally. Last uri was %s"),
-                         this.error_uri);
-            } catch (Error error) {
-                if (error is IOError.CANCELLED) {
-                    debug ("Reading was cancelled...");
-                } else {
-                    warning (_("Reading from child's error stream failed: %s"),
-                             error.message);
-                }
-            }
-        }
-    }
-
     private void on_input (GLib.Object? object, AsyncResult result) {
         try {
             var stream = object as DataInputStream;
@@ -283,6 +251,7 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
             return;
         }
 
+        this.error_uri = file.get_uri ();
         var s = "EXTRACT %s|%s\n".printf (file.get_uri (), content_type);
         try {
             this.input_stream.write_all (s.data, null, this.child_io_cancellable);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]