aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Laws2015-02-27 12:43:30 +0200
committerEli Zaretskii2015-02-27 12:43:30 +0200
commit805fe507087b9675a010a30a8a8840587ffdf5be (patch)
tree9b91858096495590692d1f5fe814cb64d9712f8b /src
parent6ef14349fa73922473ba8202e256f20e17661b25 (diff)
downloademacs-805fe507087b9675a010a30a8a8840587ffdf5be.tar.gz
emacs-805fe507087b9675a010a30a8a8840587ffdf5be.zip
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')
-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 @@
12015-02-27 Mark Laws <mdl@60hz.org>
2
3 Support daemon mode on MS-Windows (bug#19688)
4 * emacs.c <w32_daemon_event> [WINDOWSNT]: New global var.
5 (main) [WINDOWSNT]: Initialize it to NULL. Create the event to
6 signal clients we are ready for connections.
7 (Fdaemon_initialized): Use DAEMON_RUNNING.
8 [WINDOWSNT]: MS-Windows specific code to signal clients we are
9 ready for connections.
10
11 * lisp.h (DAEMON_RUNNING): New macro, encapsulates Posix and
12 MS-Windows conditions for running in daemon mode.
13
14 * minibuf.c (read_minibuf): Use DAEMON_RUNNING.
15
16 * keyboard.c (kbd_buffer_get_event): Use DAEMON_RUNNING.
17
18 * dispnew.c (init_display) [WINDOWSNT]: Initialize frames/terminal
19 even in daemon mode.
20
12015-02-26 Jan Djärv <jan.h.d@swipnet.se> 212015-02-26 Jan Djärv <jan.h.d@swipnet.se>
2 22
3 * xmenu.c (create_and_show_popup_menu): Call XTranslateCoordinates, 23 * 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)
5949 } 5949 }
5950#endif /* SIGWINCH */ 5950#endif /* SIGWINCH */
5951 5951
5952 /* If running as a daemon, no need to initialize any frames/terminal. */ 5952 /* If running as a daemon, no need to initialize any frames/terminal,
5953 except on Windows, where we at least want to initialize it. */
5954#ifndef WINDOWSNT
5953 if (IS_DAEMON) 5955 if (IS_DAEMON)
5954 return; 5956 return;
5957#endif
5955 5958
5956 /* If the user wants to use a window system, we shouldn't bother 5959 /* If the user wants to use a window system, we shouldn't bother
5957 initializing the terminal. This is especially important when the 5960 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;
195/* Name for the server started by the daemon.*/ 195/* Name for the server started by the daemon.*/
196static char *daemon_name; 196static char *daemon_name;
197 197
198#ifndef WINDOWSNT
198/* Pipe used to send exit notification to the daemon parent at 199/* Pipe used to send exit notification to the daemon parent at
199 startup. */ 200 startup. */
200int daemon_pipe[2]; 201int daemon_pipe[2];
202#else
203HANDLE w32_daemon_event;
204#endif
201 205
202/* Save argv and argc. */ 206/* Save argv and argc. */
203char **initial_argv; 207char **initial_argv;
@@ -982,8 +986,12 @@ main (int argc, char **argv)
982 exit (0); 986 exit (0);
983 } 987 }
984 988
989#ifndef WINDOWSNT
985 /* Make sure IS_DAEMON starts up as false. */ 990 /* Make sure IS_DAEMON starts up as false. */
986 daemon_pipe[1] = 0; 991 daemon_pipe[1] = 0;
992#else
993 w32_daemon_event = NULL;
994#endif
987 995
988 if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args) 996 if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
989 || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args)) 997 || 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
1107 } 1115 }
1108#endif /* DAEMON_MUST_EXEC */ 1116#endif /* DAEMON_MUST_EXEC */
1109 1117
1110 if (dname_arg)
1111 daemon_name = xstrdup (dname_arg);
1112 /* Close unused reading end of the pipe. */ 1118 /* Close unused reading end of the pipe. */
1113 emacs_close (daemon_pipe[0]); 1119 emacs_close (daemon_pipe[0]);
1114 1120
1115 setsid (); 1121 setsid ();
1116#else /* DOS_NT */ 1122#elif defined(WINDOWSNT)
1123 /* Indicate that we want daemon mode. */
1124 w32_daemon_event = CreateEvent (NULL, TRUE, FALSE, W32_DAEMON_EVENT);
1125 if (w32_daemon_event == NULL)
1126 {
1127 fprintf (stderr, "Couldn't create MS-Windows event for daemon: %s\n",
1128 w32_strerror (0));
1129 exit (1);
1130 }
1131#else /* MSDOS */
1117 fprintf (stderr, "This platform does not support the -daemon flag.\n"); 1132 fprintf (stderr, "This platform does not support the -daemon flag.\n");
1118 exit (1); 1133 exit (1);
1119#endif /* DOS_NT */ 1134#endif /* MSDOS */
1135 if (dname_arg)
1136 daemon_name = xstrdup (dname_arg);
1120 } 1137 }
1121 1138
1122#if defined HAVE_PTHREAD && !defined SYSTEM_MALLOC \ 1139#if defined HAVE_PTHREAD && !defined SYSTEM_MALLOC \
@@ -2313,17 +2330,18 @@ This finishes the daemonization process by doing the other half of detaching
2313from the parent process and its tty file descriptors. */) 2330from the parent process and its tty file descriptors. */)
2314 (void) 2331 (void)
2315{ 2332{
2316 int nfd;
2317 bool err = 0; 2333 bool err = 0;
2318 2334
2319 if (!IS_DAEMON) 2335 if (!IS_DAEMON)
2320 error ("This function can only be called if emacs is run as a daemon"); 2336 error ("This function can only be called if emacs is run as a daemon");
2321 2337
2322 if (daemon_pipe[1] < 0) 2338 if (!DAEMON_RUNNING)
2323 error ("The daemon has already been initialized"); 2339 error ("The daemon has already been initialized");
2324 2340
2325 if (NILP (Vafter_init_time)) 2341 if (NILP (Vafter_init_time))
2326 error ("This function can only be called after loading the init files"); 2342 error ("This function can only be called after loading the init files");
2343#ifndef WINDOWSNT
2344 int nfd;
2327 2345
2328 /* Get rid of stdin, stdout and stderr. */ 2346 /* Get rid of stdin, stdout and stderr. */
2329 nfd = emacs_open ("/dev/null", O_RDWR, 0); 2347 nfd = emacs_open ("/dev/null", O_RDWR, 0);
@@ -2344,6 +2362,13 @@ from the parent process and its tty file descriptors. */)
2344 err |= emacs_close (daemon_pipe[1]) != 0; 2362 err |= emacs_close (daemon_pipe[1]) != 0;
2345 /* Set it to an invalid value so we know we've already run this function. */ 2363 /* Set it to an invalid value so we know we've already run this function. */
2346 daemon_pipe[1] = -1; 2364 daemon_pipe[1] = -1;
2365#else /* WINDOWSNT */
2366 /* Signal the waiting emacsclient process. */
2367 err |= SetEvent (w32_daemon_event) == 0;
2368 err |= CloseHandle (w32_daemon_event) == 0;
2369 /* Set it to an invalid value so we know we've already run this function. */
2370 w32_daemon_event = INVALID_HANDLE_VALUE;
2371#endif
2347 2372
2348 if (err) 2373 if (err)
2349 error ("I/O error during daemon initialization"); 2374 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,
3853 if (noninteractive 3853 if (noninteractive
3854 /* In case we are running as a daemon, only do this before 3854 /* In case we are running as a daemon, only do this before
3855 detaching from the terminal. */ 3855 detaching from the terminal. */
3856 || (IS_DAEMON && daemon_pipe[1] >= 0)) 3856 || (IS_DAEMON && DAEMON_RUNNING))
3857 { 3857 {
3858 int c = getchar (); 3858 int c = getchar ();
3859 XSETINT (obj, c); 3859 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;
4222extern bool no_site_lisp; 4222extern bool no_site_lisp;
4223 4223
4224/* Pipe used to send exit notification to the daemon parent at 4224/* Pipe used to send exit notification to the daemon parent at
4225 startup. */ 4225 startup. On Windows, we use a kernel event instead. */
4226#ifndef WINDOWSNT
4226extern int daemon_pipe[2]; 4227extern int daemon_pipe[2];
4227#define IS_DAEMON (daemon_pipe[1] != 0) 4228#define IS_DAEMON (daemon_pipe[1] != 0)
4229#define DAEMON_RUNNING (daemon_pipe[1] >= 0)
4230#else /* WINDOWSNT */
4231extern void *w32_daemon_event;
4232#define IS_DAEMON (w32_daemon_event != NULL)
4233#define DAEMON_RUNNING (w32_daemon_event != INVALID_HANDLE_VALUE)
4234#endif
4228 4235
4229/* True if handling a fatal error already. */ 4236/* True if handling a fatal error already. */
4230extern bool fatal_error_in_progress; 4237extern 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,
459 if ((noninteractive 459 if ((noninteractive
460 /* In case we are running as a daemon, only do this before 460 /* In case we are running as a daemon, only do this before
461 detaching from the terminal. */ 461 detaching from the terminal. */
462 || (IS_DAEMON && (daemon_pipe[1] >= 0))) 462 || (IS_DAEMON && DAEMON_RUNNING))
463 && NILP (Vexecuting_kbd_macro)) 463 && NILP (Vexecuting_kbd_macro))
464 { 464 {
465 val = read_minibuf_noninteractive (map, initial, prompt, 465 val = read_minibuf_noninteractive (map, initial, prompt,