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.13 by root, Sun Aug 22 01:40:31 2004 UTC vs.
Revision 1.23 by root, Wed Feb 1 18:07:18 2006 UTC

19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
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 <cstdio>
25#include <cstdlib>
26#include <cstring>
27#include <csignal>
28
29#include <unistd.h>
30#include <sys/socket.h>
31#include <sys/un.h>
32
24#include "rxvtdaemon.h" 33#include "rxvtdaemon.h"
34#include "libptytty.h"
25 35
26#include "rxvt.h" 36#include "rxvt.h"
27 37
28#include <cstdio> 38#define STATUS_SUCCESS 0
29#include <cstdlib> 39#define STATUS_FAILURE 1
30#include <cstring> 40#define STATUS_CONNECTION_FAILED 2
31
32#include <unistd.h>
33#include <signal.h>
34#include <sys/socket.h>
35#include <sys/un.h>
36 41
37struct client : rxvt_connection { 42struct client : rxvt_connection {
38 client (); 43 client ();
39}; 44};
40 45
41client::client () 46client::client ()
42{ 47{
43 if ((fd = socket (PF_UNIX, SOCK_STREAM, 0)) < 0) 48 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
44 { 49 {
45 perror ("unable to create communications socket"); 50 perror ("unable to create communications socket");
46 exit (EXIT_FAILURE); 51 exit (STATUS_FAILURE);
47 } 52 }
48 53
49 char *sockname = rxvt_connection::unix_sockname (); 54 char *sockname = rxvt_connection::unix_sockname ();
50 sockaddr_un sa; 55 sockaddr_un sa;
51 sa.sun_family = AF_UNIX; 56 sa.sun_family = AF_UNIX;
53 free (sockname); 58 free (sockname);
54 59
55 if (connect (fd, (sockaddr *)&sa, sizeof (sa))) 60 if (connect (fd, (sockaddr *)&sa, sizeof (sa)))
56 { 61 {
57 perror ("unable to connect to the rxvt-unicode daemon"); 62 perror ("unable to connect to the rxvt-unicode daemon");
58 exit (EXIT_FAILURE); 63 exit (STATUS_CONNECTION_FAILED);
59 } 64 }
60} 65}
61 66
62extern char **environ; 67extern char **environ;
63 68
64int 69int
65main (int argc, const char *const *argv) 70main (int argc, const char *const *argv)
66{ 71{
67 client c; 72 client c;
68 char buf[PATH_MAX];
69
70 { 73 {
71 sigset_t ss; 74 sigset_t ss;
72 75
73 sigemptyset (&ss); 76 sigemptyset (&ss);
74 sigaddset (&ss, SIGHUP); 77 sigaddset (&ss, SIGHUP);
75 sigprocmask (SIG_BLOCK, &ss, 0); 78 sigprocmask (SIG_BLOCK, &ss, 0);
76 } 79 }
77 80
78 c.send ("NEW"); 81 c.send ("NEW");
82
79 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* 83 // instead of getcwd we could opendir (".") and pass the fd for fchdir *g*
80 c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); 84 char cwd[PATH_MAX];
81 85
86 if (!getcwd (cwd, sizeof (cwd)))
87 {
88 perror ("unable to determine current working directory");
89 exit (STATUS_FAILURE);
90 }
91
92 c.send ("CWD"), c.send (cwd);
93
82 for (char **var = environ; *environ; environ++) 94 for (char **var = environ; *var; var++)
83 c.send ("ENV"), c.send (*environ); 95 c.send ("ENV"), c.send (*var);
84 96
85 const char *base = strrchr (argv[0], '/'); 97 const char *base = strrchr (argv[0], '/');
86 base = base ? base + 1 : argv[0]; 98 base = base ? base + 1 : argv[0];
87 c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME); 99 c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME);
88 100
90 c.send ("ARG"), c.send (argv[i]); 102 c.send ("ARG"), c.send (argv[i]);
91 103
92 c.send ("END"); 104 c.send ("END");
93 105
94 auto_str tok; 106 auto_str tok;
107 int cint;
95 108
96 for (;;) 109 for (;;)
97 if (!c.recv (tok)) 110 if (!c.recv (tok))
98 { 111 {
99 fprintf (stderr, "protocol error: unexpected eof from server.\n"); 112 fprintf (stderr, "protocol error: unexpected eof from server.\n");
100 break; 113 break;
101 } 114 }
102 else if (!strcmp (tok, "MSG") && c.recv (tok)) 115 else if (!strcmp (tok, "MSG") && c.recv (tok))
103 fprintf (stderr, "%s", (const char *)tok); 116 fprintf (stderr, "%s", (const char *)tok);
117 else if (!strcmp (tok, "GETFD") && c.recv (cint))
118 {
119 if (!ptytty::send_fd (c.fd, cint))
120 {
121 fprintf (stderr, "unable to send fd %d: ", cint); perror (0);
122 exit (STATUS_FAILURE);
123 }
124 }
104 else if (!strcmp (tok, "END")) 125 else if (!strcmp (tok, "END"))
105 { 126 {
106 int success; 127 int success;
128
107 if (c.recv (success)) 129 if (c.recv (success))
108 exit (success ? EXIT_SUCCESS : EXIT_FAILURE); 130 exit (success ? STATUS_SUCCESS : STATUS_FAILURE);
109 } 131 }
110 else 132 else
111 { 133 {
112 fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok); 134 fprintf (stderr, "protocol error: received unsupported token '%s'.\n", (const char *)tok);
113 break; 135 break;
114 } 136 }
115 137
116 return EXIT_FAILURE; 138 return STATUS_FAILURE;
117} 139}
118 140

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines