… | |
… | |
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), |
51 | : read_ev (this, &server::read_cb) |
52 | log_cb (this, &server::log_msg), |
|
|
53 | getfd_cb (this, &server::getfd) |
|
|
54 | { |
52 | { |
|
|
53 | callback_set (log_cb , this, server, log_msg); |
|
|
54 | callback_set (getfd_cb, this, server, getfd); |
55 | this->fd = fd; |
55 | this->fd = fd; |
|
|
56 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
57 | fcntl (fd, F_SETFL, 0); |
56 | read_ev.start (fd, ev::READ); |
58 | read_ev.start (fd, ev::READ); |
57 | } |
59 | } |
58 | |
60 | |
59 | void err (const char *format = 0, ...); |
61 | void err (const char *format = 0, ...); |
60 | }; |
62 | }; |
… | |
… | |
83 | perror ("unable to create listening socket"); |
85 | perror ("unable to create listening socket"); |
84 | exit (EXIT_FAILURE); |
86 | exit (EXIT_FAILURE); |
85 | } |
87 | } |
86 | |
88 | |
87 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
89 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
90 | fcntl (fd, F_SETFL, O_NONBLOCK); |
88 | |
91 | |
89 | sa.sun_family = AF_UNIX; |
92 | sa.sun_family = AF_UNIX; |
90 | strcpy (sa.sun_path, sockname); |
93 | strcpy (sa.sun_path, sockname); |
91 | |
94 | |
92 | unlink (rxvt_connection::unix_sockname ()); |
95 | unlink (rxvt_connection::unix_sockname ()); |
… | |
… | |
113 | void unix_listener::accept_cb (ev::io &w, int revents) |
116 | void unix_listener::accept_cb (ev::io &w, int revents) |
114 | { |
117 | { |
115 | int fd2 = accept (fd, 0, 0); |
118 | int fd2 = accept (fd, 0, 0); |
116 | |
119 | |
117 | if (fd2 >= 0) |
120 | if (fd2 >= 0) |
118 | { |
|
|
119 | fcntl (fd2, F_SETFD, FD_CLOEXEC); |
|
|
120 | new server (fd2); |
121 | new server (fd2); |
121 | } |
|
|
122 | } |
122 | } |
123 | |
123 | |
124 | int server::getfd (int remote_fd) |
124 | int server::getfd (int remote_fd) |
125 | { |
125 | { |
126 | send ("GETFD"); |
126 | send ("GETFD"); |
… | |
… | |
271 | rxvt_log ("unable to fork daemon, aborting.\n"); |
271 | rxvt_log ("unable to fork daemon, aborting.\n"); |
272 | return EXIT_FAILURE; |
272 | return EXIT_FAILURE; |
273 | } |
273 | } |
274 | else if (pid > 0) |
274 | else if (pid > 0) |
275 | _exit (EXIT_SUCCESS); |
275 | _exit (EXIT_SUCCESS); |
276 | } |
|
|
277 | |
276 | |
|
|
277 | ev_default_fork (); |
|
|
278 | } |
|
|
279 | |
278 | ev::ev_loop (0); |
280 | ev_loop (0); |
279 | |
281 | |
280 | return EXIT_SUCCESS; |
282 | return EXIT_SUCCESS; |
281 | } |
283 | } |
282 | |
284 | |