-# $Id: Makefile.in,v 1.4 2003-11-26 10:42:34 pcg Exp $
+# $Id: Makefile.in,v 1.5 2003-11-27 10:12:10 pcg Exp $
@MCOMMON@
LINT = lint -DNARROWPROTO=1 $(XINC) -chapbxz
RXVT_BASENAME=`$(ECHO) $(RXVTNAME)|$(SED) 's/$(EXEEXT)$$//'|$(SED) '$(transform)'`
RXVT_BINNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)$(EXEEXT)
RXVT_VERNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)-$(VERSION)$(EXEEXT)
+RXVTC_BINNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)c$(EXEEXT)
+RXVTC_VERNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)c-$(VERSION)$(EXEEXT)
+RXVTD_BINNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)d$(EXEEXT)
+RXVTD_VERNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)d-$(VERSION)$(EXEEXT)
RXVT_OLDNAME=$(DESTDIR)$(bindir)/$(RXVT_BASENAME)-old$(EXEEXT)
EXTPROS = command.extpro defaultfont.extpro graphics.extpro grkelot.extpro \
$(ECHO) "$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) librxvt.la $(DESTDIR)$(libdir)/librxvt.la"; \
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) librxvt.la $(DESTDIR)$(libdir)/librxvt.la; \
fi
- @if test -f $(RXVT_BINNAME); then \
- $(ECHO) "$(RMF) $(RXVT_OLDNAME)"; \
- $(RMF) $(RXVT_OLDNAME); \
- $(ECHO) "$(MV) $(RXVT_BINNAME) $(RXVT_OLDNAME)"; \
- $(MV) $(RXVT_BINNAME) $(RXVT_OLDNAME); \
- fi
- @$(ECHO) "$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) rxvt $(RXVT_VERNAME)"
- @$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) rxvt $(RXVT_VERNAME)
- @$(ECHO) "$(LN) $(RXVT_VERNAME) $(RXVT_BINNAME)"
- @$(LN) $(RXVT_VERNAME) $(RXVT_BINNAME)
+ $(RMF) $(RXVT_BINNAME)
+ $(RMF) $(RXVTC_BINNAME)
+ $(RMF) $(RXVTD_BINNAME)
+ $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) rxvt $(RXVT_VERNAME)
+ $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) rxvtc $(RXVTC_VERNAME)
+ $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) rxvtd $(RXVTD_VERNAME)
+ $(LN) $(RXVT_VERNAME) $(RXVT_BINNAME)
+ $(LN) $(RXVTC_VERNAME) $(RXVTC_BINNAME)
+ $(LN) $(RXVTD_VERNAME) $(RXVTD_BINNAME)
uninstall:
@$(ECHO) $(RMF) $(RXVT_VERNAME)
/*--------------------------------*-C-*---------------------------------*
* File: command.c
*----------------------------------------------------------------------*
- * $Id: command.C,v 1.8 2003-11-26 10:42:34 pcg Exp $
+ * $Id: command.C,v 1.9 2003-11-27 10:12:10 pcg Exp $
*
* All portions of code are copyright by their respective author/s.
* Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
void
rxvt_term::blink_cb (time_watcher &w)
{
+ SET_R (this);
+
w.at += BLINK_INTERVAL;
hidden_cursor = !hidden_cursor;
want_refresh = 1;
void
rxvt_term::x_cb (io_watcher &w, short revents)
{
+ SET_R (this);
+
process_x_events ();
flush ();
else if (n < 0 && errno == EAGAIN)
return false;
- rxvt_clean_exit ();
- exit (EXIT_FAILURE); /* bad order of events? */
+ destroy ();
}
void
rxvt_term::pty_cb (io_watcher &w, short revents)
{
+ SET_R (this);
+
// loop, but don't allow a single term to monopolize us
// the number of loops is fully arbitrary, and thus wrong
for (int i = 7; i-- && pty_fill (); )
void
rxvt_term::pointer_cb (time_watcher &w)
{
+ SET_R (this);
+
pointer_blank ();
}
#endif
case ClientMessage:
if (ev->xclient.format == 32
&& (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW])
- exit(EXIT_SUCCESS);
+ R->destroy ();
#ifdef OFFIX_DND
/* OffiX Dnd (drag 'n' drop) protocol */
- if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL]
+ else if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL]
&& (ev->xclient.data.l[0] == DndFile
|| ev->xclient.data.l[0] == DndDir
|| ev->xclient.data.l[0] == DndLink)) {
/*--------------------------------*-C-*---------------------------------*
* File: init.c
*----------------------------------------------------------------------*
- * $Id: init.C,v 1.7 2003-11-26 10:42:34 pcg Exp $
+ * $Id: init.C,v 1.8 2003-11-27 10:12:10 pcg Exp $
*
* All portions of code are copyright by their respective author/s.
* Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
else
#endif
er = -1;
- rxvt_get_ttymode(&(R->tio), er);
-
-/* install exit handler for cleanup */
-#ifdef HAVE_ATEXIT
- atexit(rxvt_clean_exit);
-#else
-# ifdef HAVE_ON_EXIT
- on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */
-# endif
-#endif
-
- signal(SIGHUP, rxvt_Exit_signal);
-#ifndef __svr4__
- signal(SIGINT, rxvt_Exit_signal);
-#endif
- signal(SIGQUIT, rxvt_Exit_signal);
- signal(SIGTERM, rxvt_Exit_signal);
- signal(SIGCHLD, rxvt_Child_signal);
-/* need to trap SIGURG for SVR4 (Unixware) rlogin */
-/* signal (SIGURG, SIG_DFL); */
+ rxvt_get_ttymode(&(R->tio), er);
#ifndef __QNX__
/* spin off the command interpreter */
}
/* reset signals and spin off the command interpreter */
- signal(SIGINT, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
- signal(SIGCHLD, SIG_DFL);
+ signal (SIGINT, SIG_DFL);
+ signal (SIGQUIT, SIG_DFL);
+ signal (SIGCHLD, SIG_DFL);
/*
* mimick login's behavior by disabling the job control signals
* a shell that wants them can turn them back on
*/
#ifdef SIGTSTP
- signal(SIGTSTP, SIG_IGN);
- signal(SIGTTIN, SIG_IGN);
- signal(SIGTTOU, SIG_IGN);
+ signal (SIGTSTP, SIG_IGN);
+ signal (SIGTTIN, SIG_IGN);
+ signal (SIGTTOU, SIG_IGN);
#endif /* SIGTSTP */
/* set window size */
/*--------------------------------*-C-*---------------------------------*
* File: main.c
*----------------------------------------------------------------------*
- * $Id: main.C,v 1.7 2003-11-26 10:42:34 pcg Exp $
+ * $Id: main.C,v 1.8 2003-11-27 10:12:10 pcg Exp $
*
* All portions of code are copyright by their respective author/s.
* Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
#ifdef POINTER_BLANK
pointer_ev (this, &rxvt_term::pointer_cb),
#endif
- x_ev (this, &rxvt_term::x_cb)
+ x_ev (this, &rxvt_term::x_cb),
+ destroy_ev (this, &rxvt_term::destroy_cb)
{
cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
}
rxvt_term::~rxvt_term ()
{
+ rxvt_scr_release (this);
+
+#ifndef NO_SETOWNER_TTYDEV
+ rxvt_privileged_ttydev (this, RESTORE);
+#endif
+#ifdef UTMP_SUPPORT
+ rxvt_privileged_utmp (this, RESTORE);
+#endif
+#ifdef USE_XIM
+ if (Input_Context != NULL)
+ {
+ XDestroyIC (Input_Context);
+ Input_Context = NULL;
+ }
+#endif
+
+ if (cmd_fd >= 0)
+ close (cmd_fd);
+
+ if (Xfd >= 0)
+ XCloseDisplay (Xdisplay);
+
delete PixColors;
}
+void
+rxvt_term::destroy ()
+{
+ pty_ev.stop ();
+ x_ev.stop ();
+#ifdef CURSOR_BLINK
+ blink_ev.stop ();
+#endif
+#ifdef POINTER_BLANK
+ pointer_ev.stop ();
+#endif
+
+ destroy_ev.start (0);
+}
+
+void
+rxvt_term::destroy_cb (time_watcher &w)
+{
+ SET_R (this);
+
+ delete this;
+}
+
/*----------------------------------------------------------------------*/
/* rxvt_init() */
/* LIBPROTO */
return R;
}
+/* EXTPROTO */
+void
+rxvt_init_signals ()
+{
+/* install exit handler for cleanup */
+#if 0
+#ifdef HAVE_ATEXIT
+ atexit(rxvt_clean_exit);
+#else
+# ifdef HAVE_ON_EXIT
+ on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */
+# endif
+#endif
+#endif
+
+ struct sigaction sa;
+
+ sigfillset (&sa.sa_mask);
+ sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
+ sa.sa_handler = rxvt_Exit_signal; sigaction (SIGHUP , &sa, 0); //TODO, also: SIGPIPE
+ sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
+ sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
+ sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
+ sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
+
+/* need to trap SIGURG for SVR4 (Unixware) rlogin */
+/* signal (SIGURG, SIG_DFL); */
+
+ XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
+ //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
+}
+
bool
rxvt_term::init (int argc, const char *const *argv)
{
#if 0
#ifdef DEBUG_X
XSynchronize(Xdisplay, True);
- XSetErrorHandler((XErrorHandler) abort);
-#else
- XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
#endif
#endif
RETSIGTYPE
rxvt_Child_signal(int sig __attribute__ ((unused)))
{
- dR;
- int pid, save_errno = errno;
-
- do {
- errno = 0;
- } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR);
+ int pid, save_errno = errno;
+ while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
+ ;
+ errno = save_errno;
+#if 0
if (pid == R->cmd_pid)
- exit(EXIT_SUCCESS);
-
- errno = save_errno;
- signal(SIGCHLD, rxvt_Child_signal);
+ exit (EXIT_SUCCESS);
+#endif
}
/*
rxvt_xerror_handler(const Display * display
__attribute__ ((unused)), const XErrorEvent * event)
{
- dR;
+ dR;
+
+ if (R->allowedxerror == -1)
+ R->allowedxerror = event->error_code;
+ else
+ {
+ rxvt_print_error("XError: Request: %d . %d, Error: %d",
+ event->request_code, event->minor_code,
+ event->error_code);
- if (R->allowedxerror == -1) {
- R->allowedxerror = event->error_code;
- return 0; /* ignored anyway */
+ R->destroy ();
}
- rxvt_print_error("XError: Request: %d . %d, Error: %d",
- event->request_code, event->minor_code,
- event->error_code);
-/* XXX: probably should call rxvt_clean_exit() bypassing X routines */
- exit(EXIT_FAILURE);
-/* NOTREACHED */
+
+ return 0;
}
/*----------------------------------------------------------------------*/
*/
/* EXTPROTO */
void
-rxvt_clean_exit(void)
+rxvt_clean_exit ()
{
- dR;
+ dR;
-#ifdef DEBUG_SCREEN
- rxvt_scr_release(aR);
-#endif
-#ifndef NO_SETOWNER_TTYDEV
- rxvt_privileged_ttydev(aR_ RESTORE);
-#endif
-#ifdef UTMP_SUPPORT
- rxvt_privileged_utmp(aR_ RESTORE);
-#endif
-#ifdef USE_XIM
- if (R->Input_Context != NULL) {
- XDestroyIC(R->Input_Context);
- R->Input_Context = NULL;
- }
-#endif
+ R->destroy ();
}
/* ------------------------------------------------------------------------- *
int
main(int argc, const char *const *argv)
{
+ rxvt_init_signals ();
+
if (!rxvt_init(argc, argv))
return EXIT_FAILURE;
/*
- * $Id: rxvt.h,v 1.7 2003-11-26 10:42:34 pcg Exp $
+ * $Id: rxvt.h,v 1.8 2003-11-27 10:12:10 pcg Exp $
*/
#ifndef _RXVT_H_ /* include once only */
unsigned char cmdbuf_base[BUFSIZ];
unsigned char kbuf[KBUFSZ];
+ void destroy_cb (time_watcher &w); time_watcher destroy_ev;
+
void pty_cb (io_watcher &w, short revents); io_watcher pty_ev;
void x_cb (io_watcher &w, short revents); io_watcher x_ev;
rxvt_term ();
~rxvt_term ();
+ void destroy ();
bool init (int argc, const char *const *argv);
bool init_vars ();
exit (EXIT_FAILURE);
}
+ char *sockname = rxvt_connection::unix_sockname ();
sockaddr_un sa;
-
sa.sun_family = AF_UNIX;
- strcpy (sa.sun_path, rxvt_connection::unix_sockname ());
+ strcpy (sa.sun_path, sockname);
+ free (sockname);
if (connect (fd, (sockaddr *)&sa, sizeof (sa)))
{
#include <cstring>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
void err (const char *format = 0, ...);
};
-struct listener {
+struct unix_listener {
int fd;
void accept_cb (io_watcher &w, short revents); io_watcher accept_ev;
- listener ();
+ unix_listener (const char *sockname);
};
-listener::listener ()
-: accept_ev (this, &listener::accept_cb)
+unix_listener::unix_listener (const char *sockname)
+: accept_ev (this, &unix_listener::accept_cb)
{
if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0)
{
sockaddr_un sa;
sa.sun_family = AF_UNIX;
- strcpy (sa.sun_path, rxvt_connection::unix_sockname ());
+ strcpy (sa.sun_path, sockname);
unlink (rxvt_connection::unix_sockname ());
+ mode_t omask = umask (0077);
+
if (bind (fd, (sockaddr *)&sa, sizeof (sa)))
{
perror ("unable to bind listening socket");
exit (EXIT_FAILURE);
}
+ umask (omask);
+
if (listen (fd, 5))
{
perror ("unable to listen on socket");
accept_ev.start (fd, EVENT_READ);
}
-void listener::accept_cb (io_watcher &w, short revents)
+void unix_listener::accept_cb (io_watcher &w, short revents)
{
int fd2 = accept (fd, 0, 0);
int
main(int argc, const char *const *argv)
{
- listener l;
-
{
sigset_t ss;
sigaddset (&ss, SIGHUP);
+ sigaddset (&ss, SIGPIPE);
sigprocmask (SIG_BLOCK, &ss, 0);
}
- printf ("rxvtd running.\n");
+ rxvt_init_signals ();
+
+ char *sockname = rxvt_connection::unix_sockname ();
+ unix_listener l (sockname);
+ printf ("rxvtd listening on %s.\n", sockname);
+ free (sockname);
+
iom.loop ();
#if 0
-#include <unistd.h>
#include <stdint.h>
#include <cstdlib>
#include <cstring>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <limits.h>
+
#include "rxvtdaemon.h"
-const char *rxvt_connection::unix_sockname ()
+char *rxvt_connection::unix_sockname ()
{
- return "/tmp/rxvtd~";
+ char name[PATH_MAX];
+ char *path = getenv ("RXVT_SOCKET");
+
+ if (!path)
+ {
+ struct utsname u;
+ uname (&u);
+
+ path = getenv ("HOME");
+ snprintf (name, PATH_MAX, "%s/.rxvt-%s",
+ path ? path : "/tmp",
+ u.nodename);
+
+ path = name;
+ }
+
+ return strdup (path);
}
void rxvt_connection::send (const char *data, int len)
struct rxvt_connection {
int fd;
- static const char *unix_sockname ();
+ static char *unix_sockname ();
void send (const char *data, int len);
void send (const char *data);
/*
- * $Id: rxvtlib.h.in,v 1.3 2003-11-25 11:52:42 pcg Exp $
+ * $Id: rxvtlib.h.in,v 1.4 2003-11-27 10:12:10 pcg Exp $
*/
#ifndef _RXVTLIB_H_ /* include once only */
sstyle_t selection_style;
};
+void rxvt_init_signals ();
rxvt_t rxvt_init (int argc, const char *const *argv);
#endif /* _RXVTLIB_H_ */
auto_ptr() : p(0) { }
auto_ptr(T *a) : p(a) { }
- auto_ptr(auto_ptr &a)
+ auto_ptr(auto_ptr<T> &a)
{
p = a.p;
a.p = 0;