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.16 by root, Mon Nov 28 19:35:04 2005 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 "rxvtdaemon.h"
25
26#include "rxvt.h"
27
28#include <cstdio> 24#include <cstdio>
29#include <cstdlib> 25#include <cstdlib>
30#include <cstring> 26#include <cstring>
31#include <csignal> 27#include <csignal>
32 28
33#include <unistd.h> 29#include <unistd.h>
34#include <sys/socket.h> 30#include <sys/socket.h>
35#include <sys/un.h> 31#include <sys/un.h>
36 32
33#include "rxvtdaemon.h"
34#include "libptytty.h"
35
36#include "rxvt.h"
37
38#define STATUS_SUCCESS 0
39#define STATUS_FAILURE 1
40#define STATUS_CONNECTION_FAILED 2
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
79 char cwd[PATH_MAX]; 84 char cwd[PATH_MAX];
80 85
81 if (!getcwd (cwd, sizeof (cwd))) 86 if (!getcwd (cwd, sizeof (cwd)))
82 { 87 {
83 perror ("unable to determine current working directory"); 88 perror ("unable to determine current working directory");
84 exit (EXIT_FAILURE); 89 exit (STATUS_FAILURE);
85 } 90 }
86 91
87 c.send ("CWD"), c.send (cwd); 92 c.send ("CWD"), c.send (cwd);
88 93
89 for (char **var = environ; *var; var++) 94 for (char **var = environ; *var; var++)
97 c.send ("ARG"), c.send (argv[i]); 102 c.send ("ARG"), c.send (argv[i]);
98 103
99 c.send ("END"); 104 c.send ("END");
100 105
101 auto_str tok; 106 auto_str tok;
107 int cint;
102 108
103 for (;;) 109 for (;;)
104 if (!c.recv (tok)) 110 if (!c.recv (tok))
105 { 111 {
106 fprintf (stderr, "protocol error: unexpected eof from server.\n"); 112 fprintf (stderr, "protocol error: unexpected eof from server.\n");
107 break; 113 break;
108 } 114 }
109 else if (!strcmp (tok, "MSG") && c.recv (tok)) 115 else if (!strcmp (tok, "MSG") && c.recv (tok))
110 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 }
111 else if (!strcmp (tok, "END")) 125 else if (!strcmp (tok, "END"))
112 { 126 {
113 int success; 127 int success;
128
114 if (c.recv (success)) 129 if (c.recv (success))
115 exit (success ? EXIT_SUCCESS : EXIT_FAILURE); 130 exit (success ? STATUS_SUCCESS : STATUS_FAILURE);
116 } 131 }
117 else 132 else
118 { 133 {
119 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);
120 break; 135 break;
121 } 136 }
122 137
123 return EXIT_FAILURE; 138 return STATUS_FAILURE;
124} 139}
125 140

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines