aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog11
-rw-r--r--lib-src/emacsclient.c81
2 files changed, 82 insertions, 10 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 5c55bcea506..83855afa675 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,14 @@
12015-02-27 Mark Laws <mdl@60hz.org>
2
3 Support daemon mode on MS-Windows (bug#19688)
4 * emacsclient.c (decode_options) [WINDOWSNT]: Don't reject empty
5 arguments for --alternate-editor.
6 (print_help_and_exit) [WINDOWSNT]: Don't refrain from advertising
7 empty arguments for --alternate-editor.
8 (start_daemon_and_retry_set_socket) [WINDOWSNT]: MS-Windows
9 specific code to start Emacs in daemon mode and wait for it to be
10 ready for client connections.
11
12015-02-23 Pete Williamson <petewil0@googlemail.com> (tiny change) 122015-02-23 Pete Williamson <petewil0@googlemail.com> (tiny change)
2 13
3 Use ${EXEEXT} more uniformly in makefiles 14 Use ${EXEEXT} more uniformly in makefiles
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index a04dda6408f..806275f5b1d 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -595,13 +595,6 @@ decode_options (int argc, char **argv)
595 display = NULL; 595 display = NULL;
596 tty = 1; 596 tty = 1;
597 } 597 }
598
599 if (alternate_editor && alternate_editor[0] == '\0')
600 {
601 message (true, "--alternate-editor argument or ALTERNATE_EDITOR variable cannot be\n\
602an empty string");
603 exit (EXIT_FAILURE);
604 }
605#endif /* WINDOWSNT */ 598#endif /* WINDOWSNT */
606} 599}
607 600
@@ -642,10 +635,8 @@ The following OPTIONS are accepted:\n\
642 Set filename of the TCP authentication file\n\ 635 Set filename of the TCP authentication file\n\
643-a EDITOR, --alternate-editor=EDITOR\n\ 636-a EDITOR, --alternate-editor=EDITOR\n\
644 Editor to fallback to if the server is not running\n" 637 Editor to fallback to if the server is not running\n"
645#ifndef WINDOWSNT
646" If EDITOR is the empty string, start Emacs in daemon\n\ 638" If EDITOR is the empty string, start Emacs in daemon\n\
647 mode and try connecting again\n" 639 mode and try connecting again\n"
648#endif /* not WINDOWSNT */
649"\n\ 640"\n\
650Report bugs with M-x report-emacs-bug.\n"); 641Report bugs with M-x report-emacs-bug.\n");
651 exit (EXIT_SUCCESS); 642 exit (EXIT_SUCCESS);
@@ -1511,7 +1502,77 @@ start_daemon_and_retry_set_socket (void)
1511 execvp ("emacs", d_argv); 1502 execvp ("emacs", d_argv);
1512 message (true, "%s: error starting emacs daemon\n", progname); 1503 message (true, "%s: error starting emacs daemon\n", progname);
1513 } 1504 }
1514#endif /* WINDOWSNT */ 1505#else /* WINDOWSNT */
1506 DWORD wait_result;
1507 HANDLE w32_daemon_event;
1508 STARTUPINFO si;
1509 PROCESS_INFORMATION pi;
1510
1511 ZeroMemory (&si, sizeof si);
1512 si.cb = sizeof si;
1513 ZeroMemory (&pi, sizeof pi);
1514
1515 /* We start Emacs in daemon mode, and then wait for it to signal us
1516 it is ready to accept client connections, by asserting an event
1517 whose name is known to the daemon (defined by nt/inc/ms-w32.h). */
1518
1519 if (!CreateProcess (NULL, "emacs --daemon", NULL, NULL, FALSE,
1520 CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
1521 {
1522 char* msg = NULL;
1523
1524 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
1525 | FORMAT_MESSAGE_ALLOCATE_BUFFER
1526 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
1527 NULL, GetLastError (), 0, (LPTSTR)&msg, 0, NULL);
1528 message (true, "%s: error starting emacs daemon (%s)\n", progname, msg);
1529 exit (EXIT_FAILURE);
1530 }
1531
1532 w32_daemon_event = CreateEvent (NULL, TRUE, FALSE, W32_DAEMON_EVENT);
1533 if (w32_daemon_event == NULL)
1534 {
1535 message (true, "Couldn't create Windows daemon event");
1536 exit (EXIT_FAILURE);
1537 }
1538 if ((wait_result = WaitForSingleObject (w32_daemon_event, INFINITE))
1539 != WAIT_OBJECT_0)
1540 {
1541 char *msg = NULL;
1542
1543 switch (wait_result)
1544 {
1545 case WAIT_ABANDONED:
1546 msg = "The daemon exited unexpectedly";
1547 break;
1548 case WAIT_TIMEOUT:
1549 /* Can't happen due to INFINITE. */
1550 default:
1551 case WAIT_FAILED:
1552 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
1553 | FORMAT_MESSAGE_ALLOCATE_BUFFER
1554 | FORMAT_MESSAGE_ARGUMENT_ARRAY,
1555 NULL, GetLastError (), 0, (LPTSTR)&msg, 0, NULL);
1556 break;
1557 }
1558 message (true, "Error: Could not start the Emacs daemon: %s\n", msg);
1559 exit (EXIT_FAILURE);
1560 }
1561 CloseHandle (w32_daemon_event);
1562
1563 /* Try connecting, the daemon should have started by now. */
1564 /* It's just a progress message, so don't pop a dialog if this is
1565 emacsclientw. */
1566 if (!w32_window_app ())
1567 message (true,
1568 "Emacs daemon should have started, trying to connect again\n");
1569 if ((emacs_socket = set_socket (1)) == INVALID_SOCKET)
1570 {
1571 message (true,
1572 "Error: Cannot connect even after starting the Emacs daemon\n");
1573 exit (EXIT_FAILURE);
1574 }
1575#endif /* WINDOWSNT */
1515} 1576}
1516 1577
1517int 1578int