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.32 by root, Fri Aug 18 23:06:48 2006 UTC vs.
Revision 1.36 by root, Sat Nov 17 07:28:00 2007 UTC

36#include <cerrno> 36#include <cerrno>
37 37
38#include "rxvt.h" 38#include "rxvt.h"
39#include "rxvtdaemon.h" 39#include "rxvtdaemon.h"
40#include "libptytty.h" 40#include "libptytty.h"
41#include "iom.h"
42 41
43struct server : rxvt_connection { 42struct server : rxvt_connection {
44 log_callback log_cb; 43 log_callback log_cb;
45 getfd_callback getfd_cb; 44 getfd_callback getfd_cb;
46 45
47 void read_cb (io_watcher &w, short revents); io_watcher read_ev; 46 void read_cb (ev::io &w, int revents); ev::io read_ev;
48 void log_msg (const char *msg); 47 void log_msg (const char *msg);
49 int getfd (int remote_fd); 48 int getfd (int remote_fd);
50 49
51 server (int fd) 50 server (int fd)
52 : read_ev (this, &server::read_cb), 51 : read_ev (this, &server::read_cb),
53 log_cb (this, &server::log_msg), 52 log_cb (this, &server::log_msg),
54 getfd_cb (this, &server::getfd) 53 getfd_cb (this, &server::getfd)
55 { 54 {
56 this->fd = fd; 55 fcntl (fd, F_SETFD, FD_CLOEXEC);
56 fcntl (fd, F_SETFL, 0);
57 read_ev.start (fd, EVENT_READ); 57 read_ev.start (fd, ev::READ);
58 } 58 }
59 59
60 void err (const char *format = 0, ...); 60 void err (const char *format = 0, ...);
61}; 61};
62 62
63struct unix_listener { 63struct unix_listener {
64 int fd; 64 int fd;
65 65
66 void accept_cb (io_watcher &w, short revents); io_watcher accept_ev; 66 void accept_cb (ev::io &w, int revents); ev::io accept_ev;
67 67
68 unix_listener (const char *sockname); 68 unix_listener (const char *sockname);
69}; 69};
70 70
71unix_listener::unix_listener (const char *sockname) 71unix_listener::unix_listener (const char *sockname)
72: accept_ev (this, &unix_listener::accept_cb) 72: accept_ev (this, &unix_listener::accept_cb)
73{ 73{
74 sockaddr_un sa; 74 sockaddr_un sa;
75 75
76 if (strlen (sockname) >= sizeof(sa.sun_path)) 76 if (strlen (sockname) >= sizeof(sa.sun_path))
77 { 77 {
78 fputs ("socket name too long, aborting.\n", stderr); 78 fputs ("socket name too long, aborting.\n", stderr);
79 exit (EXIT_FAILURE); 79 exit (EXIT_FAILURE);
80 } 80 }
84 perror ("unable to create listening socket"); 84 perror ("unable to create listening socket");
85 exit (EXIT_FAILURE); 85 exit (EXIT_FAILURE);
86 } 86 }
87 87
88 fcntl (fd, F_SETFD, FD_CLOEXEC); 88 fcntl (fd, F_SETFD, FD_CLOEXEC);
89 fcntl (fd, F_SETFL, O_NONBLOCK);
89 90
90 sa.sun_family = AF_UNIX; 91 sa.sun_family = AF_UNIX;
91 strcpy (sa.sun_path, sockname); 92 strcpy (sa.sun_path, sockname);
92 93
93 unlink (rxvt_connection::unix_sockname ()); 94 unlink (rxvt_connection::unix_sockname ());
106 { 107 {
107 perror ("unable to listen on socket"); 108 perror ("unable to listen on socket");
108 exit (EXIT_FAILURE); 109 exit (EXIT_FAILURE);
109 } 110 }
110 111
111 accept_ev.start (fd, EVENT_READ); 112 accept_ev.start (fd, ev::READ);
112} 113}
113 114
114void unix_listener::accept_cb (io_watcher &w, short revents) 115void unix_listener::accept_cb (ev::io &w, int revents)
115{ 116{
116 int fd2 = accept (fd, 0, 0); 117 int fd2 = accept (fd, 0, 0);
117 118
118 if (fd2 >= 0) 119 if (fd2 >= 0)
119 {
120 fcntl (fd2, F_SETFD, FD_CLOEXEC);
121 new server (fd2); 120 new server (fd2);
122 }
123} 121}
124 122
125int server::getfd (int remote_fd) 123int server::getfd (int remote_fd)
126{ 124{
127 send ("GETFD"); 125 send ("GETFD");
151 send ("END"), send (0); 149 send ("END"), send (0);
152 close (fd); 150 close (fd);
153 delete this; 151 delete this;
154} 152}
155 153
156void server::read_cb (io_watcher &w, short revents) 154void server::read_cb (ev::io &w, int revents)
157{ 155{
158 auto_str tok; 156 auto_str tok;
159 157
160 if (recv (tok)) 158 if (recv (tok))
161 { 159 {
162 if (!strcmp (tok, "NEW")) 160 if (!strcmp (tok, "NEW"))
163 { 161 {
164 stringvec *argv = new stringvec; 162 stringvec *argv = new stringvec;
165 stringvec *envv = new stringvec; 163 stringvec *envv = new stringvec;
166 164
167 for (;;) 165 for (;;)
168 { 166 {
169 if (!recv (tok)) 167 if (!recv (tok))
170 return err (); 168 return err ();
171 169
191 189
192 envv->push_back (0); 190 envv->push_back (0);
193 191
194 { 192 {
195 rxvt_term *term = new rxvt_term; 193 rxvt_term *term = new rxvt_term;
196 194
197 term->log_hook = &log_cb; 195 term->log_hook = &log_cb;
198 term->getfd_hook = &getfd_cb; 196 term->getfd_hook = &getfd_cb;
199 197
200 bool success; 198 bool success;
201 199
202 try 200 try
203 { 201 {
204 success = term->init (argv, envv); 202 success = term->init (argv, envv);
205 } 203 }
206 catch (const class rxvt_failure_exception &e) 204 catch (const class rxvt_failure_exception &e)
244 { 242 {
245 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 243 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
246 return EXIT_FAILURE; 244 return EXIT_FAILURE;
247 } 245 }
248 } 246 }
249 247
250 chdir ("/"); 248 chdir ("/");
251 249
252 if (opt_opendisplay) 250 if (opt_opendisplay)
253 displays.get (getenv ("DISPLAY")); // open display and never release it 251 displays.get (getenv ("DISPLAY")); // open display and never release it
254 252
274 } 272 }
275 else if (pid > 0) 273 else if (pid > 0)
276 _exit (EXIT_SUCCESS); 274 _exit (EXIT_SUCCESS);
277 } 275 }
278 276
279 io_manager::loop (); 277 ev::ev_loop (0);
280 278
281 return EXIT_SUCCESS; 279 return EXIT_SUCCESS;
282} 280}
283 281

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines