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.34 by root, Sun Nov 11 04:08:00 2007 UTC vs.
Revision 1.44 by root, Tue Feb 19 13:37:17 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;
57 fcntl (fd, F_SETFD, FD_CLOEXEC);
58 fcntl (fd, F_SETFL, 0);
56 read_ev.start (fd, ev::READ); 59 read_ev.start (fd, ev::READ);
57 } 60 }
58 61
59 void err (const char *format = 0, ...); 62 void err (const char *format = 0, ...);
60}; 63};
66 69
67 unix_listener (const char *sockname); 70 unix_listener (const char *sockname);
68}; 71};
69 72
70unix_listener::unix_listener (const char *sockname) 73unix_listener::unix_listener (const char *sockname)
71: accept_ev (this, &unix_listener::accept_cb)
72{ 74{
75 accept_ev.set<unix_listener, &unix_listener::accept_cb> (this);
76
73 sockaddr_un sa; 77 sockaddr_un sa;
74 78
75 if (strlen (sockname) >= sizeof(sa.sun_path)) 79 if (strlen (sockname) >= sizeof(sa.sun_path))
76 { 80 {
77 fputs ("socket name too long, aborting.\n", stderr); 81 fputs ("socket name too long, aborting.\n", stderr);
83 perror ("unable to create listening socket"); 87 perror ("unable to create listening socket");
84 exit (EXIT_FAILURE); 88 exit (EXIT_FAILURE);
85 } 89 }
86 90
87 fcntl (fd, F_SETFD, FD_CLOEXEC); 91 fcntl (fd, F_SETFD, FD_CLOEXEC);
92 fcntl (fd, F_SETFL, O_NONBLOCK);
88 93
89 sa.sun_family = AF_UNIX; 94 sa.sun_family = AF_UNIX;
90 strcpy (sa.sun_path, sockname); 95 strcpy (sa.sun_path, sockname);
91 96
92 unlink (rxvt_connection::unix_sockname ()); 97 unlink (rxvt_connection::unix_sockname ());
113void unix_listener::accept_cb (ev::io &w, int revents) 118void unix_listener::accept_cb (ev::io &w, int revents)
114{ 119{
115 int fd2 = accept (fd, 0, 0); 120 int fd2 = accept (fd, 0, 0);
116 121
117 if (fd2 >= 0) 122 if (fd2 >= 0)
118 {
119 fcntl (fd2, F_SETFD, FD_CLOEXEC);
120 new server (fd2); 123 new server (fd2);
121 }
122} 124}
123 125
124int server::getfd (int remote_fd) 126int server::getfd (int remote_fd)
125{ 127{
126 send ("GETFD"); 128 send ("GETFD");
194 rxvt_term *term = new rxvt_term; 196 rxvt_term *term = new rxvt_term;
195 197
196 term->log_hook = &log_cb; 198 term->log_hook = &log_cb;
197 term->getfd_hook = &getfd_cb; 199 term->getfd_hook = &getfd_cb;
198 200
199 bool success; 201 bool success = true;
200 202
201 try 203 try
202 { 204 {
203 success = term->init (argv, envv); 205 term->init (argv, envv);
204 } 206 }
205 catch (const class rxvt_failure_exception &e) 207 catch (const class rxvt_failure_exception &e)
206 { 208 {
207 success = false; 209 success = false;
208 } 210 }
244 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 246 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
245 return EXIT_FAILURE; 247 return EXIT_FAILURE;
246 } 248 }
247 } 249 }
248 250
249 chdir ("/");
250
251 if (opt_opendisplay) 251 if (opt_opendisplay)
252 displays.get (getenv ("DISPLAY")); // open display and never release it 252 displays.get (getenv ("DISPLAY")); // open display and never release it
253 253
254 char *sockname = rxvt_connection::unix_sockname (); 254 char *sockname = rxvt_connection::unix_sockname ();
255 unix_listener l (sockname); 255 unix_listener l (sockname);
256
257 chdir ("/");
256 258
257 if (!opt_quiet) 259 if (!opt_quiet)
258 { 260 {
259 printf ("rxvt-unicode daemon listening on %s.\n", sockname); 261 printf ("rxvt-unicode daemon listening on %s.\n", sockname);
260 fflush (stdout); 262 fflush (stdout);
271 rxvt_log ("unable to fork daemon, aborting.\n"); 273 rxvt_log ("unable to fork daemon, aborting.\n");
272 return EXIT_FAILURE; 274 return EXIT_FAILURE;
273 } 275 }
274 else if (pid > 0) 276 else if (pid > 0)
275 _exit (EXIT_SUCCESS); 277 _exit (EXIT_SUCCESS);
276 }
277 278
279 ev_default_fork ();
280 }
281
278 ev::ev_loop (0); 282 ev_loop (0);
279 283
280 return EXIT_SUCCESS; 284 return EXIT_SUCCESS;
281} 285}
282 286

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines