*/
/* 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
*
-#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;
+ }
+#include "../config.h"
#include "rxvtdaemon.h"
#include <cstdio>
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;
}
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);
new server (fd2);
}
+void server::log_msg (const char *msg)
+{
+ send ("MSG"), send (msg);
+}
+
void server::err (const char *format, ...)
{
if (format)
vsnprintf (err, 1024, format, ap);
va_end (ap);
- send ("ERR"), send (err);
+ send ("MSG"), send (err);
}
+ send ("END", 0);
close (fd);
delete this;
}
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
{
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);
}