aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2008-10-28 01:02:44 +0000
committerStefan Monnier2008-10-28 01:02:44 +0000
commitfc0127715c4cea8bc2fc26ebe69592d412555a07 (patch)
tree8a1f9b379bb6aaacc7f2686886fbbb2cc829aa1a /src
parent468750667c3d91e8e57955875ab62baad5ce354c (diff)
downloademacs-fc0127715c4cea8bc2fc26ebe69592d412555a07.tar.gz
emacs-fc0127715c4cea8bc2fc26ebe69592d412555a07.zip
* xdisp.c (pos_visible_p, redisplay_internal, message3_nolog)
(message2_nolog): Check FRAME_INITIAL_P instead of noninteractively. * emacs.c (is_daemon): Remove. (main): Don't set is_daemon. (IS_DAEMON): New macro. (Fdaemonp, Fdaemon_initialized): Use it. (Fdaemon_initialized): Wrtie a char into the pipe to make sure the parent exits. (syms_of_emacs): Explicitly initialize daemon_pipe[1].
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog13
-rw-r--r--src/emacs.c39
-rw-r--r--src/xdisp.c10
3 files changed, 50 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6562ef022d7..ba79e504b53 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12008-10-28 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * xdisp.c (pos_visible_p, redisplay_internal, message3_nolog)
4 (message2_nolog): Check FRAME_INITIAL_P instead of noninteractively.
5
6 * emacs.c (is_daemon): Remove.
7 (main): Don't set is_daemon.
8 (IS_DAEMON): New macro.
9 (Fdaemonp, Fdaemon_initialized): Use it.
10 (Fdaemon_initialized): Wrtie a char into the pipe to make sure the
11 parent exits.
12 (syms_of_emacs): Explicitly initialize daemon_pipe[1].
13
12008-10-27 Chong Yidong <cyd@stupidchicken.com> 142008-10-27 Chong Yidong <cyd@stupidchicken.com>
2 15
3 * nsterm.m (ns_draw_window_cursor): When hbar cursor is on 16 * nsterm.m (ns_draw_window_cursor): When hbar cursor is on
diff --git a/src/emacs.c b/src/emacs.c
index 6f54291a514..b3dee7776a2 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -235,8 +235,6 @@ int noninteractive;
235 235
236int noninteractive1; 236int noninteractive1;
237 237
238/* Nonzero means Emacs was started as a daemon. */
239int is_daemon = 0;
240/* Name for the server started by the daemon.*/ 238/* Name for the server started by the daemon.*/
241static char *daemon_name; 239static char *daemon_name;
242 240
@@ -244,6 +242,8 @@ static char *daemon_name;
244 startup. */ 242 startup. */
245static int daemon_pipe[2]; 243static int daemon_pipe[2];
246 244
245#define IS_DAEMON (daemon_pipe[1] != 0)
246
247/* Save argv and argc. */ 247/* Save argv and argc. */
248char **initial_argv; 248char **initial_argv;
249int initial_argc; 249int initial_argc;
@@ -1086,6 +1086,20 @@ main (int argc, char **argv)
1086 /* Start as a daemon: fork a new child process which will run the 1086 /* Start as a daemon: fork a new child process which will run the
1087 rest of the initialization code, then exit. 1087 rest of the initialization code, then exit.
1088 1088
1089 Detaching a daemon requires the following steps:
1090 - fork
1091 - setsid
1092 - exit the parent
1093 - close the tty file-descriptors
1094
1095 We only want to do the last 2 steps once the daemon is ready to
1096 serve requests, i.e. after loading .emacs (initialization).
1097 OTOH initialization may start subprocesses (e.g. ispell) and these
1098 should be run from the proper process (the one that will end up
1099 running as daemon) and with the proper "session id" in order for
1100 them to keep working after detaching, so fork and setsid need to be
1101 performed before initialization.
1102
1089 We want to avoid exiting before the server socket is ready, so 1103 We want to avoid exiting before the server socket is ready, so
1090 use a pipe for synchronization. The parent waits for the child 1104 use a pipe for synchronization. The parent waits for the child
1091 to close its end of the pipe (using `daemon-initialized') 1105 to close its end of the pipe (using `daemon-initialized')
@@ -1131,7 +1145,6 @@ main (int argc, char **argv)
1131 daemon_name = xstrdup (dname_arg); 1145 daemon_name = xstrdup (dname_arg);
1132 /* Close unused reading end of the pipe. */ 1146 /* Close unused reading end of the pipe. */
1133 close (daemon_pipe[0]); 1147 close (daemon_pipe[0]);
1134 is_daemon = 1;
1135#ifdef HAVE_SETSID 1148#ifdef HAVE_SETSID
1136 setsid(); 1149 setsid();
1137#endif 1150#endif
@@ -2429,7 +2442,7 @@ DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0,
2429If the daemon was given a name argument, return that name. */) 2442If the daemon was given a name argument, return that name. */)
2430 () 2443 ()
2431{ 2444{
2432 if (is_daemon) 2445 if (IS_DAEMON)
2433 if (daemon_name) 2446 if (daemon_name)
2434 return build_string (daemon_name); 2447 return build_string (daemon_name);
2435 else 2448 else
@@ -2439,12 +2452,14 @@ If the daemon was given a name argument, return that name. */)
2439} 2452}
2440 2453
2441DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0, 2454DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0,
2442 doc: /* Mark the Emacs daemon as being initialized. */) 2455 doc: /* Mark the Emacs daemon as being initialized.
2456This finishes the daemonization process by doing the other half of detaching
2457from the parent process and its tty file descriptors. */)
2443 () 2458 ()
2444{ 2459{
2445 int nfd; 2460 int nfd;
2446 2461
2447 if (!is_daemon) 2462 if (!IS_DAEMON)
2448 error ("This function can only be called if emacs is run as a daemon"); 2463 error ("This function can only be called if emacs is run as a daemon");
2449 2464
2450 if (daemon_pipe[1] < 0) 2465 if (daemon_pipe[1] < 0)
@@ -2460,7 +2475,14 @@ DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0,
2460 dup2 (nfd, 2); 2475 dup2 (nfd, 2);
2461 close (nfd); 2476 close (nfd);
2462 2477
2463 /* Closing the pipe will notify the parent that it can exit. */ 2478 /* Closing the pipe will notify the parent that it can exit.
2479 FIXME: In case some other process inherited the pipe, closing it here
2480 won't notify the parent because it's still open elsewhere, so we
2481 additionally send a byte, just to make sure the parent really exits.
2482 Instead, we should probably close the pipe in start-process and
2483 call-process to make sure the pipe is never inherited by
2484 subprocesses. */
2485 write (daemon_pipe[1], "\n", 1);
2464 close (daemon_pipe[1]); 2486 close (daemon_pipe[1]);
2465 /* Set it to an invalid value so we know we've already run this function. */ 2487 /* Set it to an invalid value so we know we've already run this function. */
2466 daemon_pipe[1] = -1; 2488 daemon_pipe[1] = -1;
@@ -2584,6 +2606,9 @@ was found. */);
2584 doc: /* Value of `current-time' after loading the init files. 2606 doc: /* Value of `current-time' after loading the init files.
2585This is nil during initialization. */); 2607This is nil during initialization. */);
2586 Vafter_init_time = Qnil; 2608 Vafter_init_time = Qnil;
2609
2610 /* Make sure IS_DAEMON starts up as false. */
2611 daemon_pipe[1] = 0;
2587} 2612}
2588 2613
2589/* arch-tag: 7bfd356a-c720-4612-8ab6-aa4222931c2e 2614/* arch-tag: 7bfd356a-c720-4612-8ab6-aa4222931c2e
diff --git a/src/xdisp.c b/src/xdisp.c
index d6ac67a7333..5509d1e65ed 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1323,7 +1323,7 @@ pos_visible_p (w, charpos, x, y, rtop, rbot, rowh, vpos)
1323 int visible_p = 0; 1323 int visible_p = 0;
1324 struct buffer *old_buffer = NULL; 1324 struct buffer *old_buffer = NULL;
1325 1325
1326 if (noninteractive) 1326 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w))))
1327 return visible_p; 1327 return visible_p;
1328 1328
1329 if (XBUFFER (w->buffer) != current_buffer) 1329 if (XBUFFER (w->buffer) != current_buffer)
@@ -7891,7 +7891,7 @@ message2_nolog (m, nbytes, multibyte)
7891 struct frame *sf = SELECTED_FRAME (); 7891 struct frame *sf = SELECTED_FRAME ();
7892 message_enable_multibyte = multibyte; 7892 message_enable_multibyte = multibyte;
7893 7893
7894 if (noninteractive) 7894 if (FRAME_INITIAL_P (sf))
7895 { 7895 {
7896 if (noninteractive_need_newline) 7896 if (noninteractive_need_newline)
7897 putc ('\n', stderr); 7897 putc ('\n', stderr);
@@ -7990,7 +7990,7 @@ message3_nolog (m, nbytes, multibyte)
7990 struct frame *sf = SELECTED_FRAME (); 7990 struct frame *sf = SELECTED_FRAME ();
7991 message_enable_multibyte = multibyte; 7991 message_enable_multibyte = multibyte;
7992 7992
7993 if (noninteractive) 7993 if (FRAME_INITIAL_P (sf))
7994 { 7994 {
7995 if (noninteractive_need_newline) 7995 if (noninteractive_need_newline)
7996 putc ('\n', stderr); 7996 putc ('\n', stderr);
@@ -8088,7 +8088,7 @@ message_with_string (m, string, log)
8088 putc ('\n', stderr); 8088 putc ('\n', stderr);
8089 noninteractive_need_newline = 0; 8089 noninteractive_need_newline = 0;
8090 fprintf (stderr, m, SDATA (string)); 8090 fprintf (stderr, m, SDATA (string));
8091 if (cursor_in_echo_area == 0) 8091 if (!cursor_in_echo_area)
8092 fprintf (stderr, "\n"); 8092 fprintf (stderr, "\n");
8093 fflush (stderr); 8093 fflush (stderr);
8094 } 8094 }
@@ -11300,7 +11300,7 @@ redisplay_internal (preserve_echo_area)
11300 /* No redisplay if running in batch mode or frame is not yet fully 11300 /* No redisplay if running in batch mode or frame is not yet fully
11301 initialized, or redisplay is explicitly turned off by setting 11301 initialized, or redisplay is explicitly turned off by setting
11302 Vinhibit_redisplay. */ 11302 Vinhibit_redisplay. */
11303 if (noninteractive 11303 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11304 || !NILP (Vinhibit_redisplay)) 11304 || !NILP (Vinhibit_redisplay))
11305 return; 11305 return;
11306 11306