ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtd.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtd.C (file contents):
Revision 1.44 by root, Tue Feb 19 13:37:17 2008 UTC vs.
Revision 1.53 by sf-exg, Fri Nov 19 00:10:18 2010 UTC

31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/stat.h> 32#include <sys/stat.h>
33#include <sys/socket.h> 33#include <sys/socket.h>
34#include <sys/un.h> 34#include <sys/un.h>
35 35
36#if defined(ENABLE_FRILLS) && defined(_POSIX_MEMLOCK) && _POSIX_MEMLOCK > 0
37# define ENABLE_MLOCK 1
38#endif
39
40#if ENABLE_MLOCK
41# include <sys/mman.h>
42#endif
43
36#include <cerrno> 44#include <cerrno>
37 45
38#include "rxvt.h" 46#include "rxvt.h"
39#include "rxvtdaemon.h" 47#include "rxvtdaemon.h"
40#include "libptytty.h" 48#include "libptytty.h"
172 180
173 if (!strcmp (tok, "END")) 181 if (!strcmp (tok, "END"))
174 break; 182 break;
175 else if (!strcmp (tok, "ENV") && recv (tok)) 183 else if (!strcmp (tok, "ENV") && recv (tok))
176 envv->push_back (strdup (tok)); 184 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)) 185 else if (!strcmp (tok, "ARG") && recv (tok))
188 argv->push_back (strdup (tok)); 186 argv->push_back (strdup (tok));
189 else 187 else
190 return err ("protocol error: unexpected NEW token.\n"); 188 return err ("protocol error: unexpected NEW token.\n");
191 } 189 }
209 success = false; 207 success = false;
210 } 208 }
211 209
212 term->log_hook = 0; 210 term->log_hook = 0;
213 211
214 chdir ("/"); 212 chdir ("/"); // init might change to different working directory
215 213
216 if (!success) 214 if (!success)
217 term->destroy (); 215 term->destroy ();
218 216
219 send ("END"); send (success ? 1 : 0); 217 send ("END"); send (success ? 1 : 0);
224 } 222 }
225 else 223 else
226 return err (); 224 return err ();
227} 225}
228 226
229int opt_fork, opt_opendisplay, opt_quiet;
230
231int 227int
232main (int argc, const char *const *argv) 228main (int argc, const char *const *argv)
233{ 229{
234 rxvt_init (); 230 ptytty::init ();
231
232 int opt_fork = 0, opt_opendisplay = 0, opt_quiet = 0;
233#if ENABLE_MLOCK
234 int opt_lock = 0;
235#endif
235 236
236 for (int i = 1; i < argc; i++) 237 for (int i = 1; i < argc; i++)
237 { 238 {
238 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork")) 239 if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
239 opt_fork = 1; 240 opt_fork = 1;
240 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay")) 241 else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
241 opt_opendisplay = 1; 242 opt_opendisplay = 1;
242 else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet")) 243 else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet"))
243 opt_quiet = 1; 244 opt_quiet = 1;
245#if ENABLE_MLOCK
246 else if (!strcmp (argv [i], "-m") || !strcmp (argv [i], "--mlock"))
247 opt_lock = 1;
248#endif
244 else 249 else
245 { 250 {
246 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]); 251 rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
247 return EXIT_FAILURE; 252 return EXIT_FAILURE;
248 } 253 }
249 } 254 }
250 255
256 rxvt_init ();
257
258 // optionally open display and never release it.
251 if (opt_opendisplay) 259 if (opt_opendisplay)
252 displays.get (getenv ("DISPLAY")); // open display and never release it 260 if (const char *dpy = getenv ("DISPLAY"))
261 displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe?
253 262
254 char *sockname = rxvt_connection::unix_sockname (); 263 char *sockname = rxvt_connection::unix_sockname ();
255 unix_listener l (sockname); 264 unix_listener l (sockname);
256 265
257 chdir ("/"); 266 chdir ("/");
262 fflush (stdout); 271 fflush (stdout);
263 } 272 }
264 273
265 free (sockname); 274 free (sockname);
266 275
276 pid_t pid = 0;
267 if (opt_fork) 277 if (opt_fork)
268 { 278 {
269 pid_t pid = fork (); 279 pid = fork ();
280 }
270 281
282#if ENABLE_MLOCK
283 // Optionally perform an mlockall so this process does not get swapped out.
284 if (opt_lock && !pid)
285 if (mlockall (MCL_CURRENT | MCL_FUTURE) < 0)
286 perror ("unable to lock into ram");
287#endif
288
289 if (opt_fork)
290 {
271 if (pid < 0) 291 if (pid < 0)
272 { 292 {
273 rxvt_log ("unable to fork daemon, aborting.\n"); 293 rxvt_log ("unable to fork daemon, aborting.\n");
274 return EXIT_FAILURE; 294 return EXIT_FAILURE;
275 } 295 }
276 else if (pid > 0) 296 else if (pid > 0)
277 _exit (EXIT_SUCCESS); 297 _exit (EXIT_SUCCESS);
278 298
279 ev_default_fork (); 299 ev_loop_fork (EV_DEFAULT_UC);
280 } 300 }
281 301
282 ev_loop (0); 302 ev_run ();
283 303
284 return EXIT_SUCCESS; 304 return EXIT_SUCCESS;
285} 305}
286 306

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines