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.24 by root, Tue Jan 17 15:17:39 2006 UTC vs.
Revision 1.29 by root, Mon Feb 20 22:42:00 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
120 118
121int server::getfd (int remote_fd) 119int server::getfd (int remote_fd)
122{ 120{
123 send ("GETFD"); 121 send ("GETFD");
124 send (remote_fd); 122 send (remote_fd);
125 return rxvt_recv_fd (fd); 123 return ptytty::recv_fd (fd);
126} 124}
127 125
128void server::log_msg (const char *msg) 126void server::log_msg (const char *msg)
129{ 127{
130 send ("MSG"), send (msg); 128 send ("MSG"), send (msg);
166 return err (); 164 return err ();
167 165
168 if (!strcmp (tok, "END")) 166 if (!strcmp (tok, "END"))
169 break; 167 break;
170 else if (!strcmp (tok, "ENV") && recv (tok)) 168 else if (!strcmp (tok, "ENV") && recv (tok))
171 envv->push_back (tok.get ()); 169 envv->push_back (strdup (tok));
172 else if (!strcmp (tok, "CWD") && recv (tok)) 170 else if (!strcmp (tok, "CWD") && recv (tok))
173 { 171 {
174 if (chdir (tok)) 172 if (chdir (tok))
175 err ("unable to change to working directory to '%s': %s", 173 err ("unable to change to working directory to '%s': %s",
176 (char *)tok, strerror (errno)); 174 (char *)tok, strerror (errno));
177 } 175 }
178 else if (!strcmp (tok, "ARG") && recv (tok)) 176 else if (!strcmp (tok, "ARG") && recv (tok))
179 argv->push_back (tok.get ()); 177 argv->push_back (strdup (tok));
180 else 178 else
181 return err ("protocol error: unexpected NEW token"); 179 return err ("protocol error: unexpected NEW token");
182 } 180 }
183 181
184 envv->push_back (0); 182 envv->push_back (0);
186 { 184 {
187 rxvt_term *term = new rxvt_term; 185 rxvt_term *term = new rxvt_term;
188 186
189 term->log_hook = &log_cb; 187 term->log_hook = &log_cb;
190 term->getfd_hook = &getfd_cb; 188 term->getfd_hook = &getfd_cb;
191 term->argv = argv;
192 term->envv = envv;
193 189
194 bool success; 190 bool success;
195 191
196 try 192 try
197 { 193 {
198 success = term->init (argv->size (), argv->begin ()); 194 success = term->init (argv, envv);
199 } 195 }
200 catch (const class rxvt_failure_exception &e) 196 catch (const class rxvt_failure_exception &e)
201 { 197 {
202 success = false; 198 success = false;
203 } 199 }
222int opt_fork, opt_opendisplay, opt_quiet; 218int opt_fork, opt_opendisplay, opt_quiet;
223 219
224int 220int
225main (int argc, const char *const *argv) 221main (int argc, const char *const *argv)
226{ 222{
223 rxvt_init ();
224
227 for (int i = 1; i < argc; i++) 225 for (int i = 1; i < argc; i++)
228 { 226 {
229 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) 227 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
230 opt_fork = 1; 228 opt_fork = 1;
231 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) 229 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
237 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 235 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
238 return EXIT_FAILURE; 236 return EXIT_FAILURE;
239 } 237 }
240 } 238 }
241 239
242 rxvt_init ();
243
244 chdir ("/"); 240 chdir ("/");
245 241
246 if (opt_opendisplay) 242 if (opt_opendisplay)
247 displays.get (getenv ("DISPLAY")); // open display and never release it 243 displays.get (getenv ("DISPLAY")); // open display and never release it
248 244

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines