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.45 by root, Tue Feb 19 18:58:05 2008 UTC vs.
Revision 1.51 by root, Sun Oct 24 17:34:47 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{
230 int opt_fork, opt_opendisplay, opt_quiet;
231#if ENABLE_MLOCK
232 int opt_lock;
233#endif
234
234 rxvt_init (); 235 rxvt_init ();
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 }
264 fflush (stdout); 269 fflush (stdout);
265 } 270 }
266 271
267 free (sockname); 272 free (sockname);
268 273
274 pid_t pid = 0;
269 if (opt_fork) 275 if (opt_fork)
270 { 276 {
271 pid_t pid = fork (); 277 pid = fork ();
278 }
272 279
280#if ENABLE_MLOCK
281 // Optionally perform an mlockall so this process does not get swapped out.
282 if (opt_lock && !pid)
283 if (mlockall (MCL_CURRENT | MCL_FUTURE) < 0)
284 perror ("unable to lock into ram");
285#endif
286
287 if (opt_fork)
288 {
273 if (pid < 0) 289 if (pid < 0)
274 { 290 {
275 rxvt_log ("unable to fork daemon, aborting.\n"); 291 rxvt_log ("unable to fork daemon, aborting.\n");
276 return EXIT_FAILURE; 292 return EXIT_FAILURE;
277 } 293 }
278 else if (pid > 0) 294 else if (pid > 0)
279 _exit (EXIT_SUCCESS); 295 _exit (EXIT_SUCCESS);
280 296
281 ev_default_fork (); 297 ev_loop_fork (EV_DEFAULT_UC);
282 } 298 }
283 299
284 ev_loop (0); 300 ev_run ();
285 301
286 return EXIT_SUCCESS; 302 return EXIT_SUCCESS;
287} 303}
288 304

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines