ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtc.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtc.C (file contents):
Revision 1.11 by pcg, Thu Apr 8 20:31:45 2004 UTC vs.
Revision 1.19 by root, Tue Jan 10 04:23:39 2006 UTC

20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------*/ 21 *----------------------------------------------------------------------*/
22 22
23#include "../config.h" 23#include "../config.h"
24#include "rxvtdaemon.h" 24#include "rxvtdaemon.h"
25#include "fdpass.h"
25 26
26#include "rxvt.h" 27#include "rxvt.h"
27 28
28#include <cstdio> 29#include <cstdio>
29#include <cstdlib> 30#include <cstdlib>
31#include <cstring>
32#include <csignal>
30 33
31#include <unistd.h> 34#include <unistd.h>
32#include <signal.h>
33#include <sys/socket.h> 35#include <sys/socket.h>
34#include <sys/un.h> 36#include <sys/un.h>
35 37
36struct client : rxvt_connection { 38struct client : rxvt_connection {
37 client (); 39 client ();
51 strcpy (sa.sun_path, sockname); 53 strcpy (sa.sun_path, sockname);
52 free (sockname); 54 free (sockname);
53 55
54 if (connect (fd, (sockaddr *)&sa, sizeof (sa))) 56 if (connect (fd, (sockaddr *)&sa, sizeof (sa)))
55 { 57 {
56 perror ("unable to connect to rxvtd"); 58 perror ("unable to connect to the rxvt-unicode daemon");
57 exit (EXIT_FAILURE); 59 exit (EXIT_FAILURE);
58 } 60 }
59} 61}
60 62
61extern char **environ; 63extern char **environ;
62 64
63int 65int
64main (int argc, const char *const *argv) 66main (int argc, const char *const *argv)
65{ 67{
66 client c; 68 client c;
67 char buf[PATH_MAX];
68
69 { 69 {
70 sigset_t ss; 70 sigset_t ss;
71 71
72 sigemptyset (&ss); 72 sigemptyset (&ss);
73 sigaddset (&ss, SIGHUP); 73 sigaddset (&ss, SIGHUP);
74 sigprocmask (SIG_BLOCK, &ss, 0); 74 sigprocmask (SIG_BLOCK, &ss, 0);
75 } 75 }
76 76
77 c.send ("NEW"); 77 c.send ("NEW");
78
78 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* 79 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g*
79 c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); 80 char cwd[PATH_MAX];
80 81
81 for (char **var = environ; *environ; environ++) 82 if (!getcwd (cwd, sizeof (cwd)))
82 c.send ("ENV"), c.send (*environ); 83 {
84 perror ("unable to determine current working directory");
85 exit (EXIT_FAILURE);
86 }
83 87
88 c.send ("CWD"), c.send (cwd);
89
90 for (char **var = environ; *var; var++)
91 c.send ("ENV"), c.send (*var);
92
93 const char *base = strrchr (argv[0], '/');
94 base = base ? base + 1 : argv[0];
95 c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME);
96
84 for (int i = 0; i < argc; i++) 97 for (int i = 1; i < argc; i++)
85 c.send ("ARG"), c.send (argv[i]); 98 c.send ("ARG"), c.send (argv[i]);
86 99
87 c.send ("END"); 100 c.send ("END");
88 101
89 auto_str tok; 102 auto_str tok;
103 int cint;
90 104
91 for (;;) 105 for (;;)
92 if (!c.recv (tok)) 106 if (!c.recv (tok))
93 { 107 {
94 fprintf (stderr, "protocol error: unexpected eof from server.\n"); 108 fprintf (stderr, "protocol error: unexpected eof from server.\n");
95 break; 109 break;
96 } 110 }
97 else if (!strcmp (tok, "MSG") && c.recv (tok)) 111 else if (!strcmp (tok, "MSG") && c.recv (tok))
98 fprintf (stderr, "%s", (const char *)tok); 112 fprintf (stderr, "%s", (const char *)tok);
113#if ENABLE_FRILLS && HAVE_UNIX_FDPASS
114 else if (!strcmp (tok, "GETFD") && c.recv (cint))
115 {
116 if (rxvt_send_fd (c.fd, cint) < 0)
117 {
118 fprintf (stderr, "unable to send fd %d: ", cint); perror (0);
119 exit (EXIT_FAILURE);
120 }
121 }
122#endif
99 else if (!strcmp (tok, "END")) 123 else if (!strcmp (tok, "END"))
100 { 124 {
101 int success; 125 int success;
126
102 if (c.recv (success)) 127 if (c.recv (success))
103 exit (success ? EXIT_SUCCESS : EXIT_FAILURE); 128 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
104 } 129 }
105 else 130 else
106 { 131 {
107 fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok); 132 fprintf (stderr, "protocol error: received unsupported token '%s'.\n", (const char *)tok);
108 break; 133 break;
109 } 134 }
110 135
111 return EXIT_FAILURE; 136 return EXIT_FAILURE;
112} 137}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines