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.23 by root, Wed Jan 11 00:59:58 2006 UTC vs.
Revision 1.27 by root, Sun Jan 22 04:01:52 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 "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{
76 if ((fd = socket (PF_UNIX, SOCK_STREAM, 0)) < 0) 74 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
77 { 75 {
78 perror ("unable to create listening socket"); 76 perror ("unable to create listening socket");
79 exit (EXIT_FAILURE); 77 exit (EXIT_FAILURE);
80 } 78 }
81 79
118 } 116 }
119} 117}
120 118
121int server::getfd (int remote_fd) 119int server::getfd (int remote_fd)
122{ 120{
123#if ENABLE_FRILLS && HAVE_UNIX_FDPASS
124 send ("GETFD"); 121 send ("GETFD");
125 send (remote_fd); 122 send (remote_fd);
126 return rxvt_recv_fd (fd); 123 return ptytty::recv_fd (fd);
127#else
128 return -1;
129#endif
130} 124}
131 125
132void server::log_msg (const char *msg) 126void server::log_msg (const char *msg)
133{ 127{
134 send ("MSG"), send (msg); 128 send ("MSG"), send (msg);
170 return err (); 164 return err ();
171 165
172 if (!strcmp (tok, "END")) 166 if (!strcmp (tok, "END"))
173 break; 167 break;
174 else if (!strcmp (tok, "ENV") && recv (tok)) 168 else if (!strcmp (tok, "ENV") && recv (tok))
175 envv->push_back (tok.get ()); 169 envv->push_back (strdup (tok));
176 else if (!strcmp (tok, "CWD") && recv (tok)) 170 else if (!strcmp (tok, "CWD") && recv (tok))
177 { 171 {
178 if (chdir (tok)) 172 if (chdir (tok))
179 err ("unable to change to working directory to '%s': %s", 173 err ("unable to change to working directory to '%s': %s",
180 (char *)tok, strerror (errno)); 174 (char *)tok, strerror (errno));
181 } 175 }
182 else if (!strcmp (tok, "ARG") && recv (tok)) 176 else if (!strcmp (tok, "ARG") && recv (tok))
183 argv->push_back (tok.get ()); 177 argv->push_back (strdup (tok));
184 else 178 else
185 return err ("protocol error: unexpected NEW token"); 179 return err ("protocol error: unexpected NEW token");
186 } 180 }
187 181
188 envv->push_back (0); 182 envv->push_back (0);
190 { 184 {
191 rxvt_term *term = new rxvt_term; 185 rxvt_term *term = new rxvt_term;
192 186
193 term->log_hook = &log_cb; 187 term->log_hook = &log_cb;
194 term->getfd_hook = &getfd_cb; 188 term->getfd_hook = &getfd_cb;
195 term->argv = argv;
196 term->envv = envv;
197 189
198 bool success; 190 bool success;
199 191
200 try 192 try
201 { 193 {
202 success = term->init (argv->size (), argv->begin ()); 194 success = term->init (argv, envv);
203 } 195 }
204 catch (const class rxvt_failure_exception &e) 196 catch (const class rxvt_failure_exception &e)
205 { 197 {
206 success = false; 198 success = false;
207 } 199 }
226int opt_fork, opt_opendisplay, opt_quiet; 218int opt_fork, opt_opendisplay, opt_quiet;
227 219
228int 220int
229main (int argc, const char *const *argv) 221main (int argc, const char *const *argv)
230{ 222{
223 rxvt_init ();
224
231 for (int i = 1; i < argc; i++) 225 for (int i = 1; i < argc; i++)
232 { 226 {
233 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) 227 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
234 opt_fork = 1; 228 opt_fork = 1;
235 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) 229 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
241 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]);
242 return EXIT_FAILURE; 236 return EXIT_FAILURE;
243 } 237 }
244 } 238 }
245 239
246 rxvt_init ();
247
248 chdir ("/"); 240 chdir ("/");
249 241
250 if (opt_opendisplay) 242 if (opt_opendisplay)
251 displays.get (getenv ("DISPLAY")); // open display and never release it 243 displays.get (getenv ("DISPLAY")); // open display and never release it
252 244

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines