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. |
… | |
… | |
172 | |
172 | |
173 | if (!strcmp (tok, "END")) |
173 | if (!strcmp (tok, "END")) |
174 | break; |
174 | break; |
175 | else if (!strcmp (tok, "ENV") && recv (tok)) |
175 | else if (!strcmp (tok, "ENV") && recv (tok)) |
176 | envv->push_back (strdup (tok)); |
176 | envv->push_back (strdup (tok)); |
177 | else if (!strcmp (tok, "CWD") && recv (tok)) |
|
|
178 | { |
|
|
179 | if (chdir (tok)) |
|
|
180 | { |
|
|
181 | delete envv; |
|
|
182 | delete argv; |
|
|
183 | return err ("unable to change to working directory to '%s', aborting: %s.\n", |
|
|
184 | (char *)tok, strerror (errno)); |
|
|
185 | } |
|
|
186 | } |
|
|
187 | else if (!strcmp (tok, "ARG") && recv (tok)) |
177 | else if (!strcmp (tok, "ARG") && recv (tok)) |
188 | argv->push_back (strdup (tok)); |
178 | argv->push_back (strdup (tok)); |
189 | else |
179 | else |
190 | return err ("protocol error: unexpected NEW token.\n"); |
180 | return err ("protocol error: unexpected NEW token.\n"); |
191 | } |
181 | } |
… | |
… | |
209 | success = false; |
199 | success = false; |
210 | } |
200 | } |
211 | |
201 | |
212 | term->log_hook = 0; |
202 | term->log_hook = 0; |
213 | |
203 | |
214 | chdir ("/"); |
204 | chdir ("/"); // init might change to different working directory |
215 | |
205 | |
216 | if (!success) |
206 | if (!success) |
217 | term->destroy (); |
207 | term->destroy (); |
218 | |
208 | |
219 | send ("END"); send (success ? 1 : 0); |
209 | send ("END"); send (success ? 1 : 0); |
… | |
… | |
246 | rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); |
236 | rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); |
247 | return EXIT_FAILURE; |
237 | return EXIT_FAILURE; |
248 | } |
238 | } |
249 | } |
239 | } |
250 | |
240 | |
251 | chdir ("/"); |
241 | // optionally open display and never release it. |
252 | |
|
|
253 | if (opt_opendisplay) |
242 | if (opt_opendisplay) |
254 | displays.get (getenv ("DISPLAY")); // open display and never release it |
243 | if (const char *dpy = getenv ("DISPLAY")) |
|
|
244 | displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? |
255 | |
245 | |
256 | char *sockname = rxvt_connection::unix_sockname (); |
246 | char *sockname = rxvt_connection::unix_sockname (); |
257 | unix_listener l (sockname); |
247 | unix_listener l (sockname); |
|
|
248 | |
|
|
249 | chdir ("/"); |
258 | |
250 | |
259 | if (!opt_quiet) |
251 | if (!opt_quiet) |
260 | { |
252 | { |
261 | printf ("rxvt-unicode daemon listening on %s.\n", sockname); |
253 | printf ("rxvt-unicode daemon listening on %s.\n", sockname); |
262 | fflush (stdout); |
254 | fflush (stdout); |