summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog20
-rw-r--r--src/dispnew.c5
-rw-r--r--src/emacs.c37
-rw-r--r--src/keyboard.c2
-rw-r--r--src/lisp.h9
-rw-r--r--src/minibuf.c2
6 files changed, 65 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index bf4043666c6..61bb321649f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,23 @@
+2015-02-27 Mark Laws <mdl@60hz.org>
+
+ Support daemon mode on MS-Windows (bug#19688)
+ * emacs.c <w32_daemon_event> [WINDOWSNT]: New global var.
+ (main) [WINDOWSNT]: Initialize it to NULL. Create the event to
+ signal clients we are ready for connections.
+ (Fdaemon_initialized): Use DAEMON_RUNNING.
+ [WINDOWSNT]: MS-Windows specific code to signal clients we are
+ ready for connections.
+
+ * lisp.h (DAEMON_RUNNING): New macro, encapsulates Posix and
+ MS-Windows conditions for running in daemon mode.
+
+ * minibuf.c (read_minibuf): Use DAEMON_RUNNING.
+
+ * keyboard.c (kbd_buffer_get_event): Use DAEMON_RUNNING.
+
+ * dispnew.c (init_display) [WINDOWSNT]: Initialize frames/terminal
+ even in daemon mode.
+
2015-02-26 Jan Djärv <jan.h.d@swipnet.se>
* xmenu.c (create_and_show_popup_menu): Call XTranslateCoordinates,
diff --git a/src/dispnew.c b/src/dispnew.c
index a1782913154..6bc24697cb7 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5949,9 +5949,12 @@ init_display (void)
}
#endif /* SIGWINCH */
- /* If running as a daemon, no need to initialize any frames/terminal. */
+ /* If running as a daemon, no need to initialize any frames/terminal,
+ except on Windows, where we at least want to initialize it. */
+#ifndef WINDOWSNT
if (IS_DAEMON)
return;
+#endif
/* If the user wants to use a window system, we shouldn't bother
initializing the terminal. This is especially important when the
diff --git a/src/emacs.c b/src/emacs.c
index cb0c8417794..ca5633da2dd 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -195,9 +195,13 @@ bool no_site_lisp;
/* Name for the server started by the daemon.*/
static char *daemon_name;
+#ifndef WINDOWSNT
/* Pipe used to send exit notification to the daemon parent at
startup. */
int daemon_pipe[2];
+#else
+HANDLE w32_daemon_event;
+#endif
/* Save argv and argc. */
char **initial_argv;
@@ -982,8 +986,12 @@ main (int argc, char **argv)
exit (0);
}
+#ifndef WINDOWSNT
/* Make sure IS_DAEMON starts up as false. */
daemon_pipe[1] = 0;
+#else
+ w32_daemon_event = NULL;
+#endif
if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
|| argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args))
@@ -1107,16 +1115,25 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
}
#endif /* DAEMON_MUST_EXEC */
- if (dname_arg)
- daemon_name = xstrdup (dname_arg);
/* Close unused reading end of the pipe. */
emacs_close (daemon_pipe[0]);
setsid ();
-#else /* DOS_NT */
+#elif defined(WINDOWSNT)
+ /* Indicate that we want daemon mode. */
+ w32_daemon_event = CreateEvent (NULL, TRUE, FALSE, W32_DAEMON_EVENT);
+ if (w32_daemon_event == NULL)
+ {
+ fprintf (stderr, "Couldn't create MS-Windows event for daemon: %s\n",
+ w32_strerror (0));
+ exit (1);
+ }
+#else /* MSDOS */
fprintf (stderr, "This platform does not support the -daemon flag.\n");
exit (1);
-#endif /* DOS_NT */
+#endif /* MSDOS */
+ if (dname_arg)
+ daemon_name = xstrdup (dname_arg);
}
#if defined HAVE_PTHREAD && !defined SYSTEM_MALLOC \
@@ -2313,17 +2330,18 @@ This finishes the daemonization process by doing the other half of detaching
from the parent process and its tty file descriptors. */)
(void)
{
- int nfd;
bool err = 0;
if (!IS_DAEMON)
error ("This function can only be called if emacs is run as a daemon");
- if (daemon_pipe[1] < 0)
+ if (!DAEMON_RUNNING)
error ("The daemon has already been initialized");
if (NILP (Vafter_init_time))
error ("This function can only be called after loading the init files");
+#ifndef WINDOWSNT
+ int nfd;
/* Get rid of stdin, stdout and stderr. */
nfd = emacs_open ("/dev/null", O_RDWR, 0);
@@ -2344,6 +2362,13 @@ from the parent process and its tty file descriptors. */)
err |= emacs_close (daemon_pipe[1]) != 0;
/* Set it to an invalid value so we know we've already run this function. */
daemon_pipe[1] = -1;
+#else /* WINDOWSNT */
+ /* Signal the waiting emacsclient process. */
+ err |= SetEvent (w32_daemon_event) == 0;
+ err |= CloseHandle (w32_daemon_event) == 0;
+ /* Set it to an invalid value so we know we've already run this function. */
+ w32_daemon_event = INVALID_HANDLE_VALUE;
+#endif
if (err)
error ("I/O error during daemon initialization");
diff --git a/src/keyboard.c b/src/keyboard.c
index c2174539ea7..e1c5691324d 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3853,7 +3853,7 @@ kbd_buffer_get_event (KBOARD **kbp,
if (noninteractive
/* In case we are running as a daemon, only do this before
detaching from the terminal. */
- || (IS_DAEMON && daemon_pipe[1] >= 0))
+ || (IS_DAEMON && DAEMON_RUNNING))
{
int c = getchar ();
XSETINT (obj, c);
diff --git a/src/lisp.h b/src/lisp.h
index 9764b096ef0..fb436776121 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4222,9 +4222,16 @@ extern bool noninteractive;
extern bool no_site_lisp;
/* Pipe used to send exit notification to the daemon parent at
- startup. */
+ startup. On Windows, we use a kernel event instead. */
+#ifndef WINDOWSNT
extern int daemon_pipe[2];
#define IS_DAEMON (daemon_pipe[1] != 0)
+#define DAEMON_RUNNING (daemon_pipe[1] >= 0)
+#else /* WINDOWSNT */
+extern void *w32_daemon_event;
+#define IS_DAEMON (w32_daemon_event != NULL)
+#define DAEMON_RUNNING (w32_daemon_event != INVALID_HANDLE_VALUE)
+#endif
/* True if handling a fatal error already. */
extern bool fatal_error_in_progress;
diff --git a/src/minibuf.c b/src/minibuf.c
index 2dc5c544457..e7c288b251b 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -459,7 +459,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
if ((noninteractive
/* In case we are running as a daemon, only do this before
detaching from the terminal. */
- || (IS_DAEMON && (daemon_pipe[1] >= 0)))
+ || (IS_DAEMON && DAEMON_RUNNING))
&& NILP (Vexecuting_kbd_macro))
{
val = read_minibuf_noninteractive (map, initial, prompt,