--- rxvt-unicode/src/rxvtc.C 2003/11/24 17:28:08 1.1 +++ rxvt-unicode/src/rxvtc.C 2004/04/02 20:41:01 1.9 @@ -1,9 +1,13 @@ +#include "../config.h" #include "rxvtdaemon.h" +#include "rxvt.h" + #include #include #include +#include #include #include @@ -15,36 +19,73 @@ { if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) { - perror ("unable to create listening socket"); + perror ("unable to create communications socket"); 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))) { - perror ("unable to bind listening socket"); + perror ("unable to connect to rxvtd"); exit (EXIT_FAILURE); } } +extern char **environ; + int -main(int argc, const char *const *argv) +main (int argc, const char *const *argv) { client c; char buf[PATH_MAX]; + { + sigset_t ss; + + sigemptyset (&ss); + sigaddset (&ss, SIGHUP); + sigprocmask (SIG_BLOCK, &ss, 0); + } + c.send ("NEW"); - c.send ("DISPLAY"); c.send (getenv ("DISPLAY")); - // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* - c.send ("CWD"); c.send (getcwd (buf, sizeof (buf))); + // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* + c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); + + for (char **var = environ; *environ; environ++) + c.send ("ENV"), c.send (*environ); - c.send ("ARGV"); c.send (argc); for (int i = 0; i < argc; i++) - c.send (argv[i]); + 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; }