diff options
| author | Dan Nicolaescu | 2008-09-21 23:31:40 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2008-09-21 23:31:40 +0000 |
| commit | eab2ee89441d51e885e3df6b3fbcb3c12a177232 (patch) | |
| tree | 16fff121c73fb31938ace464c17dd6650c2bcf5d /src | |
| parent | d06f8010663c3eacd0fd873f816803a6ffceb692 (diff) | |
| download | emacs-eab2ee89441d51e885e3df6b3fbcb3c12a177232.tar.gz emacs-eab2ee89441d51e885e3df6b3fbcb3c12a177232.zip | |
* emacs.c (standard_args): Add --daemon.
(main): Disconnect from the terminal when --daemon is passed.
(is_daemon): New variable.
(Fdaemonp): New function.
(syms_of_emacs): Defsubr it.
* startup.el (command-line): Start the server when in daemon mode.
* cmdargs.texi (Initial Options): Document --daemon.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/emacs.c | 40 |
2 files changed, 48 insertions, 0 deletions
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. |