… | |
… | |
21 | *----------------------------------------------------------------------*/ |
21 | *----------------------------------------------------------------------*/ |
22 | |
22 | |
23 | #include "../config.h" |
23 | #include "../config.h" |
24 | #include "rxvt.h" |
24 | #include "rxvt.h" |
25 | #include "rxvtdaemon.h" |
25 | #include "rxvtdaemon.h" |
|
|
26 | #include "fdpass.h" |
26 | #include "iom.h" |
27 | #include "iom.h" |
27 | |
28 | |
28 | #include <cstdio> |
29 | #include <cstdio> |
29 | #include <cstdlib> |
30 | #include <cstdlib> |
30 | #include <cstdarg> |
31 | #include <cstdarg> |
… | |
… | |
41 | |
42 | |
42 | extern char **environ; |
43 | extern char **environ; |
43 | |
44 | |
44 | struct server : rxvt_connection { |
45 | struct server : rxvt_connection { |
45 | log_callback log_cb; |
46 | log_callback log_cb; |
|
|
47 | getfd_callback getfd_cb; |
46 | |
48 | |
47 | void read_cb (io_watcher &w, short revents); io_watcher read_ev; |
49 | void read_cb (io_watcher &w, short revents); io_watcher read_ev; |
48 | void log_msg (const char *msg); |
50 | void log_msg (const char *msg); |
|
|
51 | int getfd (int remote_fd); |
49 | |
52 | |
50 | server (int fd) |
53 | server (int fd) |
51 | : read_ev (this, &server::read_cb), |
54 | : read_ev (this, &server::read_cb), |
52 | log_cb (this, &server::log_msg) |
55 | log_cb (this, &server::log_msg), |
|
|
56 | getfd_cb (this, &server::getfd) |
53 | { |
57 | { |
54 | this->fd = fd; |
58 | this->fd = fd; |
55 | read_ev.start (fd, EVENT_READ); |
59 | read_ev.start (fd, EVENT_READ); |
56 | } |
60 | } |
57 | |
61 | |
… | |
… | |
110 | if (fd2 >= 0) |
114 | if (fd2 >= 0) |
111 | { |
115 | { |
112 | fcntl (fd2, F_SETFD, FD_CLOEXEC); |
116 | fcntl (fd2, F_SETFD, FD_CLOEXEC); |
113 | new server (fd2); |
117 | new server (fd2); |
114 | } |
118 | } |
|
|
119 | } |
|
|
120 | |
|
|
121 | int server::getfd (int remote_fd) |
|
|
122 | { |
|
|
123 | #if ENABLE_FRILLS && HAVE_UNIX_FDPASS |
|
|
124 | send ("GETFD"); |
|
|
125 | send (remote_fd); |
|
|
126 | return rxvt_recv_fd (fd); |
|
|
127 | #else |
|
|
128 | return -1; |
|
|
129 | #endif |
115 | } |
130 | } |
116 | |
131 | |
117 | void server::log_msg (const char *msg) |
132 | void server::log_msg (const char *msg) |
118 | { |
133 | { |
119 | send ("MSG"), send (msg); |
134 | send ("MSG"), send (msg); |
… | |
… | |
171 | } |
186 | } |
172 | |
187 | |
173 | envv->push_back (0); |
188 | envv->push_back (0); |
174 | |
189 | |
175 | { |
190 | { |
176 | char **old_environ = environ; |
|
|
177 | environ = envv->begin (); |
|
|
178 | |
|
|
179 | rxvt_term *term = new rxvt_term; |
191 | rxvt_term *term = new rxvt_term; |
180 | |
192 | |
181 | term->log_hook = &log_cb; |
193 | term->log_hook = &log_cb; |
|
|
194 | term->getfd_hook = &getfd_cb; |
182 | term->argv = argv; |
195 | term->argv = argv; |
183 | term->envv = envv; |
196 | term->envv = envv; |
184 | |
197 | |
185 | bool success; |
198 | bool success; |
186 | |
199 | |
… | |
… | |
193 | success = false; |
206 | success = false; |
194 | } |
207 | } |
195 | |
208 | |
196 | term->log_hook = 0; |
209 | term->log_hook = 0; |
197 | |
210 | |
198 | environ = old_environ; |
|
|
199 | chdir ("/"); |
211 | chdir ("/"); |
200 | |
212 | |
201 | if (!success) |
213 | if (!success) |
202 | term->destroy (); |
214 | term->destroy (); |
203 | |
215 | |