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: Thu, 21 Aug 2008 10:20:28 -0700 Message-ID: <200808211720.m7LHKSne001960@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 1219339375 14427 80.91.229.12 (21 Aug 2008 17:22:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Aug 2008 17:22:55 +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 Thu Aug 21 19:23:47 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 1KWDsv-0007X0-9F for ged-emacs-devel@m.gmane.org; Thu, 21 Aug 2008 19:23:45 +0200 Original-Received: from localhost ([127.0.0.1]:33666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWDrx-0004zE-Pq for ged-emacs-devel@m.gmane.org; Thu, 21 Aug 2008 13:22:45 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KWDrs-0004uY-Gn for emacs-devel@gnu.org; Thu, 21 Aug 2008 13:22:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KWDrp-0004lB-4n for emacs-devel@gnu.org; Thu, 21 Aug 2008 13:22:39 -0400 Original-Received: from [199.232.76.173] (port=40467 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWDro-0004kj-SS for emacs-devel@gnu.org; Thu, 21 Aug 2008 13:22:36 -0400 Original-Received: from sallyv1.ics.uci.edu ([128.195.1.109]:58030) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1KWDrk-0003Q9-4g; Thu, 21 Aug 2008 13:22:32 -0400 X-ICS-MailScanner-Watermark: 1219944031.617@lo0N03GKZATmFWX28XfI3g 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 m7LHKSne001960; Thu, 21 Aug 2008 10:20:29 -0700 (PDT) In-Reply-To: (Richard M. Stallman's message of "Thu, 14 Aug 2008 01:19:05 -0400") Original-Lines: 110 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:102786 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'll update the all the docs whenever it gets checked in. Here's a new version of the patch, now it has code to detach from the terminal, so it is a real daemon (how scary, emacs is haunted by daemons now). Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.502 diff -u -3 -p -r1.502 startup.el --- lisp/startup.el 7 Aug 2008 03:10:08 -0000 1.502 +++ lisp/startup.el 21 Aug 2008 16:55:54 -0000 @@ -877,9 +877,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.442 diff -u -3 -p -r1.442 emacs.c --- src/emacs.c 5 Aug 2008 17:33:05 -0000 1.442 +++ src/emacs.c 21 Aug 2008 16:55:54 -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 +1070,25 @@ main (int argc, char **argv) exit (0); } + if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) + { + pid_t f = fork(); + if (f > 0) + exit(0); + if (f < 0) + { + fprintf (stderr, "Cannot fork!\n"); + exit(1); + } + close(0); + close(1); + close(2); + is_daemon = 1; +#ifdef HAVE_SETSID + setsid(); +#endif + } + if (! noninteractive) { #ifdef BSD_PGRPS @@ -1715,6 +1736,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 }, @@ -2346,6 +2368,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 () { @@ -2364,6 +2393,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.