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.22 by root, Fri Dec 23 14:46:35 2005 UTC vs.
Revision 1.30 by root, Wed Aug 9 22:01:07 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 rxvt_fatal ("socket name too long, aborting.\n");
78
76 if ((fd = socket (PF_UNIX, SOCK_STREAM, 0)) < 0) 79 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
77 { 80 {
78 perror ("unable to create listening socket"); 81 perror ("unable to create listening socket");
79 exit (EXIT_FAILURE); 82 exit (EXIT_FAILURE);
80 } 83 }
81 84
82 fcntl (fd, F_SETFD, FD_CLOEXEC); 85 fcntl (fd, F_SETFD, FD_CLOEXEC);
83 86
84 sockaddr_un sa;
85
86 sa.sun_family = AF_UNIX; 87 sa.sun_family = AF_UNIX;
87 strcpy (sa.sun_path, sockname); 88 strcpy (sa.sun_path, sockname);
88 89
89 unlink (rxvt_connection::unix_sockname ()); 90 unlink (rxvt_connection::unix_sockname ());
90 91
118 } 119 }
119} 120}
120 121
121int server::getfd (int remote_fd) 122int server::getfd (int remote_fd)
122{ 123{
123#if ENABLE_FRILLS && HAVE_UNIX_FDPASS
124 send ("GETFD"); 124 send ("GETFD");
125 send (remote_fd); 125 send (remote_fd);
126 return rxvt_recv_fd (fd); 126 return ptytty::recv_fd (fd);
127#else
128 return -1;
129#endif
130} 127}
131 128
132void server::log_msg (const char *msg) 129void server::log_msg (const char *msg)
133{ 130{
134 send ("MSG"), send (msg); 131 send ("MSG"), send (msg);
170 return err (); 167 return err ();
171 168
172 if (!strcmp (tok, "END")) 169 if (!strcmp (tok, "END"))
173 break; 170 break;
174 else if (!strcmp (tok, "ENV") && recv (tok)) 171 else if (!strcmp (tok, "ENV") && recv (tok))
175 envv->push_back (tok.get ()); 172 envv->push_back (strdup (tok));
176 else if (!strcmp (tok, "CWD") && recv (tok)) 173 else if (!strcmp (tok, "CWD") && recv (tok))
177 { 174 {
178 if (chdir (tok)) 175 if (chdir (tok))
179 err ("unable to change to working directory to '%s': %s", 176 err ("unable to change to working directory to '%s': %s",
180 (char *)tok, strerror (errno)); 177 (char *)tok, strerror (errno));
181 } 178 }
182 else if (!strcmp (tok, "ARG") && recv (tok)) 179 else if (!strcmp (tok, "ARG") && recv (tok))
183 argv->push_back (tok.get ()); 180 argv->push_back (strdup (tok));
184 else 181 else
185 return err ("protocol error: unexpected NEW token"); 182 return err ("protocol error: unexpected NEW token");
186 } 183 }
187 184
188 envv->push_back (0); 185 envv->push_back (0);
189 186
190 { 187 {
191 char **old_environ = environ;
192 environ = envv->begin ();
193
194 rxvt_term *term = new rxvt_term; 188 rxvt_term *term = new rxvt_term;
195 189
196 term->log_hook = &log_cb; 190 term->log_hook = &log_cb;
197 term->getfd_hook = &getfd_cb; 191 term->getfd_hook = &getfd_cb;
198 term->argv = argv;
199 term->envv = envv;
200 192
201 bool success; 193 bool success;
202 194
203 try 195 try
204 { 196 {
205 success = term->init (argv->size (), argv->begin ()); 197 success = term->init (argv, envv);
206 } 198 }
207 catch (const class rxvt_failure_exception &e) 199 catch (const class rxvt_failure_exception &e)
208 { 200 {
209 success = false; 201 success = false;
210 } 202 }
211 203
212 term->log_hook = 0; 204 term->log_hook = 0;
213 205
214 environ = old_environ;
215 chdir ("/"); 206 chdir ("/");
216 207
217 if (!success) 208 if (!success)
218 term->destroy (); 209 term->destroy ();
219 210
230int opt_fork, opt_opendisplay, opt_quiet; 221int opt_fork, opt_opendisplay, opt_quiet;
231 222
232int 223int
233main (int argc, const char *const *argv) 224main (int argc, const char *const *argv)
234{ 225{
226 rxvt_init ();
227
235 for (int i = 1; i < argc; i++) 228 for (int i = 1; i < argc; i++)
236 { 229 {
237 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) 230 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
238 opt_fork = 1; 231 opt_fork = 1;
239 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) 232 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
245 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 238 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
246 return EXIT_FAILURE; 239 return EXIT_FAILURE;
247 } 240 }
248 } 241 }
249 242
250 rxvt_init ();
251
252 chdir ("/"); 243 chdir ("/");
253 244
254 if (opt_opendisplay) 245 if (opt_opendisplay)
255 displays.get (getenv ("DISPLAY")); // open display and never release it 246 displays.get (getenv ("DISPLAY")); // open display and never release it
256 247

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines