From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#19688: [patch] add support for emacs daemon on Windows Date: Sun, 25 Jan 2015 22:34:10 +0200 Message-ID: <83h9ver459.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1422218119 22559 80.91.229.3 (25 Jan 2015 20:35:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Jan 2015 20:35:19 +0000 (UTC) Cc: 19688@debbugs.gnu.org To: Mark Laws Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 25 21:35:15 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YFTto-0002PA-Jq for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Jan 2015 21:35:12 +0100 Original-Received: from localhost ([::1]:38820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFTto-00044P-3N for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Jan 2015 15:35:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFTtj-0003zc-6O for bug-gnu-emacs@gnu.org; Sun, 25 Jan 2015 15:35:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFTtf-00072K-68 for bug-gnu-emacs@gnu.org; Sun, 25 Jan 2015 15:35:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFTtf-000725-3G for bug-gnu-emacs@gnu.org; Sun, 25 Jan 2015 15:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YFTte-000853-Lt for bug-gnu-emacs@gnu.org; Sun, 25 Jan 2015 15:35:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Jan 2015 20:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19688 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 19688-submit@debbugs.gnu.org id=B19688.142221807731019 (code B ref 19688); Sun, 25 Jan 2015 20:35:02 +0000 Original-Received: (at 19688) by debbugs.gnu.org; 25 Jan 2015 20:34:37 +0000 Original-Received: from localhost ([127.0.0.1]:56258 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YFTtE-00084E-3n for submit@debbugs.gnu.org; Sun, 25 Jan 2015 15:34:36 -0500 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:33182) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YFTtA-00083w-RE for 19688@debbugs.gnu.org; Sun, 25 Jan 2015 15:34:34 -0500 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0NIR00H002A79Z00@a-mtaout22.012.net.il> for 19688@debbugs.gnu.org; Sun, 25 Jan 2015 22:34:25 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NIR00GK32HDVM80@a-mtaout22.012.net.il>; Sun, 25 Jan 2015 22:34:25 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:98727 Archived-At: > Date: Mon, 26 Jan 2015 04:18:34 +0900 > From: Mark Laws > > Attached is a patch which should apply cleanly on top of master > (a3689d3c661fe36df971c875760f8d500b5ae994 as of this email). It allows > Emacs to run as a daemon on Windows. Without daemon mode, emacsclient > -a "" does not work, which makes it impossible to pass elisp to Emacs > via emacsclient unless Emacs is already running. In other words, this > will now work correctly: > > emacsclient -a "" -e "(ediff-merge-files-with-ancestor ...)" Thanks. Did you get your paperwork with the FSF clerk done? I don't see your assignment on file yet. > +#define W32_EMACS_SERVER_GUID "{0B8E5DCB-D7CF-4423-A9F1-2F6927F0D318}" Where did this GUID come from? In any case, instead of adding a one-line header file, it is better to put this on nt/inc/ms-w32.h, which is included by both emacsclient.c and all src/*.c files via src/config.h. > +#ifndef WINDOWSNT > /* Pipe used to send exit notification to the daemon parent at > startup. */ > int daemon_pipe[2]; > +#else > +bool w32_is_daemon; > +bool w32_daemon_is_initialized; > +static HANDLE w32_daemon_event; > +#endif Why do we need anything beyond the event handle? Can't it serve double duty as a flag as well? We could use INVALID_HANDLE_VALUE and/or NULL as distinct values with specific meanings. > +#ifndef WINDOWSNT > /* Make sure IS_DAEMON starts up as false. */ > daemon_pipe[1] = 0; > +#endif You should do a similar initialization on WINDOWSNT, to avoid using the value that was initialized when Emacs was dumped. > +#ifdef WINDOWSNT > + daemon_check_preconditions (); > + > + w32_daemon_event = CreateEvent (NULL, TRUE, FALSE, W32_EMACS_SERVER_GUID); > + if (w32_daemon_event == NULL) > + error ("Couldn't create event for Windows daemon"); > + if (GetLastError () == ERROR_ALREADY_EXISTS) > + /* Signal the waiting emacsclient process. */ > + SetEvent (w32_daemon_event); > + CloseHandle (w32_daemon_event); > + w32_daemon_is_initialized = true; > +#else Please move this code to a function in w32.c, and here just call that function. Also, the call to daemon_check_preconditions should be outside of the #ifdef, as it is used on all platforms.