--- rxvt-unicode/src/rxvtd.C 2007/11/17 07:28:00 1.36 +++ rxvt-unicode/src/rxvtd.C 2008/06/15 13:54:15 1.46 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2007 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,10 +48,12 @@ int getfd (int remote_fd); server (int fd) - : read_ev (this, &server::read_cb), - log_cb (this, &server::log_msg), - getfd_cb (this, &server::getfd) { + read_ev.set (this); + log_cb.set (this); + getfd_cb.set (this); + + this->fd = fd; fcntl (fd, F_SETFD, FD_CLOEXEC); fcntl (fd, F_SETFL, 0); read_ev.start (fd, ev::READ); @@ -69,8 +71,9 @@ }; unix_listener::unix_listener (const char *sockname) -: accept_ev (this, &unix_listener::accept_cb) { + accept_ev.set (this); + sockaddr_un sa; if (strlen (sockname) >= sizeof(sa.sun_path)) @@ -171,16 +174,6 @@ break; else if (!strcmp (tok, "ENV") && recv (tok)) envv->push_back (strdup (tok)); - else if (!strcmp (tok, "CWD") && recv (tok)) - { - if (chdir (tok)) - { - delete envv; - delete argv; - return err ("unable to change to working directory to '%s', aborting: %s.\n", - (char *)tok, strerror (errno)); - } - } else if (!strcmp (tok, "ARG") && recv (tok)) argv->push_back (strdup (tok)); else @@ -195,11 +188,11 @@ term->log_hook = &log_cb; term->getfd_hook = &getfd_cb; - bool success; + bool success = true; try { - success = term->init (argv, envv); + term->init (argv, envv); } catch (const class rxvt_failure_exception &e) { @@ -208,7 +201,7 @@ term->log_hook = 0; - chdir ("/"); + chdir ("/"); // init might change to different working directory if (!success) term->destroy (); @@ -245,14 +238,16 @@ } } - chdir ("/"); - + // optionally open display and never release it. if (opt_opendisplay) - displays.get (getenv ("DISPLAY")); // open display and never release it + if (const char *dpy = getenv ("DISPLAY")) + displays.get (dpy ? dpy : ":0"); // move string logic into rxvt_display maybe? char *sockname = rxvt_connection::unix_sockname (); unix_listener l (sockname); + chdir ("/"); + if (!opt_quiet) { printf ("rxvt-unicode daemon listening on %s.\n", sockname); @@ -272,9 +267,11 @@ } else if (pid > 0) _exit (EXIT_SUCCESS); + + ev_default_fork (); } - ev::ev_loop (0); + ev_loop (0); return EXIT_SUCCESS; }