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

Comparing rxvt-unicode/src/rxvtd.C (file contents):
Revision 1.25 by root, Tue Jan 17 15:43:49 2006 UTC vs.
Revision 1.31 by root, Fri Aug 18 23:03:31 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtd.C 2 * File: rxvtd.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
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 "rxvt.h"
25#include "rxvtdaemon.h"
26#include "fdpass.h"
27#include "iom.h"
28
29#include <cstdio> 24#include <cstdio>
30#include <cstdlib> 25#include <cstdlib>
31#include <cstdarg> 26#include <cstdarg>
32#include <cstring> 27#include <cstring>
33 28
38#include <sys/socket.h> 33#include <sys/socket.h>
39#include <sys/un.h> 34#include <sys/un.h>
40 35
41#include <cerrno> 36#include <cerrno>
42 37
43extern char **environ; 38#include "rxvt.h"
39#include "rxvtdaemon.h"
40#include "libptytty.h"
41#include "iom.h"
44 42
45struct server : rxvt_connection { 43struct server : rxvt_connection {
46 log_callback log_cb; 44 log_callback log_cb;
47 getfd_callback getfd_cb; 45 getfd_callback getfd_cb;
48 46
71}; 69};
72 70
73unix_listener::unix_listener (const char *sockname) 71unix_listener::unix_listener (const char *sockname)
74: accept_ev (this, &unix_listener::accept_cb) 72: accept_ev (this, &unix_listener::accept_cb)
75{ 73{
74 sockaddr_un sa;
75
76 if (strlen (sockname) >= sizeof(sa.sun_path))
77 {
78 fputs ("socket name too long, aborting.\n", stderr);
79 exit (EXIT_FAILURE);
80 }
81
76 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) 82 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
77 { 83 {
78 perror ("unable to create listening socket"); 84 perror ("unable to create listening socket");
79 exit (EXIT_FAILURE); 85 exit (EXIT_FAILURE);
80 } 86 }
81 87
82 fcntl (fd, F_SETFD, FD_CLOEXEC); 88 fcntl (fd, F_SETFD, FD_CLOEXEC);
83
84 sockaddr_un sa;
85 89
86 sa.sun_family = AF_UNIX; 90 sa.sun_family = AF_UNIX;
87 strcpy (sa.sun_path, sockname); 91 strcpy (sa.sun_path, sockname);
88 92
89 unlink (rxvt_connection::unix_sockname ()); 93 unlink (rxvt_connection::unix_sockname ());
120 124
121int server::getfd (int remote_fd) 125int server::getfd (int remote_fd)
122{ 126{
123 send ("GETFD"); 127 send ("GETFD");
124 send (remote_fd); 128 send (remote_fd);
125 return rxvt_recv_fd (fd); 129 return ptytty::recv_fd (fd);
126} 130}
127 131
128void server::log_msg (const char *msg) 132void server::log_msg (const char *msg)
129{ 133{
130 send ("MSG"), send (msg); 134 send ("MSG"), send (msg);
142 va_end (ap); 146 va_end (ap);
143 147
144 send ("MSG"), send (err); 148 send ("MSG"), send (err);
145 } 149 }
146 150
147 send ("END", 0); 151 send ("END"); send (0);
148 close (fd); 152 close (fd);
149 delete this; 153 delete this;
150} 154}
151 155
152void server::read_cb (io_watcher &w, short revents) 156void server::read_cb (io_watcher &w, short revents)
157 { 161 {
158 if (!strcmp (tok, "NEW")) 162 if (!strcmp (tok, "NEW"))
159 { 163 {
160 stringvec *argv = new stringvec; 164 stringvec *argv = new stringvec;
161 stringvec *envv = new stringvec; 165 stringvec *envv = new stringvec;
162 166
163 for (;;) 167 for (;;)
164 { 168 {
165 if (!recv (tok)) 169 if (!recv (tok))
166 return err (); 170 return err ();
167 171
168 if (!strcmp (tok, "END")) 172 if (!strcmp (tok, "END"))
169 break; 173 break;
170 else if (!strcmp (tok, "ENV") && recv (tok)) 174 else if (!strcmp (tok, "ENV") && recv (tok))
171 envv->push_back (tok.get ()); 175 envv->push_back (strdup (tok));
172 else if (!strcmp (tok, "CWD") && recv (tok)) 176 else if (!strcmp (tok, "CWD") && recv (tok))
173 { 177 {
174 if (chdir (tok)) 178 if (chdir (tok))
179 {
180 delete envv;
181 delete argv;
175 err ("unable to change to working directory to '%s': %s", 182 return err ("unable to change to working directory to '%s', aborting: %s.\n",
176 (char *)tok, strerror (errno)); 183 (char *)tok, strerror (errno));
184 }
177 } 185 }
178 else if (!strcmp (tok, "ARG") && recv (tok)) 186 else if (!strcmp (tok, "ARG") && recv (tok))
179 argv->push_back (tok.get ()); 187 argv->push_back (strdup (tok));
180 else 188 else
181 return err ("protocol error: unexpected NEW token"); 189 return err ("protocol error: unexpected NEW token.\n");
182 } 190 }
183 191
184 envv->push_back (0); 192 envv->push_back (0);
185 193
186 { 194 {
187 rxvt_term *term = new rxvt_term; 195 rxvt_term *term = new rxvt_term;
188 196
189 term->log_hook = &log_cb; 197 term->log_hook = &log_cb;
190 term->getfd_hook = &getfd_cb; 198 term->getfd_hook = &getfd_cb;
191 term->argv = argv;
192 term->envv = envv;
193 199
194 bool success; 200 bool success;
195 201
196 try 202 try
197 { 203 {
198 success = term->init (argv->size (), argv->begin ()); 204 success = term->init (argv, envv);
199 } 205 }
200 catch (const class rxvt_failure_exception &e) 206 catch (const class rxvt_failure_exception &e)
201 { 207 {
202 success = false; 208 success = false;
203 } 209 }
211 217
212 send ("END"); send (success ? 1 : 0); 218 send ("END"); send (success ? 1 : 0);
213 } 219 }
214 } 220 }
215 else 221 else
216 return err ("protocol error: request '%s' unsupported.", (char *)tok); 222 return err ("protocol error: request '%s' unsupported.\n", (char *)tok);
217 } 223 }
218 else 224 else
219 return err (); 225 return err ();
220} 226}
221 227

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines