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.18 by root, Thu Sep 2 07:44:40 2004 UTC vs.
Revision 1.22 by root, Fri Dec 23 14:46:35 2005 UTC

21 *----------------------------------------------------------------------*/ 21 *----------------------------------------------------------------------*/
22 22
23#include "../config.h" 23#include "../config.h"
24#include "rxvt.h" 24#include "rxvt.h"
25#include "rxvtdaemon.h" 25#include "rxvtdaemon.h"
26#include "fdpass.h"
26#include "iom.h" 27#include "iom.h"
27 28
28#include <cstdio> 29#include <cstdio>
29#include <cstdlib> 30#include <cstdlib>
30#include <cstdarg> 31#include <cstdarg>
41 42
42extern char **environ; 43extern char **environ;
43 44
44struct server : rxvt_connection { 45struct server : rxvt_connection {
45 log_callback log_cb; 46 log_callback log_cb;
47 getfd_callback getfd_cb;
46 48
47 void read_cb (io_watcher &w, short revents); io_watcher read_ev; 49 void read_cb (io_watcher &w, short revents); io_watcher read_ev;
48 void log_msg (const char *msg); 50 void log_msg (const char *msg);
51 int getfd (int remote_fd);
49 52
50 server (int fd) 53 server (int fd)
51 : read_ev (this, &server::read_cb), 54 : read_ev (this, &server::read_cb),
52 log_cb (this, &server::log_msg) 55 log_cb (this, &server::log_msg),
56 getfd_cb (this, &server::getfd)
53 { 57 {
54 this->fd = fd; 58 this->fd = fd;
55 read_ev.start (fd, EVENT_READ); 59 read_ev.start (fd, EVENT_READ);
56 } 60 }
57 61
110 if (fd2 >= 0) 114 if (fd2 >= 0)
111 { 115 {
112 fcntl (fd2, F_SETFD, FD_CLOEXEC); 116 fcntl (fd2, F_SETFD, FD_CLOEXEC);
113 new server (fd2); 117 new server (fd2);
114 } 118 }
119}
120
121int server::getfd (int remote_fd)
122{
123#if ENABLE_FRILLS && HAVE_UNIX_FDPASS
124 send ("GETFD");
125 send (remote_fd);
126 return rxvt_recv_fd (fd);
127#else
128 return -1;
129#endif
115} 130}
116 131
117void server::log_msg (const char *msg) 132void server::log_msg (const char *msg)
118{ 133{
119 send ("MSG"), send (msg); 134 send ("MSG"), send (msg);
177 environ = envv->begin (); 192 environ = envv->begin ();
178 193
179 rxvt_term *term = new rxvt_term; 194 rxvt_term *term = new rxvt_term;
180 195
181 term->log_hook = &log_cb; 196 term->log_hook = &log_cb;
197 term->getfd_hook = &getfd_cb;
182 term->argv = argv; 198 term->argv = argv;
183 term->envv = envv; 199 term->envv = envv;
184 200
185 bool success; 201 bool success;
186 202
194 } 210 }
195 211
196 term->log_hook = 0; 212 term->log_hook = 0;
197 213
198 environ = old_environ; 214 environ = old_environ;
215 chdir ("/");
199 216
200 if (!success) 217 if (!success)
201 term->destroy (); 218 term->destroy ();
202 219
203 send ("END"); send (success ? 1 : 0); 220 send ("END"); send (success ? 1 : 0);
208 } 225 }
209 else 226 else
210 return err (); 227 return err ();
211} 228}
212 229
230int opt_fork, opt_opendisplay, opt_quiet;
231
213int 232int
214main (int argc, const char *const *argv) 233main (int argc, const char *const *argv)
215{ 234{
235 for (int i = 1; i < argc; i++)
236 {
237 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
238 opt_fork = 1;
239 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
240 opt_opendisplay = 1;
241 else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet"))
242 opt_quiet = 1;
243 else
244 {
245 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
246 return EXIT_FAILURE;
247 }
248 }
249
216 rxvt_init (); 250 rxvt_init ();
251
252 chdir ("/");
253
254 if (opt_opendisplay)
255 displays.get (getenv ("DISPLAY")); // open display and never release it
217 256
218 char *sockname = rxvt_connection::unix_sockname (); 257 char *sockname = rxvt_connection::unix_sockname ();
219 unix_listener l (sockname); 258 unix_listener l (sockname);
259
260 if (!opt_quiet)
261 {
220 printf ("rxvt-unicode daemon listening on %s.\n", sockname); 262 printf ("rxvt-unicode daemon listening on %s.\n", sockname);
263 fflush (stdout);
264 }
265
221 free (sockname); 266 free (sockname);
222 267
268 if (opt_fork)
269 {
270 pid_t pid = fork ();
271
272 if (pid < 0)
273 {
274 rxvt_log ("unable to fork daemon, aborting.\n");
275 return EXIT_FAILURE;
276 }
277 else if (pid > 0)
278 _exit (EXIT_SUCCESS);
279 }
280
223 io_manager::loop (); 281 io_manager::loop ();
224 282
225 return EXIT_SUCCESS; 283 return EXIT_SUCCESS;
226} 284}
227 285

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines