*** empty log message ***
authorpcg <pcg>
Wed, 17 Mar 2004 05:15:02 +0000 (05:15 +0000)
committerpcg <pcg>
Wed, 17 Mar 2004 05:15:02 +0000 (05:15 +0000)
src/misc.C
src/rxvt.C
src/rxvtc.C
src/rxvtd.C
src/rxvtdaemon.C

index 3f04220efc4b1a9451b8adeb9c062043e876b851..f11227d92b19c8a8db544ea88d33fa85ac6d722f 100644 (file)
@@ -70,17 +70,69 @@ rxvt_r_basename (const char *str)
  */
 /* EXTPROTO */
 void
-rxvt_print_error (const char *fmt,...)
+rxvt_vlog (const char *fmt, va_list arg_ptr)
+{
+  char msg[1024];
+
+  vsnprintf (msg, sizeof msg, fmt, arg_ptr);
+
+  if (GET_R && GET_R->log_hook)
+    (*GET_R->log_hook) (msg);
+  else
+    write (STDOUT_FILENO, msg, strlen (msg));
+}
+
+/* EXTPROTO */
+void
+rxvt_log (const char *fmt,...)
+{
+  va_list arg_ptr;
+
+  va_start (arg_ptr, fmt);
+  rxvt_vlog (fmt, arg_ptr);
+  va_end (arg_ptr);
+}
+
+/*
+ * Print an error message
+ */
+/* EXTPROTO */
+void
+rxvt_warn (const char *fmt,...)
 {
   va_list arg_ptr;
 
+  rxvt_log ("%s: ", RESNAME);
+
   va_start (arg_ptr, fmt);
-  fprintf (stderr, RESNAME ": ");
-  vfprintf (stderr, fmt, arg_ptr);
-  fprintf (stderr, "\n");
+  rxvt_vlog (fmt, arg_ptr);
   va_end (arg_ptr);
 }
 
+/* EXTPROTO */
+void
+rxvt_fatal (const char *fmt,...)
+{
+  va_list arg_ptr;
+
+  rxvt_log ("%s: ", RESNAME);
+
+  va_start (arg_ptr, fmt);
+  rxvt_vlog (fmt, arg_ptr);
+  va_end (arg_ptr);
+
+  rxvt_exit_failure ();
+}
+
+class rxvt_failure_exception rxvt_failure_exception;
+
+/* EXTPROTO */
+void
+rxvt_exit_failure ()
+{
+  throw (rxvt_failure_exception);
+}
+
 /*
  * check that the first characters of S1 match S2
  *
index cc5c4dffb26a4cc21e8b4bbc9b2566e77bafe0f5..68bc1d5d3cad2b1b4cf04b1f96d97456b10d4f5f 100644 (file)
@@ -1,17 +1,24 @@
-#include "rxvtlib.h"
-#include "iom.h"
+#include "../config.h"
+#include "rxvt.h"
 
 /*----------------------------------------------------------------------*/
 /* main () */
 int
 main (int argc, const char *const *argv)
-{
-  rxvt_init_signals ();
+try
+  {
+    rxvt_init_signals ();
 
-  if (!rxvt_init (argc, argv))
-    return EXIT_FAILURE;
+    rxvt_term *t = new rxvt_term;
+
+    if (!t->init (argc, argv))
+      return EXIT_FAILURE;
 
-  iom.loop ();
+    iom.loop ();
 
-  return EXIT_SUCCESS;
-}
+    return EXIT_SUCCESS;
+  }
+catch (const class rxvt_failure_exception &e)
+  {
+    return EXIT_FAILURE;
+  }
index 00b9ef2d2f0246e7ca8dff51ecd7ecfadad05081..fa0bbe2ba866fa0e1b159797ae26f2d486f032e7 100644 (file)
@@ -1,3 +1,4 @@
+#include "../config.h"
 #include "rxvtdaemon.h"
 
 #include <cstdio>
@@ -60,5 +61,29 @@ main (int argc, const char *const *argv)
     c.send ("ARG"), c.send (argv[i]);
 
   c.send ("END");
+
+  auto_str tok;
+
+  for (;;)
+    if (!c.recv (tok))
+      {
+        fprintf (stderr, "protocol error: unexpected eof from server.\n");
+        break;
+      }
+    else if (!strcmp (tok, "MSG") && c.recv (tok))
+      fprintf (stderr, "%s", (const char *)tok);
+    else if (!strcmp (tok, "END"))
+      {
+        int success;
+        if (c.recv (success))
+          exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
+      }
+    else
+      {
+        fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok);
+        break;
+      }
+
+  return EXIT_FAILURE;
 }
 
index 4be63aefe8854874de7582421dad67167da09042..dbb2051c4aed3ea221b8aae42a16d94b6a4ed049 100644 (file)
 extern char **environ;
 
 struct server : rxvt_connection {
+  log_callback log_cb;
+
   void read_cb (io_watcher &w, short revents); io_watcher read_ev;
+  void log_msg (const char *msg);
 
   server (int fd)
-  : read_ev (this, &server::read_cb)
+  : read_ev (this, &server::read_cb),
+    log_cb (this, &server::log_msg)
   {
     this->fd = fd;
     read_ev.start (fd, EVENT_READ);
@@ -82,6 +86,11 @@ void unix_listener::accept_cb (io_watcher &w, short revents)
     new server (fd2);
 }
 
+void server::log_msg (const char *msg)
+{
+  send ("MSG"), send (msg);
+}
+
 void server::err (const char *format, ...)
 {
   if (format)
@@ -93,9 +102,10 @@ void server::err (const char *format, ...)
       vsnprintf (err, 1024, format, ap);
       va_end (ap);
 
-      send ("ERR"), send (err);
+      send ("MSG"), send (err);
     }
 
+  send ("END", 0);
   close (fd);
   delete this;
 }
@@ -138,12 +148,29 @@ void server::read_cb (io_watcher &w, short revents)
             char **old_environ = environ;
             environ = envv->begin ();
 
-            rxvt_term *term = rxvt_init (argv->size (), argv->begin ());
-
+            rxvt_term *term = new rxvt_term;
+            
+            term->log_hook = &log_cb;
             term->argv = argv;
             term->envv = envv;
 
+            bool success;
+            
+            try
+              {
+                success = term->init (argv->size (), argv->begin ());
+              }
+            catch (const class rxvt_failure_exception &e)
+              {
+                success = false;
+              }
+
             environ = old_environ;
+
+            if (!success)
+              term->destroy ();
+
+            send ("END"); send (success ? 1 : 0);
           }
         }
       else
index cd8f030b41a9fd3cf2024069abae7fd1a46c65c9..a9cb785672d3bb5c2768b025cca26528775f0ec3 100644 (file)
@@ -77,7 +77,7 @@ void rxvt_connection::send (int data)
 {
   uint8_t s[4];
 
-  s[0] = data >> 24; s[1] = data >> 16; s[0] = data >> 8; s[1] = data;
+  s[0] = data >> 24; s[1] = data >> 16; s[2] = data >> 8; s[3] = data;
 
   write (fd, s, 4);
 }