From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: start emacs without creating frames and connect with emacsclient later Date: Mon, 01 Sep 2008 07:02:21 -0700 Message-ID: <200809011402.m81E2LSf020327@sallyv1.ics.uci.edu> References: <200808131610.m7DGAkvk020047@sallyv1.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1220278084 24923 80.91.229.12 (1 Sep 2008 14:08:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Sep 2008 14:08:04 +0000 (UTC) Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 01 16:08:59 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KaA3k-0001G7-NB for ged-emacs-devel@m.gmane.org; Mon, 01 Sep 2008 16:07:13 +0200 Original-Received: from localhost ([127.0.0.1]:53893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KaA2h-00027c-2x for ged-emacs-devel@m.gmane.org; Mon, 01 Sep 2008 10:06:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KaA23-0001r8-ME for emacs-devel@gnu.org; Mon, 01 Sep 2008 10:05:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KaA21-0001pz-Af for emacs-devel@gnu.org; Mon, 01 Sep 2008 10:05:26 -0400 Original-Received: from [199.232.76.173] (port=46686 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KaA21-0001pt-26 for emacs-devel@gnu.org; Mon, 01 Sep 2008 10:05:25 -0400 Original-Received: from sallyv1.ics.uci.edu ([128.195.1.109]:64487) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1KaA1s-0001TS-FJ; Mon, 01 Sep 2008 10:05:18 -0400 X-ICS-MailScanner-Watermark: 1220882545.41286@XzKguPXXLfmITNS+z5BMSA Original-Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv1.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m81E2LSf020327; Mon, 1 Sep 2008 07:02:21 -0700 (PDT) In-Reply-To: (Richard M. Stallman's message of "Thu, 14 Aug 2008 01:19:05 -0400") Original-Lines: 160 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-0.263, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FM_MULTI_ODD2 1.10, TW_RG 0.08) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103368 Archived-At: "Richard M. Stallman" writes: > Should something like this go in? We do have a feature freeze, but this > is quite simple, and it completes the multi-tty functionality, which is > one of the major features of 23.1. > > I think it should go in > provided you write the text for etc/NEWS AND all the relevant manuals. I got a lot of private emails from people very happy to use this feature. And some people actually want to distribute the patch. So here's an updated version including documentation. Index: doc/emacs/cmdargs.texi =================================================================== RCS file: /cvsroot/emacs/emacs/doc/emacs/cmdargs.texi,v retrieving revision 1.3 diff -u -3 -p -r1.3 cmdargs.texi --- doc/emacs/cmdargs.texi 22 Jan 2008 23:53:34 -0000 1.3 +++ doc/emacs/cmdargs.texi 1 Sep 2008 13:56:17 -0000 @@ -277,6 +277,15 @@ option and @samp{-Q} are the only option Start emacs with minimum customizations. This is like using @samp{-q} and @samp{--no-site-file}, but also disables the startup screen. +@item -daemon +@opindex -daemon +@itemx --daemon +@opindex --daemon +Start emacs in background as a daemon (i.e. it will disconnect from the +terminal), do not open any frames and start the server. Clients can +connect and create graphical or terminal frames using +@code{emacsclient}. + @item --no-splash @opindex --no-splash @vindex inhibit-splash-screen Index: etc/NEWS =================================================================== RCS file: /cvsroot/emacs/emacs/etc/NEWS,v retrieving revision 1.1843 diff -u -3 -p -r1.1843 NEWS --- etc/NEWS 31 Aug 2008 02:13:38 -0000 1.1843 +++ etc/NEWS 1 Sep 2008 13:56:17 -0000 @@ -130,6 +130,11 @@ Now, the default behavior is to open a n Use the -c option to get the old behavior of opening files in the currently selected Emacs frame. +*** Emacs can now start in background, as a daemon when using the +--daemon command line argument. It disconnects from the terminal and +starts the server. Clients can connect and create graphical or +terminal frames using emacsclient. + *** The new command close-display-connection closes a connection to a remote display. Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.503 diff -u -3 -p -r1.503 startup.el --- lisp/startup.el 23 Aug 2008 16:59:19 -0000 1.503 +++ lisp/startup.el 1 Sep 2008 13:56:17 -0000 @@ -881,9 +881,11 @@ opening the first frame (e.g. open a con (run-hooks 'before-init-hook) - ;; Under X Window, this creates the X frame and deletes the terminal frame. - (when (fboundp 'frame-initialize) - (frame-initialize)) + (if (daemonp) + (server-start) + ;; Under X Window, this creates the X frame and deletes the terminal frame. + (when (and (fboundp 'frame-initialize)) + (frame-initialize))) ;; Turn off blinking cursor if so specified in X resources. This is here ;; only because all other settings of no-blinking-cursor are here. Index: src/emacs.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/emacs.c,v retrieving revision 1.443 diff -u -3 -p -r1.443 emacs.c --- src/emacs.c 23 Aug 2008 16:45:13 -0000 1.443 +++ src/emacs.c 1 Sep 2008 13:56:18 -0000 @@ -232,6 +232,9 @@ int noninteractive; int noninteractive1; +/* Nonzero means Emacs was started as a daemon. */ +int is_daemon = 0; + /* Save argv and argc. */ char **initial_argv; int initial_argc; @@ -1068,6 +1071,34 @@ main (int argc, char **argv) exit (0); } +#ifndef DOS_NT + if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) + { + pid_t f = fork(); + int nfd; + if (f > 0) + exit(0); + if (f < 0) + { + fprintf (stderr, "Cannot fork!\n"); + exit(1); + } + + nfd = open("/dev/null", O_RDWR); + dup2(nfd, 0); + dup2(nfd, 1); + dup2(nfd, 2); + close (nfd); + is_daemon = 1; +#ifdef HAVE_SETSID + setsid(); +#endif + } +#else /* DOS_NT */ + fprintf (stderr, "This platform does not support the -daemon flag.\n"); + exit (1); +#endif /* DOS_NT */ + if (! noninteractive) { #ifdef BSD_PGRPS @@ -1719,6 +1750,7 @@ struct standard_args standard_args[] = { "-nw", "--no-windows", 110, 0 }, { "-batch", "--batch", 100, 0 }, { "-script", "--script", 100, 1 }, + { "-daemon", "--daemon", 99, 0 }, { "-help", "--help", 90, 0 }, { "-no-unibyte", "--no-unibyte", 83, 0 }, { "-multibyte", "--multibyte", 82, 0 }, @@ -2350,6 +2382,13 @@ decode_env_path (evarname, defalt) return Fnreverse (lpath); } +DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, + doc: /* Make the current emacs process a daemon.*/) + (void) +{ + return is_daemon ? Qt : Qnil; +} + void syms_of_emacs () { @@ -2368,6 +2407,7 @@ syms_of_emacs () defsubr (&Sinvocation_name); defsubr (&Sinvocation_directory); + defsubr (&Sdaemonp); DEFVAR_LISP ("command-line-args", &Vcommand_line_args, doc: /* Args passed by shell to Emacs, as a list of strings.