some fixes for socket & fifo. fifo is still broken though
authorDieter Plaetinck <dieter@plaetinck.be>
Sat, 2 May 2009 20:55:14 +0000 (22:55 +0200)
committerDieter Plaetinck <dieter@plaetinck.be>
Sat, 2 May 2009 20:55:14 +0000 (22:55 +0200)
uzbl.c

diff --git a/uzbl.c b/uzbl.c
index ca4f733..b9e7876 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -503,15 +503,24 @@ control_fifo(GIOChannel *fd) {
 static void
 create_fifo() {
     GIOChannel *chan = NULL;
+    GError *error = NULL;
 
     build_stream_name(FIFO);
-    printf ("Control fifo opened in %s\n", fifo_path);
-    if (mkfifo (fifo_path, 0666) == -1) {
-        printf ("Possible error creating fifo\n");
+    if (file_exists(fifo_path)) {
+        printf ("Fifo: disabled.  Error when creating %s: File exists\n", fifo_path);
+        return;
+    }
+    if (mkfifo (fifo_path, 0666) == -1) { //TODO: mkfifo blocks (waits for writer)
+        printf ("Fifo: disabled.  Error when creating %s: %s\n", fifo_path, strerror(errno));
+    } else {
+        chan = g_io_channel_new_file((gchar *) fifo_path, "r", &error);
+        if (chan) {
+            printf ("Fifo: created successfully as %s\n", fifo_path);
+            g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, chan);
+        } else {
+            g_error ("Fifo: error while opening: %s\n", error->message);
+        }
     }
-
-    if( (chan = g_io_channel_new_file((gchar *) fifo_path, "r+", NULL)) )
-        g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, chan);
     return;
 }
 
@@ -586,16 +595,14 @@ create_socket() {
     bind (sock, (struct sockaddr *) &local, len);
 
     if (errno == -1) {
-        printf ("Socket: Could not open in %s\n", socket_path);
+        printf ("Socket: Could not open in %s: %s\n", socket_path, strerror(errno));
     } else {
         printf ("Socket: Opened in %s\n", socket_path);
-    }
-
-    listen (sock, 5);
+        listen (sock, 5);
 
-    if( (chan = g_io_channel_unix_new(sock)) )
-        g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_socket, chan);
+        if( (chan = g_io_channel_unix_new(sock)) )
+            g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_socket, chan);
+    }
 }
 
 static void