summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrhp <rhp>2001-06-13 05:29:14 +0000
committerrhp <rhp>2001-06-13 05:29:14 +0000
commited4225fd52a28920975240b288614b4a2c8b70f1 (patch)
treec4aa60c63dddebcc37dd1170eaa38fb3d4975c37 /src
parentd5914732d203b6905830a5ae500825f7e1fb3b46 (diff)
downloadmetacity-ed4225fd52a28920975240b288614b4a2c8b70f1.tar.gz
metacity-ed4225fd52a28920975240b288614b4a2c8b70f1.tar.bz2
...
Diffstat (limited to 'src')
-rw-r--r--src/uislave.c105
-rw-r--r--src/uislave.h5
-rw-r--r--src/uislave/messagequeue.c22
-rw-r--r--src/uislave/messagequeue.h3
-rw-r--r--src/uislave/messages.c13
-rw-r--r--src/uislave/messages.h3
6 files changed, 58 insertions, 93 deletions
diff --git a/src/uislave.c b/src/uislave.c
index 2e987ad..2f43fc4 100644
--- a/src/uislave.c
+++ b/src/uislave.c
@@ -29,9 +29,6 @@
#include <fcntl.h>
static void respawn_child (MetaUISlave *uislave);
-static gboolean error_callback (GIOChannel *source,
- GIOCondition condition,
- gpointer data);
static void kill_child (MetaUISlave *uislave);
static void reset_vals (MetaUISlave *uislave);
static void message_queue_func (MetaMessageQueue *mq,
@@ -52,6 +49,7 @@ meta_ui_slave_new (const char *display_name,
uislave->func = func;
uislave->data = data;
uislave->no_respawn = FALSE;
+ uislave->serial = 1;
reset_vals (uislave);
@@ -137,6 +135,7 @@ respawn_child (MetaUISlave *uislave)
argv[2] = "uislave-strace.log";
#endif
argv[0] = path;
+ argv[1] = "--sync";
meta_verbose ("Launching UI slave in dir %s display %s\n",
uislavedir, disp);
@@ -149,21 +148,14 @@ respawn_child (MetaUISlave *uislave)
0,
child_setup, disp,
&child_pid,
- &inpipe, &outpipe, &errpipe,
+ &inpipe, &outpipe, NULL,
&error))
{
+ errpipe = -1;
uislave->child_pid = child_pid;
uislave->in_pipe = inpipe;
- uislave->err_pipe = errpipe;
uislave->out_pipe = outpipe;
- uislave->err_channel = g_io_channel_unix_new (errpipe);
-
- uislave->errwatch = g_io_add_watch (uislave->err_channel,
- G_IO_IN,
- error_callback,
- uislave);
-
uislave->mq = meta_message_queue_new (outpipe,
message_queue_func,
uislave);
@@ -181,75 +173,23 @@ respawn_child (MetaUISlave *uislave)
g_free (path);
}
-static gboolean
-error_callback (GIOChannel *source,
- GIOCondition condition,
- gpointer data)
-{
- /* Relay slave errors to WM stderr */
-#define BUFSIZE 1024
- MetaUISlave *uislave;
- char buf[1024];
- int n;
- static int logfile = -1;
-
- if (meta_is_debugging () && logfile < 0)
- {
- const char *dir;
- char *str;
-
- dir = g_get_home_dir ();
- str = g_strconcat (dir, "/", "metacity-uislave.log", NULL);
-
- logfile = open (str, O_TRUNC | O_CREAT, 0644);
-
- if (logfile < 0)
- meta_warning ("Failed to open uislave log file %s\n", str);
- else
- meta_verbose ("Opened uislave log file %s\n", str);
-
- g_free (str);
- }
-
- if (logfile < 0)
- logfile = 2;
-
- uislave = data;
-
- n = read (uislave->err_pipe, buf, BUFSIZE);
- if (n > 0)
- {
- if (write (logfile, buf, n) != n)
- ; /* error, but printing a message to stderr will hardly help. */
- }
- else if (n < 0)
- meta_warning (_("Error reading errors from UI slave: %s\n"),
- g_strerror (errno));
-
- return TRUE;
-#undef BUFSIZE
-}
-
static void
kill_child (MetaUISlave *uislave)
{
if (uislave->mq)
meta_message_queue_free (uislave->mq);
- if (uislave->errwatch != 0)
- g_source_remove (uislave->errwatch);
-
- if (uislave->err_channel)
- g_io_channel_unref (uislave->err_channel);
-
if (uislave->out_pipe >= 0)
- close (uislave->out_pipe);
+ {
+ meta_verbose ("Closing UI child output pipe\n");
+ close (uislave->out_pipe);
+ }
if (uislave->in_pipe >= 0)
- close (uislave->in_pipe);
-
- if (uislave->err_pipe >= 0)
- close (uislave->err_pipe);
+ {
+ meta_verbose ("Closing UI child input pipe\n");
+ close (uislave->in_pipe);
+ }
if (uislave->child_pid > 0)
{
@@ -272,10 +212,7 @@ reset_vals (MetaUISlave *uislave)
uislave->mq = NULL;
uislave->child_pid = 0;
uislave->in_pipe = -1;
- uislave->err_pipe = -1;
uislave->out_pipe = -1;
- uislave->err_channel = NULL;
- uislave->errwatch = 0;
/* don't reset no_respawn, it's a permanent thing. */
}
@@ -310,9 +247,9 @@ write_bytes (int fd, void *buf, int bytes)
}
static void
-send_message (MetaUISlave *uislave, MetaMessage *message)
+send_message (MetaUISlave *uislave, MetaMessage *message,
+ int request_serial)
{
- static int serial = 0;
MetaMessageFooter *footer;
if (uislave->no_respawn)
@@ -320,11 +257,13 @@ send_message (MetaUISlave *uislave, MetaMessage *message)
respawn_child (uislave);
- message->header.serial = serial;
+ message->header.serial = uislave->serial;
+ message->header.request_serial = request_serial;
+
footer = META_MESSAGE_FOOTER (message);
footer->checksum = META_MESSAGE_CHECKSUM (message);
- ++serial;
+ uislave->serial += 1;
if (write_bytes (uislave->in_pipe,
META_MESSAGE_ESCAPE, META_MESSAGE_ESCAPE_LEN) < 0)
@@ -359,7 +298,7 @@ meta_ui_slave_show_tip (MetaUISlave *uislave,
strncpy (showtip.markup, markup_text, META_MESSAGE_MAX_TIP_LEN);
showtip.markup[META_MESSAGE_MAX_TIP_LEN] = '\0';
- send_message (uislave, (MetaMessage*)&showtip);
+ send_message (uislave, (MetaMessage*)&showtip, 0);
}
void
@@ -371,7 +310,7 @@ meta_ui_slave_hide_tip (MetaUISlave *uislave)
hidetip.header.message_code = MetaMessageHideTipCode;
hidetip.header.length = META_MESSAGE_LENGTH (MetaMessageHideTip);
- send_message (uislave, (MetaMessage*)&hidetip);
+ send_message (uislave, (MetaMessage*)&hidetip, 0);
}
void
@@ -398,7 +337,7 @@ meta_ui_slave_show_window_menu (MetaUISlave *uislave,
showmenu.insensitive = insensitive;
showmenu.timestamp = timestamp;
- send_message (uislave, (MetaMessage*)&showmenu);
+ send_message (uislave, (MetaMessage*)&showmenu, 0);
}
void
@@ -410,5 +349,5 @@ meta_ui_slave_hide_window_menu (MetaUISlave *uislave)
hidemenu.header.message_code = MetaMessageHideWindowMenuCode;
hidemenu.header.length = META_MESSAGE_LENGTH (MetaMessageHideWindowMenu);
- send_message (uislave, (MetaMessage*)&hidemenu);
+ send_message (uislave, (MetaMessage*)&hidemenu, 0);
}
diff --git a/src/uislave.h b/src/uislave.h
index c585292..3ea15ea 100644
--- a/src/uislave.h
+++ b/src/uislave.h
@@ -37,14 +37,13 @@ struct _MetaUISlave
int child_pid;
int in_pipe;
int out_pipe;
- int err_pipe;
- GIOChannel *err_channel;
- unsigned int errwatch;
MetaMessageQueue *mq;
MetaUISlaveFunc func;
gpointer data;
+
+ int serial;
/* if we determine that our available slave is hosed,
* set this bit.
diff --git a/src/uislave/messagequeue.c b/src/uislave/messagequeue.c
index ee20b8c..73bcc29 100644
--- a/src/uislave/messagequeue.c
+++ b/src/uislave/messagequeue.c
@@ -360,7 +360,6 @@ mq_prepare (GSource *source, gint *timeout)
return mq_messages_pending (mq);
}
-#include <stdio.h>
static gboolean
mq_check (GSource *source)
{
@@ -383,7 +382,12 @@ mq_check (GSource *source)
mq->buf->len);
break;
case READ_EOF:
+#ifdef METACITY_COMPILE
meta_verbose ("EOF reading stdout from slave process\n");
+#else
+ meta_ui_warning ("Metacity parent process disappeared\n");
+ exit (1);
+#endif
break;
case READ_FAILED:
@@ -391,6 +395,17 @@ mq_check (GSource *source)
break;
}
}
+
+
+ if (mq->out_poll.revents & G_IO_HUP)
+ {
+#ifdef METACITY_COMPILE
+ meta_verbose ("UI slave hung up\n");
+#else
+ meta_ui_warning ("Metacity parent process hung up\n");
+ exit (1);
+#endif
+ }
mq->out_poll.revents = 0;
@@ -529,7 +544,12 @@ meta_message_queue_wait_for_reply (MetaMessageQueue *mq,
break;
case READ_EOF:
+#ifdef METACITY_COMPILE
meta_verbose ("EOF reading stdout from slave process\n");
+#else
+ meta_ui_warning ("Metacity parent process disappeared\n");
+ exit (1);
+#endif
return;
break;
diff --git a/src/uislave/messagequeue.h b/src/uislave/messagequeue.h
index 763716f..a3c9cd9 100644
--- a/src/uislave/messagequeue.h
+++ b/src/uislave/messagequeue.h
@@ -41,4 +41,7 @@ MetaMessageQueue* meta_message_queue_new (int fd,
gpointer data);
void meta_message_queue_free (MetaMessageQueue *mq);
+void meta_message_queue_wait_for_reply (MetaMessageQueue *mq,
+ int serial_of_request);
+
#endif
diff --git a/src/uislave/messages.c b/src/uislave/messages.c
index fe3eb16..ff975e5 100644
--- a/src/uislave/messages.c
+++ b/src/uislave/messages.c
@@ -40,7 +40,8 @@ typedef enum
static ReadResult read_data (GString *str,
gint fd);
-static void send_message (MetaMessage *message);
+static void send_message (MetaMessage *message,
+ int request_serial);
void
meta_message_send_check (void)
@@ -58,8 +59,8 @@ meta_message_send_check (void)
check.host_alias[META_MESSAGE_MAX_HOST_ALIAS_LEN] = '\0';
check.messages_version = META_MESSAGES_VERSION;
-
- send_message ((MetaMessage*)&check);
+
+ send_message ((MetaMessage*)&check, 0);
}
static int
@@ -113,12 +114,14 @@ print_mem (int fd, void *mem, int len)
#endif
static void
-send_message (MetaMessage *message)
+send_message (MetaMessage *message,
+ int request_serial)
{
- static int serial = 0;
+ static int serial = 1;
MetaMessageFooter *footer;
message->header.serial = serial;
+ message->header.request_serial = request_serial;
footer = META_MESSAGE_FOOTER (message);
footer->checksum = META_MESSAGE_CHECKSUM (message);
diff --git a/src/uislave/messages.h b/src/uislave/messages.h
index f9a2149..def4b9f 100644
--- a/src/uislave/messages.h
+++ b/src/uislave/messages.h
@@ -36,7 +36,7 @@
/* We increment this when we change this header, so we can
* check for mismatched UI slave and WM
*/
-#define META_MESSAGES_VERSION 1
+#define META_MESSAGES_VERSION 2
/* We have an escape sequence, just in case some part of GTK
* decides to write to stdout, so that we have a good chance
@@ -87,6 +87,7 @@ struct _MetaMessageHeader
MetaMessageCode message_code;
int length;
int serial;
+ int request_serial; /* 0 if none */
};
/* The footer thing was pretty much just a debug hack and could die. */