From f514b435c49bf9167ed4f5a96bd004d27e7d5e2c Mon Sep 17 00:00:00 2001 From: pcg Date: Wed, 17 Mar 2004 05:15:02 +0000 Subject: [PATCH] *** empty log message *** --- src/misc.C | 60 ++++++++++++++++++++++++++++++++++++++++++++---- src/rxvt.C | 25 ++++++++++++-------- src/rxvtc.C | 25 ++++++++++++++++++++ src/rxvtd.C | 35 ++++++++++++++++++++++++---- src/rxvtdaemon.C | 2 +- 5 files changed, 129 insertions(+), 18 deletions(-) diff --git a/src/misc.C b/src/misc.C index 3f04220e..f11227d9 100644 --- a/src/misc.C +++ b/src/misc.C @@ -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 * diff --git a/src/rxvt.C b/src/rxvt.C index cc5c4dff..68bc1d5d 100644 --- a/src/rxvt.C +++ b/src/rxvt.C @@ -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; + } diff --git a/src/rxvtc.C b/src/rxvtc.C index 00b9ef2d..fa0bbe2b 100644 --- a/src/rxvtc.C +++ b/src/rxvtc.C @@ -1,3 +1,4 @@ +#include "../config.h" #include "rxvtdaemon.h" #include @@ -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; } diff --git a/src/rxvtd.C b/src/rxvtd.C index 4be63aef..dbb2051c 100644 --- a/src/rxvtd.C +++ b/src/rxvtd.C @@ -19,10 +19,14 @@ 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 diff --git a/src/rxvtdaemon.C b/src/rxvtdaemon.C index cd8f030b..a9cb7856 100644 --- a/src/rxvtdaemon.C +++ b/src/rxvtdaemon.C @@ -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); } -- 2.34.1