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 | |
|
|
56 | this->fd = fd; |
55 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
57 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
56 | fcntl (fd, F_SETFL, 0); |
58 | fcntl (fd, F_SETFL, 0); |
57 | read_ev.start (fd, ev::READ); |
59 | read_ev.start (fd, ev::READ); |
58 | } |
60 | } |
59 | |
61 | |
… | |
… | |
67 | |
69 | |
68 | unix_listener (const char *sockname); |
70 | unix_listener (const char *sockname); |
69 | }; |
71 | }; |
70 | |
72 | |
71 | unix_listener::unix_listener (const char *sockname) |
73 | unix_listener::unix_listener (const char *sockname) |
72 | : accept_ev (this, &unix_listener::accept_cb) |
|
|
73 | { |
74 | { |
|
|
75 | accept_ev.set<unix_listener, &unix_listener::accept_cb> (this); |
|
|
76 | |
74 | sockaddr_un sa; |
77 | sockaddr_un sa; |
75 | |
78 | |
76 | if (strlen (sockname) >= sizeof(sa.sun_path)) |
79 | if (strlen (sockname) >= sizeof(sa.sun_path)) |
77 | { |
80 | { |
78 | fputs ("socket name too long, aborting.\n", stderr); |
81 | fputs ("socket name too long, aborting.\n", stderr); |
… | |
… | |
193 | rxvt_term *term = new rxvt_term; |
196 | rxvt_term *term = new rxvt_term; |
194 | |
197 | |
195 | term->log_hook = &log_cb; |
198 | term->log_hook = &log_cb; |
196 | term->getfd_hook = &getfd_cb; |
199 | term->getfd_hook = &getfd_cb; |
197 | |
200 | |
198 | bool success; |
201 | bool success = true; |
199 | |
202 | |
200 | try |
203 | try |
201 | { |
204 | { |
202 | success = term->init (argv, envv); |
205 | term->init (argv, envv); |
203 | } |
206 | } |
204 | catch (const class rxvt_failure_exception &e) |
207 | catch (const class rxvt_failure_exception &e) |
205 | { |
208 | { |
206 | success = false; |
209 | success = false; |
207 | } |
210 | } |
… | |
… | |
243 | 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]); |
244 | return EXIT_FAILURE; |
247 | return EXIT_FAILURE; |
245 | } |
248 | } |
246 | } |
249 | } |
247 | |
250 | |
248 | chdir ("/"); |
251 | // optionally open display and never release it. |
249 | |
|
|
250 | if (opt_opendisplay) |
252 | if (opt_opendisplay) |
251 | displays.get (getenv ("DISPLAY")); // open display and never release it |
253 | if (const char *dpy = getenv ("DISPLAY")) |
|
|
254 | displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? |
252 | |
255 | |
253 | char *sockname = rxvt_connection::unix_sockname (); |
256 | char *sockname = rxvt_connection::unix_sockname (); |
254 | unix_listener l (sockname); |
257 | unix_listener l (sockname); |
|
|
258 | |
|
|
259 | chdir ("/"); |
255 | |
260 | |
256 | if (!opt_quiet) |
261 | if (!opt_quiet) |
257 | { |
262 | { |
258 | printf ("rxvt-unicode daemon listening on %s.\n", sockname); |
263 | printf ("rxvt-unicode daemon listening on %s.\n", sockname); |
259 | fflush (stdout); |
264 | fflush (stdout); |
… | |
… | |
270 | rxvt_log ("unable to fork daemon, aborting.\n"); |
275 | rxvt_log ("unable to fork daemon, aborting.\n"); |
271 | return EXIT_FAILURE; |
276 | return EXIT_FAILURE; |
272 | } |
277 | } |
273 | else if (pid > 0) |
278 | else if (pid > 0) |
274 | _exit (EXIT_SUCCESS); |
279 | _exit (EXIT_SUCCESS); |
275 | } |
|
|
276 | |
280 | |
|
|
281 | ev_default_fork (); |
|
|
282 | } |
|
|
283 | |
277 | ev::ev_loop (0); |
284 | ev_loop (0); |
278 | |
285 | |
279 | return EXIT_SUCCESS; |
286 | return EXIT_SUCCESS; |
280 | } |
287 | } |
281 | |
288 | |