diff options
| -rw-r--r-- | doc/emacs/ChangeLog | 4 | ||||
| -rw-r--r-- | doc/emacs/cmdargs.texi | 9 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/startup.el | 12 | ||||
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/emacs.c | 40 |
7 files changed, 77 insertions, 3 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index bae3e02d302..c3b98fc55de 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2008-09-21 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | * cmdargs.texi (Initial Options): Document --daemon. | ||
| 4 | |||
| 1 | 2008-09-20 Glenn Morris <rgm@gnu.org> | 5 | 2008-09-20 Glenn Morris <rgm@gnu.org> |
| 2 | 6 | ||
| 3 | * files.texi (Numbered Backups): Mention that some modes set | 7 | * files.texi (Numbered Backups): Mention that some modes set |
diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi index 74ebe3c9e1f..1e733755e99 100644 --- a/doc/emacs/cmdargs.texi +++ b/doc/emacs/cmdargs.texi | |||
| @@ -277,6 +277,15 @@ option and @samp{-Q} are the only options that block it. | |||
| 277 | Start emacs with minimum customizations. This is like using @samp{-q} | 277 | Start emacs with minimum customizations. This is like using @samp{-q} |
| 278 | and @samp{--no-site-file}, but also disables the startup screen. | 278 | and @samp{--no-site-file}, but also disables the startup screen. |
| 279 | 279 | ||
| 280 | @item -daemon | ||
| 281 | @opindex -daemon | ||
| 282 | @itemx --daemon | ||
| 283 | @opindex --daemon | ||
| 284 | Start emacs in background as a daemon (i.e. it will disconnect from the | ||
| 285 | terminal), do not open any frames and start the server. Clients can | ||
| 286 | connect and create graphical or terminal frames using | ||
| 287 | @code{emacsclient}. | ||
| 288 | |||
| 280 | @item --no-splash | 289 | @item --no-splash |
| 281 | @opindex --no-splash | 290 | @opindex --no-splash |
| 282 | @vindex inhibit-splash-screen | 291 | @vindex inhibit-splash-screen |
| @@ -130,6 +130,11 @@ Now, the default behavior is to open a new Emacs frame by default. | |||
| 130 | Use the -c option to get the old behavior of opening files in the | 130 | Use the -c option to get the old behavior of opening files in the |
| 131 | currently selected Emacs frame. | 131 | currently selected Emacs frame. |
| 132 | 132 | ||
| 133 | *** Emacs can now start in background, as a daemon when using the | ||
| 134 | --daemon command line argument. It disconnects from the terminal and | ||
| 135 | starts the server. Clients can connect and create graphical or | ||
| 136 | terminal frames using emacsclient. | ||
| 137 | |||
| 133 | *** The new command close-display-connection closes a connection to a | 138 | *** The new command close-display-connection closes a connection to a |
| 134 | remote display. | 139 | remote display. |
| 135 | 140 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a43dd64ed2e..4479267b406 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 2008-09-21 Dan Nicolaescu <dann@ics.uci.edu> | 1 | 2008-09-21 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 2 | ||
| 3 | * startup.el (command-line): Start the server when in daemon mode. | ||
| 4 | |||
| 3 | * frame.el (frame-initialize): Remove spurious setting of | 5 | * frame.el (frame-initialize): Remove spurious setting of |
| 4 | special-display-function with the default value. | 6 | special-display-function with the default value. |
| 5 | 7 | ||
diff --git a/lisp/startup.el b/lisp/startup.el index 6c4f2091b1a..5ad00c2f456 100644 --- a/lisp/startup.el +++ b/lisp/startup.el | |||
| @@ -881,9 +881,15 @@ opening the first frame (e.g. open a connection to an X server).") | |||
| 881 | 881 | ||
| 882 | (run-hooks 'before-init-hook) | 882 | (run-hooks 'before-init-hook) |
| 883 | 883 | ||
| 884 | ;; Under X Window, this creates the X frame and deletes the terminal frame. | 884 | (if (daemonp) |
| 885 | (when (fboundp 'frame-initialize) | 885 | ;; Just start the server here, no need to run |
| 886 | (frame-initialize)) | 886 | ;; `frame-initialize', it deals with creating a frame and |
| 887 | ;; setting the parameters for the initial frame, we don't need | ||
| 888 | ;; any oxof those. | ||
| 889 | (server-start) | ||
| 890 | ;; Under X Window, this creates the X frame and deletes the terminal frame. | ||
| 891 | (when (fboundp 'frame-initialize) | ||
| 892 | (frame-initialize))) | ||
| 887 | 893 | ||
| 888 | ;; Turn off blinking cursor if so specified in X resources. This is here | 894 | ;; Turn off blinking cursor if so specified in X resources. This is here |
| 889 | ;; only because all other settings of no-blinking-cursor are here. | 895 | ;; only because all other settings of no-blinking-cursor are here. |
diff --git a/src/ChangeLog b/src/ChangeLog index 9e855a4898b..97f11fb55bc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2008-09-21 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | * emacs.c (standard_args): Add --daemon. | ||
| 4 | (main): Disconnect from the terminal when --daemon is passed. | ||
| 5 | (is_daemon): New variable. | ||
| 6 | (Fdaemonp): New function. | ||
| 7 | (syms_of_emacs): Defsubr it. | ||
| 8 | |||
| 1 | 2008-09-20 Chong Yidong <cyd@stupidchicken.com> | 9 | 2008-09-20 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 10 | ||
| 3 | * xdisp.c (get_next_display_element): Handle string display | 11 | * xdisp.c (get_next_display_element): Handle string display |
diff --git a/src/emacs.c b/src/emacs.c index 68127df0c06..131662c27a1 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -232,6 +232,9 @@ int noninteractive; | |||
| 232 | 232 | ||
| 233 | int noninteractive1; | 233 | int noninteractive1; |
| 234 | 234 | ||
| 235 | /* Nonzero means Emacs was started as a daemon. */ | ||
| 236 | int is_daemon = 0; | ||
| 237 | |||
| 235 | /* Save argv and argc. */ | 238 | /* Save argv and argc. */ |
| 236 | char **initial_argv; | 239 | char **initial_argv; |
| 237 | int initial_argc; | 240 | int initial_argc; |
| @@ -1068,6 +1071,34 @@ main (int argc, char **argv) | |||
| 1068 | exit (0); | 1071 | exit (0); |
| 1069 | } | 1072 | } |
| 1070 | 1073 | ||
| 1074 | #ifndef DOS_NT | ||
| 1075 | if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) | ||
| 1076 | { | ||
| 1077 | pid_t f = fork(); | ||
| 1078 | int nfd; | ||
| 1079 | if (f > 0) | ||
| 1080 | exit(0); | ||
| 1081 | if (f < 0) | ||
| 1082 | { | ||
| 1083 | fprintf (stderr, "Cannot fork!\n"); | ||
| 1084 | exit(1); | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | nfd = open("/dev/null", O_RDWR); | ||
| 1088 | dup2(nfd, 0); | ||
| 1089 | dup2(nfd, 1); | ||
| 1090 | dup2(nfd, 2); | ||
| 1091 | close (nfd); | ||
| 1092 | is_daemon = 1; | ||
| 1093 | #ifdef HAVE_SETSID | ||
| 1094 | setsid(); | ||
| 1095 | #endif | ||
| 1096 | } | ||
| 1097 | #else /* DOS_NT */ | ||
| 1098 | fprintf (stderr, "This platform does not support the -daemon flag.\n"); | ||
| 1099 | exit (1); | ||
| 1100 | #endif /* DOS_NT */ | ||
| 1101 | |||
| 1071 | if (! noninteractive) | 1102 | if (! noninteractive) |
| 1072 | { | 1103 | { |
| 1073 | #ifdef BSD_PGRPS | 1104 | #ifdef BSD_PGRPS |
| @@ -1719,6 +1750,7 @@ struct standard_args standard_args[] = | |||
| 1719 | { "-nw", "--no-windows", 110, 0 }, | 1750 | { "-nw", "--no-windows", 110, 0 }, |
| 1720 | { "-batch", "--batch", 100, 0 }, | 1751 | { "-batch", "--batch", 100, 0 }, |
| 1721 | { "-script", "--script", 100, 1 }, | 1752 | { "-script", "--script", 100, 1 }, |
| 1753 | { "-daemon", "--daemon", 99, 0 }, | ||
| 1722 | { "-help", "--help", 90, 0 }, | 1754 | { "-help", "--help", 90, 0 }, |
| 1723 | { "-no-unibyte", "--no-unibyte", 83, 0 }, | 1755 | { "-no-unibyte", "--no-unibyte", 83, 0 }, |
| 1724 | { "-multibyte", "--multibyte", 82, 0 }, | 1756 | { "-multibyte", "--multibyte", 82, 0 }, |
| @@ -2350,6 +2382,13 @@ decode_env_path (evarname, defalt) | |||
| 2350 | return Fnreverse (lpath); | 2382 | return Fnreverse (lpath); |
| 2351 | } | 2383 | } |
| 2352 | 2384 | ||
| 2385 | DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, | ||
| 2386 | doc: /* Make the current emacs process a daemon.*/) | ||
| 2387 | (void) | ||
| 2388 | { | ||
| 2389 | return is_daemon ? Qt : Qnil; | ||
| 2390 | } | ||
| 2391 | |||
| 2353 | void | 2392 | void |
| 2354 | syms_of_emacs () | 2393 | syms_of_emacs () |
| 2355 | { | 2394 | { |
| @@ -2368,6 +2407,7 @@ syms_of_emacs () | |||
| 2368 | 2407 | ||
| 2369 | defsubr (&Sinvocation_name); | 2408 | defsubr (&Sinvocation_name); |
| 2370 | defsubr (&Sinvocation_directory); | 2409 | defsubr (&Sinvocation_directory); |
| 2410 | defsubr (&Sdaemonp); | ||
| 2371 | 2411 | ||
| 2372 | DEFVAR_LISP ("command-line-args", &Vcommand_line_args, | 2412 | DEFVAR_LISP ("command-line-args", &Vcommand_line_args, |
| 2373 | doc: /* Args passed by shell to Emacs, as a list of strings. | 2413 | doc: /* Args passed by shell to Emacs, as a list of strings. |