diff options
author | Mark Laws <mdl@60hz.org> | 2015-02-27 12:43:30 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2015-02-27 12:43:30 +0200 |
commit | 805fe507087b9675a010a30a8a8840587ffdf5be (patch) | |
tree | 9b91858096495590692d1f5fe814cb64d9712f8b /src/emacs.c | |
parent | 6ef14349fa73922473ba8202e256f20e17661b25 (diff) | |
download | emacs-805fe507087b9675a010a30a8a8840587ffdf5be.tar.gz |
Support daemon mode on MS-Windows (bug#19688)
src/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.
src/lisp.h (DAEMON_RUNNING): New macro, encapsulates Posix and
MS-Windows conditions for running in daemon mode.
src/minibuf.c (read_minibuf): Use DAEMON_RUNNING.
src/keyboard.c (kbd_buffer_get_event): Use DAEMON_RUNNING.
src/dispnew.c (init_display) [WINDOWSNT]: Initialize frames/terminal
even in daemon mode.
nt/inc/ms-w32.h (W32_DAEMON_EVENT): New macro.
lib-src/emacsclient.c (decode_options) [WINDOWSNT]: Don't reject empty
arguments for --alternate-editor.
(print_help_and_exit) [WINDOWSNT]: Don't refrain from advertising
empty arguments for --alternate-editor.
(start_daemon_and_retry_set_socket) [WINDOWSNT]: MS-Windows
specific code to start Emacs in daemon mode and wait for it to be
ready for client connections.
lisp/server.el (server-process-filter): Force GUI frames on
MS-Windows in daemon mode, even if a TTY frame was requested.
lisp/frameset.el (frameset-keep-original-display-p): Don't assume
windows-nt cannot be in daemon mode.
lisp/frame.el (window-system-for-display): Don't assume windows-nt
cannot be in daemon mode.
Diffstat (limited to 'src/emacs.c')
-rw-r--r-- | src/emacs.c | 37 |
1 files changed, 31 insertions, 6 deletions
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"); |