From 4ff029f613a6f9a4bd54bf3b3e7763c25a510045 Mon Sep 17 00:00:00 2001 From: Dan Nicolaescu Date: Mon, 27 Oct 2008 07:02:30 +0000 Subject: [PATCH] * emacs.c (daemon_name): New variable. (main): Deal with --daemon=SERVER_NAME. (Fdaemonp): Return a name if one was passed to --daemon. * startup.el (server-name): Pacify byte compiler. (command-line): If --daemon=SERVER_NAME was used, set server-name before calling server-start. * cmdargs.texi (Initial Options): Document -daemon=SERVER_NAME. --- doc/emacs/ChangeLog | 4 ++++ doc/emacs/cmdargs.texi | 4 ++++ lisp/ChangeLog | 6 ++++++ lisp/startup.el | 10 +++++++--- src/ChangeLog | 6 ++++++ src/emacs.c | 19 ++++++++++++++++--- 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 7f1cf1b78e0..fbbe7ec0ed3 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,7 @@ +2008-10-27 Dan Nicolaescu + + * cmdargs.texi (Initial Options): Document -daemon=SERVER_NAME. + 2008-10-23 Chong Yidong * custom.texi (Function Keys): Note that modified keypad keys are not diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi index 94e69bcdfe8..6be6a983461 100644 --- a/doc/emacs/cmdargs.texi +++ b/doc/emacs/cmdargs.texi @@ -286,6 +286,10 @@ terminal), do not open any frames and start the server. Clients can connect and create graphical or terminal frames using @code{emacsclient}. +@item -daemon=@var{SERVER-NAME} +Start emacs in background as a daemon, and start the server with the +name set to @var{SERVER-NAME}. + @item --no-splash @opindex --no-splash @vindex inhibit-startup-screen diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9175fe33918..0efd40b7fad 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2008-10-27 Dan Nicolaescu + + * startup.el (server-name): Pacify byte compiler. + (command-line): If --daemon=SERVER_NAME was used, set server-name + before calling server-start. + 2008-10-26 Romain Francoise * startup.el (command-line): Call daemon-initialized after diff --git a/lisp/startup.el b/lisp/startup.el index 7b7fbb2fd68..2d7995a1c0b 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -693,6 +693,8 @@ opening the first frame (e.g. open a connection to an X server).") (declare-function tool-bar-mode "tool-bar" (&optional arg)) (declare-function tool-bar-setup "tool-bar") +(defvar server-name) + (defun command-line () (setq before-init-time (current-time) after-init-time nil @@ -1212,9 +1214,11 @@ the `--debug-init' option to view a complete error backtrace." ;; This is done after loading the user's init file and after ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. - (when (daemonp) - (server-start) - (daemon-initialized)) + (let ((dn (daemonp))) + (when dn + (when (stringp dn) (setq server-name dn)) + (server-start) + (daemon-initialized))) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. diff --git a/src/ChangeLog b/src/ChangeLog index 4de35db502f..6379e86b9e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2008-10-27 Dan Nicolaescu + + * emacs.c (daemon_name): New variable. + (main): Deal with --daemon=SERVER_NAME. + (Fdaemonp): Return a name if one was passed to --daemon. + 2008-10-26 Romain Francoise * emacs.c (daemon_pipe): New variable. diff --git a/src/emacs.c b/src/emacs.c index bcc7fb05792..6f54291a514 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -237,6 +237,8 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Name for the server started by the daemon.*/ +static char *daemon_name; /* Pipe used to send exit notification to the daemon parent at startup. */ @@ -796,6 +798,7 @@ main (int argc, char **argv) #endif int no_loadup = 0; char *junk = 0; + char *dname_arg = 0; #if GC_MARK_STACK extern Lisp_Object *stack_base; @@ -1074,7 +1077,8 @@ main (int argc, char **argv) exit (0); } - if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) + if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args) + || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args)) { #ifndef DOS_NT pid_t f; @@ -1123,6 +1127,8 @@ main (int argc, char **argv) exit (1); } + if (dname_arg) + daemon_name = xstrdup (dname_arg); /* Close unused reading end of the pipe. */ close (daemon_pipe[0]); is_daemon = 1; @@ -2419,10 +2425,17 @@ decode_env_path (evarname, defalt) } DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, - doc: /* Return t if the current emacs process is a daemon. */) + doc: /* Return non-nil if the current emacs process is a daemon. +If the daemon was given a name argument, return that name. */) () { - return is_daemon ? Qt : Qnil; + if (is_daemon) + if (daemon_name) + return build_string (daemon_name); + else + return Qt; + else + return Qnil; } DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0, -- 2.39.2