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.38 by root, Sun Nov 18 00:47:13 2007 UTC vs.
Revision 1.46 by root, Sun Jun 15 13:54:15 2008 UTC

1/*----------------------------------------------------------------------* 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-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2007 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.
46 void read_cb (ev::io &w, int revents); ev::io read_ev; 46 void read_cb (ev::io &w, int revents); ev::io read_ev;
47 void log_msg (const char *msg); 47 void log_msg (const char *msg);
48 int getfd (int remote_fd); 48 int getfd (int remote_fd);
49 49
50 server (int fd) 50 server (int fd)
51 : read_ev (this, &server::read_cb),
52 log_cb (this, &server::log_msg),
53 getfd_cb (this, &server::getfd)
54 { 51 {
52 read_ev.set <server, &server::read_cb> (this);
53 log_cb.set <server, &server::log_msg> (this);
54 getfd_cb.set<server, &server::getfd> (this);
55
55 this->fd = fd; 56 this->fd = fd;
56 fcntl (fd, F_SETFD, FD_CLOEXEC); 57 fcntl (fd, F_SETFD, FD_CLOEXEC);
57 fcntl (fd, F_SETFL, 0); 58 fcntl (fd, F_SETFL, 0);
58 read_ev.start (fd, ev::READ); 59 read_ev.start (fd, ev::READ);
59 } 60 }
68 69
69 unix_listener (const char *sockname); 70 unix_listener (const char *sockname);
70}; 71};
71 72
72unix_listener::unix_listener (const char *sockname) 73unix_listener::unix_listener (const char *sockname)
73: accept_ev (this, &unix_listener::accept_cb)
74{ 74{
75 accept_ev.set<unix_listener, &unix_listener::accept_cb> (this);
76
75 sockaddr_un sa; 77 sockaddr_un sa;
76 78
77 if (strlen (sockname) >= sizeof(sa.sun_path)) 79 if (strlen (sockname) >= sizeof(sa.sun_path))
78 { 80 {
79 fputs ("socket name too long, aborting.\n", stderr); 81 fputs ("socket name too long, aborting.\n", stderr);
170 172
171 if (!strcmp (tok, "END")) 173 if (!strcmp (tok, "END"))
172 break; 174 break;
173 else if (!strcmp (tok, "ENV") && recv (tok)) 175 else if (!strcmp (tok, "ENV") && recv (tok))
174 envv->push_back (strdup (tok)); 176 envv->push_back (strdup (tok));
175 else if (!strcmp (tok, "CWD") && recv (tok))
176 {
177 if (chdir (tok))
178 {
179 delete envv;
180 delete argv;
181 return err ("unable to change to working directory to '%s', aborting: %s.\n",
182 (char *)tok, strerror (errno));
183 }
184 }
185 else if (!strcmp (tok, "ARG") && recv (tok)) 177 else if (!strcmp (tok, "ARG") && recv (tok))
186 argv->push_back (strdup (tok)); 178 argv->push_back (strdup (tok));
187 else 179 else
188 return err ("protocol error: unexpected NEW token.\n"); 180 return err ("protocol error: unexpected NEW token.\n");
189 } 181 }
194 rxvt_term *term = new rxvt_term; 186 rxvt_term *term = new rxvt_term;
195 187
196 term->log_hook = &log_cb; 188 term->log_hook = &log_cb;
197 term->getfd_hook = &getfd_cb; 189 term->getfd_hook = &getfd_cb;
198 190
199 bool success; 191 bool success = true;
200 192
201 try 193 try
202 { 194 {
203 success = term->init (argv, envv); 195 term->init (argv, envv);
204 } 196 }
205 catch (const class rxvt_failure_exception &e) 197 catch (const class rxvt_failure_exception &e)
206 { 198 {
207 success = false; 199 success = false;
208 } 200 }
209 201
210 term->log_hook = 0; 202 term->log_hook = 0;
211 203
212 chdir ("/"); 204 chdir ("/"); // init might change to different working directory
213 205
214 if (!success) 206 if (!success)
215 term->destroy (); 207 term->destroy ();
216 208
217 send ("END"); send (success ? 1 : 0); 209 send ("END"); send (success ? 1 : 0);
244 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 236 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
245 return EXIT_FAILURE; 237 return EXIT_FAILURE;
246 } 238 }
247 } 239 }
248 240
249 chdir ("/"); 241 // optionally open display and never release it.
250
251 if (opt_opendisplay) 242 if (opt_opendisplay)
252 displays.get (getenv ("DISPLAY")); // open display and never release it 243 if (const char *dpy = getenv ("DISPLAY"))
244 displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe?
253 245
254 char *sockname = rxvt_connection::unix_sockname (); 246 char *sockname = rxvt_connection::unix_sockname ();
255 unix_listener l (sockname); 247 unix_listener l (sockname);
248
249 chdir ("/");
256 250
257 if (!opt_quiet) 251 if (!opt_quiet)
258 { 252 {
259 printf ("rxvt-unicode daemon listening on %s.\n", sockname); 253 printf ("rxvt-unicode daemon listening on %s.\n", sockname);
260 fflush (stdout); 254 fflush (stdout);
272 return EXIT_FAILURE; 266 return EXIT_FAILURE;
273 } 267 }
274 else if (pid > 0) 268 else if (pid > 0)
275 _exit (EXIT_SUCCESS); 269 _exit (EXIT_SUCCESS);
276 270
277 ev::ev_default_fork (); 271 ev_default_fork ();
278 } 272 }
279 273
280 ev::ev_loop (0); 274 ev_loop (0);
281 275
282 return EXIT_SUCCESS; 276 return EXIT_SUCCESS;
283} 277}
284 278

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines