… | |
… | |
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 | |
72 | unix_listener::unix_listener (const char *sockname) |
73 | unix_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); |
… | |
… | |
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 | } |
… | |
… | |
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 | |