diff options
| author | Tom Tromey | 2013-07-12 18:44:13 -0600 |
|---|---|---|
| committer | Tom Tromey | 2013-07-12 18:44:13 -0600 |
| commit | b34a529f177a6ea32da5cb1254f91bf9d71838db (patch) | |
| tree | 477131abc15d3107b30b635223d87a22550b480b /src/emacs.c | |
| parent | e6f63071a3f7721f55220514b6d9a8ee8c1232d8 (diff) | |
| parent | 5e301d7651c0691bb2bc7f3fbe711fdbe26ac471 (diff) | |
| download | emacs-b34a529f177a6ea32da5cb1254f91bf9d71838db.tar.gz emacs-b34a529f177a6ea32da5cb1254f91bf9d71838db.zip | |
Merge from trunk
Diffstat (limited to 'src/emacs.c')
| -rw-r--r-- | src/emacs.c | 89 |
1 files changed, 51 insertions, 38 deletions
diff --git a/src/emacs.c b/src/emacs.c index ec17322f57a..274321482e1 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -28,12 +28,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 28 | #include <unistd.h> | 28 | #include <unistd.h> |
| 29 | 29 | ||
| 30 | #include <close-stream.h> | 30 | #include <close-stream.h> |
| 31 | #include <ignore-value.h> | ||
| 32 | 31 | ||
| 33 | #include "lisp.h" | 32 | #include "lisp.h" |
| 34 | 33 | ||
| 35 | #ifdef WINDOWSNT | 34 | #ifdef WINDOWSNT |
| 36 | #include <fcntl.h> | 35 | #include <fcntl.h> |
| 36 | #include <sys/socket.h> | ||
| 37 | #include "w32.h" | 37 | #include "w32.h" |
| 38 | #include "w32heap.h" | 38 | #include "w32heap.h" |
| 39 | #endif | 39 | #endif |
| @@ -197,10 +197,10 @@ int initial_argc; | |||
| 197 | static void sort_args (int argc, char **argv); | 197 | static void sort_args (int argc, char **argv); |
| 198 | static void syms_of_emacs (void); | 198 | static void syms_of_emacs (void); |
| 199 | 199 | ||
| 200 | /* MSVC needs each string be shorter than 2048 bytes, so the usage | 200 | /* C89 needs each string be at most 509 characters, so the usage |
| 201 | strings below are split to not overflow this limit. */ | 201 | strings below are split to not overflow this limit. */ |
| 202 | #define USAGE1 "\ | 202 | static char const *const usage_message[] = |
| 203 | Usage: %s [OPTION-OR-FILENAME]...\n\ | 203 | { "\ |
| 204 | \n\ | 204 | \n\ |
| 205 | Run Emacs, the extensible, customizable, self-documenting real-time\n\ | 205 | Run Emacs, the extensible, customizable, self-documenting real-time\n\ |
| 206 | display editor. The recommended way to start Emacs for normal editing\n\ | 206 | display editor. The recommended way to start Emacs for normal editing\n\ |
| @@ -211,11 +211,15 @@ read the main documentation for these command-line arguments.\n\ | |||
| 211 | \n\ | 211 | \n\ |
| 212 | Initialization options:\n\ | 212 | Initialization options:\n\ |
| 213 | \n\ | 213 | \n\ |
| 214 | ", | ||
| 215 | "\ | ||
| 214 | --batch do not do interactive display; implies -q\n\ | 216 | --batch do not do interactive display; implies -q\n\ |
| 215 | --chdir DIR change to directory DIR\n\ | 217 | --chdir DIR change to directory DIR\n\ |
| 216 | --daemon start a server in the background\n\ | 218 | --daemon start a server in the background\n\ |
| 217 | --debug-init enable Emacs Lisp debugger for init file\n\ | 219 | --debug-init enable Emacs Lisp debugger for init file\n\ |
| 218 | --display, -d DISPLAY use X server DISPLAY\n\ | 220 | --display, -d DISPLAY use X server DISPLAY\n\ |
| 221 | ", | ||
| 222 | "\ | ||
| 219 | --no-desktop do not load a saved desktop\n\ | 223 | --no-desktop do not load a saved desktop\n\ |
| 220 | --no-init-file, -q load neither ~/.emacs nor default.el\n\ | 224 | --no-init-file, -q load neither ~/.emacs nor default.el\n\ |
| 221 | --no-shared-memory, -nl do not use shared memory\n\ | 225 | --no-shared-memory, -nl do not use shared memory\n\ |
| @@ -223,14 +227,16 @@ Initialization options:\n\ | |||
| 223 | --no-site-lisp, -nsl do not add site-lisp directories to load-path\n\ | 227 | --no-site-lisp, -nsl do not add site-lisp directories to load-path\n\ |
| 224 | --no-splash do not display a splash screen on startup\n\ | 228 | --no-splash do not display a splash screen on startup\n\ |
| 225 | --no-window-system, -nw do not communicate with X, ignoring $DISPLAY\n\ | 229 | --no-window-system, -nw do not communicate with X, ignoring $DISPLAY\n\ |
| 230 | ", | ||
| 231 | "\ | ||
| 226 | --quick, -Q equivalent to:\n\ | 232 | --quick, -Q equivalent to:\n\ |
| 227 | -q --no-site-file --no-site-lisp --no-splash\n\ | 233 | -q --no-site-file --no-site-lisp --no-splash\n\ |
| 228 | --script FILE run FILE as an Emacs Lisp script\n\ | 234 | --script FILE run FILE as an Emacs Lisp script\n\ |
| 229 | --terminal, -t DEVICE use DEVICE for terminal I/O\n\ | 235 | --terminal, -t DEVICE use DEVICE for terminal I/O\n\ |
| 230 | --user, -u USER load ~USER/.emacs instead of your own\n\ | 236 | --user, -u USER load ~USER/.emacs instead of your own\n\ |
| 231 | \n%s" | 237 | \n\ |
| 232 | 238 | ", | |
| 233 | #define USAGE2 "\ | 239 | "\ |
| 234 | Action options:\n\ | 240 | Action options:\n\ |
| 235 | \n\ | 241 | \n\ |
| 236 | FILE visit FILE using find-file\n\ | 242 | FILE visit FILE using find-file\n\ |
| @@ -239,6 +245,8 @@ FILE visit FILE using find-file\n\ | |||
| 239 | --directory, -L DIR add DIR to variable load-path\n\ | 245 | --directory, -L DIR add DIR to variable load-path\n\ |
| 240 | --eval EXPR evaluate Emacs Lisp expression EXPR\n\ | 246 | --eval EXPR evaluate Emacs Lisp expression EXPR\n\ |
| 241 | --execute EXPR evaluate Emacs Lisp expression EXPR\n\ | 247 | --execute EXPR evaluate Emacs Lisp expression EXPR\n\ |
| 248 | ", | ||
| 249 | "\ | ||
| 242 | --file FILE visit FILE using find-file\n\ | 250 | --file FILE visit FILE using find-file\n\ |
| 243 | --find-file FILE visit FILE using find-file\n\ | 251 | --find-file FILE visit FILE using find-file\n\ |
| 244 | --funcall, -f FUNC call Emacs Lisp function FUNC with no arguments\n\ | 252 | --funcall, -f FUNC call Emacs Lisp function FUNC with no arguments\n\ |
| @@ -246,9 +254,9 @@ FILE visit FILE using find-file\n\ | |||
| 246 | --kill exit without asking for confirmation\n\ | 254 | --kill exit without asking for confirmation\n\ |
| 247 | --load, -l FILE load Emacs Lisp FILE using the load function\n\ | 255 | --load, -l FILE load Emacs Lisp FILE using the load function\n\ |
| 248 | --visit FILE visit FILE using find-file\n\ | 256 | --visit FILE visit FILE using find-file\n\ |
| 249 | \n" | 257 | \n\ |
| 250 | 258 | ", | |
| 251 | #define USAGE3 "\ | 259 | "\ |
| 252 | Display options:\n\ | 260 | Display options:\n\ |
| 253 | \n\ | 261 | \n\ |
| 254 | --background-color, -bg COLOR window background color\n\ | 262 | --background-color, -bg COLOR window background color\n\ |
| @@ -256,6 +264,8 @@ Display options:\n\ | |||
| 256 | used for debugging Emacs\n\ | 264 | used for debugging Emacs\n\ |
| 257 | --border-color, -bd COLOR main border color\n\ | 265 | --border-color, -bd COLOR main border color\n\ |
| 258 | --border-width, -bw WIDTH width of main border\n\ | 266 | --border-width, -bw WIDTH width of main border\n\ |
| 267 | ", | ||
| 268 | "\ | ||
| 259 | --color, --color=MODE override color mode for character terminals;\n\ | 269 | --color, --color=MODE override color mode for character terminals;\n\ |
| 260 | MODE defaults to `auto', and\n\ | 270 | MODE defaults to `auto', and\n\ |
| 261 | can also be `never', `always',\n\ | 271 | can also be `never', `always',\n\ |
| @@ -263,17 +273,23 @@ Display options:\n\ | |||
| 263 | --cursor-color, -cr COLOR color of the Emacs cursor indicating point\n\ | 273 | --cursor-color, -cr COLOR color of the Emacs cursor indicating point\n\ |
| 264 | --font, -fn FONT default font; must be fixed-width\n\ | 274 | --font, -fn FONT default font; must be fixed-width\n\ |
| 265 | --foreground-color, -fg COLOR window foreground color\n\ | 275 | --foreground-color, -fg COLOR window foreground color\n\ |
| 276 | ", | ||
| 277 | "\ | ||
| 266 | --fullheight, -fh make the first frame high as the screen\n\ | 278 | --fullheight, -fh make the first frame high as the screen\n\ |
| 267 | --fullscreen, -fs make the first frame fullscreen\n\ | 279 | --fullscreen, -fs make the first frame fullscreen\n\ |
| 268 | --fullwidth, -fw make the first frame wide as the screen\n\ | 280 | --fullwidth, -fw make the first frame wide as the screen\n\ |
| 269 | --maximized, -mm make the first frame maximized\n\ | 281 | --maximized, -mm make the first frame maximized\n\ |
| 270 | --geometry, -g GEOMETRY window geometry\n\ | 282 | --geometry, -g GEOMETRY window geometry\n\ |
| 283 | ", | ||
| 284 | "\ | ||
| 271 | --no-bitmap-icon, -nbi do not use picture of gnu for Emacs icon\n\ | 285 | --no-bitmap-icon, -nbi do not use picture of gnu for Emacs icon\n\ |
| 272 | --iconic start Emacs in iconified state\n\ | 286 | --iconic start Emacs in iconified state\n\ |
| 273 | --internal-border, -ib WIDTH width between text and main border\n\ | 287 | --internal-border, -ib WIDTH width between text and main border\n\ |
| 274 | --line-spacing, -lsp PIXELS additional space to put between lines\n\ | 288 | --line-spacing, -lsp PIXELS additional space to put between lines\n\ |
| 275 | --mouse-color, -ms COLOR mouse cursor color in Emacs window\n\ | 289 | --mouse-color, -ms COLOR mouse cursor color in Emacs window\n\ |
| 276 | --name NAME title for initial Emacs frame\n\ | 290 | --name NAME title for initial Emacs frame\n\ |
| 291 | ", | ||
| 292 | "\ | ||
| 277 | --no-blinking-cursor, -nbc disable blinking cursor\n\ | 293 | --no-blinking-cursor, -nbc disable blinking cursor\n\ |
| 278 | --reverse-video, -r, -rv switch foreground and background\n\ | 294 | --reverse-video, -r, -rv switch foreground and background\n\ |
| 279 | --title, -T TITLE title for initial Emacs frame\n\ | 295 | --title, -T TITLE title for initial Emacs frame\n\ |
| @@ -282,9 +298,9 @@ Display options:\n\ | |||
| 282 | --parent-id XID set parent window\n\ | 298 | --parent-id XID set parent window\n\ |
| 283 | --help display this help and exit\n\ | 299 | --help display this help and exit\n\ |
| 284 | --version output version information and exit\n\ | 300 | --version output version information and exit\n\ |
| 285 | \n" | 301 | \n\ |
| 286 | 302 | ", | |
| 287 | #define USAGE4 "\ | 303 | "\ |
| 288 | You can generally also specify long option names with a single -; for\n\ | 304 | You can generally also specify long option names with a single -; for\n\ |
| 289 | example, -batch as well as --batch. You can use any unambiguous\n\ | 305 | example, -batch as well as --batch. You can use any unambiguous\n\ |
| 290 | abbreviation for a --option.\n\ | 306 | abbreviation for a --option.\n\ |
| @@ -294,6 +310,7 @@ Emacs' operation. See the main documentation.\n\ | |||
| 294 | \n\ | 310 | \n\ |
| 295 | Report bugs to bug-gnu-emacs@gnu.org. First, please see the Bugs\n\ | 311 | Report bugs to bug-gnu-emacs@gnu.org. First, please see the Bugs\n\ |
| 296 | section of the Emacs manual or the file BUGS.\n" | 312 | section of the Emacs manual or the file BUGS.\n" |
| 313 | }; | ||
| 297 | 314 | ||
| 298 | 315 | ||
| 299 | /* True if handling a fatal error already. */ | 316 | /* True if handling a fatal error already. */ |
| @@ -641,9 +658,7 @@ close_output_streams (void) | |||
| 641 | { | 658 | { |
| 642 | if (close_stream (stdout) != 0) | 659 | if (close_stream (stdout) != 0) |
| 643 | { | 660 | { |
| 644 | fprintf (stderr, "Write error to standard output: %s\n", | 661 | emacs_perror ("Write error to standard output"); |
| 645 | strerror (errno)); | ||
| 646 | fflush (stderr); | ||
| 647 | _exit (EXIT_FAILURE); | 662 | _exit (EXIT_FAILURE); |
| 648 | } | 663 | } |
| 649 | 664 | ||
| @@ -780,7 +795,7 @@ main (int argc, char **argv) | |||
| 780 | execvp (argv[0], argv); | 795 | execvp (argv[0], argv); |
| 781 | 796 | ||
| 782 | /* If the exec fails, try to dump anyway. */ | 797 | /* If the exec fails, try to dump anyway. */ |
| 783 | perror ("execvp"); | 798 | emacs_perror (argv[0]); |
| 784 | } | 799 | } |
| 785 | #endif /* HAVE_PERSONALITY_LINUX32 */ | 800 | #endif /* HAVE_PERSONALITY_LINUX32 */ |
| 786 | 801 | ||
| @@ -878,7 +893,7 @@ main (int argc, char **argv) | |||
| 878 | emacs_close (0); | 893 | emacs_close (0); |
| 879 | emacs_close (1); | 894 | emacs_close (1); |
| 880 | result = emacs_open (term, O_RDWR, 0); | 895 | result = emacs_open (term, O_RDWR, 0); |
| 881 | if (result < 0 || dup (0) < 0) | 896 | if (result < 0 || fcntl (0, F_DUPFD_CLOEXEC, 1) < 0) |
| 882 | { | 897 | { |
| 883 | char *errstring = strerror (errno); | 898 | char *errstring = strerror (errno); |
| 884 | fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring); | 899 | fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring); |
| @@ -925,9 +940,10 @@ main (int argc, char **argv) | |||
| 925 | /* Handle the --help option, which gives a usage message. */ | 940 | /* Handle the --help option, which gives a usage message. */ |
| 926 | if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args)) | 941 | if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args)) |
| 927 | { | 942 | { |
| 928 | printf (USAGE1, argv[0], USAGE2); | 943 | int i; |
| 929 | printf (USAGE3); | 944 | printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]); |
| 930 | printf (USAGE4); | 945 | for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++) |
| 946 | fputs (usage_message[i], stdout); | ||
| 931 | exit (0); | 947 | exit (0); |
| 932 | } | 948 | } |
| 933 | 949 | ||
| @@ -958,7 +974,7 @@ main (int argc, char **argv) | |||
| 958 | use a pipe for synchronization. The parent waits for the child | 974 | use a pipe for synchronization. The parent waits for the child |
| 959 | to close its end of the pipe (using `daemon-initialized') | 975 | to close its end of the pipe (using `daemon-initialized') |
| 960 | before exiting. */ | 976 | before exiting. */ |
| 961 | if (pipe (daemon_pipe) == -1) | 977 | if (pipe2 (daemon_pipe, O_CLOEXEC) != 0) |
| 962 | { | 978 | { |
| 963 | fprintf (stderr, "Cannot pipe!\n"); | 979 | fprintf (stderr, "Cannot pipe!\n"); |
| 964 | exit (1); | 980 | exit (1); |
| @@ -983,7 +999,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 983 | char buf[1]; | 999 | char buf[1]; |
| 984 | 1000 | ||
| 985 | /* Close unused writing end of the pipe. */ | 1001 | /* Close unused writing end of the pipe. */ |
| 986 | close (daemon_pipe[1]); | 1002 | emacs_close (daemon_pipe[1]); |
| 987 | 1003 | ||
| 988 | /* Just wait for the child to close its end of the pipe. */ | 1004 | /* Just wait for the child to close its end of the pipe. */ |
| 989 | do | 1005 | do |
| @@ -1003,13 +1019,13 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1003 | exit (1); | 1019 | exit (1); |
| 1004 | } | 1020 | } |
| 1005 | 1021 | ||
| 1006 | close (daemon_pipe[0]); | 1022 | emacs_close (daemon_pipe[0]); |
| 1007 | exit (0); | 1023 | exit (0); |
| 1008 | } | 1024 | } |
| 1009 | if (f < 0) | 1025 | if (f < 0) |
| 1010 | { | 1026 | { |
| 1011 | fprintf (stderr, "Cannot fork!\n"); | 1027 | emacs_perror ("fork"); |
| 1012 | exit (1); | 1028 | exit (EXIT_CANCELED); |
| 1013 | } | 1029 | } |
| 1014 | 1030 | ||
| 1015 | #ifdef DAEMON_MUST_EXEC | 1031 | #ifdef DAEMON_MUST_EXEC |
| @@ -1026,14 +1042,14 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1026 | if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr)) | 1042 | if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr)) |
| 1027 | { | 1043 | { |
| 1028 | fprintf (stderr, "daemon: child name too long\n"); | 1044 | fprintf (stderr, "daemon: child name too long\n"); |
| 1029 | exit (1); | 1045 | exit (EXIT_CANNOT_INVOKE); |
| 1030 | } | 1046 | } |
| 1031 | 1047 | ||
| 1032 | argv[skip_args] = fdStr; | 1048 | argv[skip_args] = fdStr; |
| 1033 | 1049 | ||
| 1034 | execvp (argv[0], argv); | 1050 | execvp (argv[0], argv); |
| 1035 | fprintf (stderr, "emacs daemon: exec failed: %d\n", errno); | 1051 | emacs_perror (argv[0]); |
| 1036 | exit (1); | 1052 | exit (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); |
| 1037 | } | 1053 | } |
| 1038 | 1054 | ||
| 1039 | /* In exec'd: parse special dname into pipe and name info. */ | 1055 | /* In exec'd: parse special dname into pipe and name info. */ |
| @@ -1041,7 +1057,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1041 | || strlen (dname_arg) < 1 || strlen (dname_arg) > 70) | 1057 | || strlen (dname_arg) < 1 || strlen (dname_arg) > 70) |
| 1042 | { | 1058 | { |
| 1043 | fprintf (stderr, "emacs daemon: daemon name absent or too long\n"); | 1059 | fprintf (stderr, "emacs daemon: daemon name absent or too long\n"); |
| 1044 | exit (1); | 1060 | exit (EXIT_CANNOT_INVOKE); |
| 1045 | } | 1061 | } |
| 1046 | dname_arg2[0] = '\0'; | 1062 | dname_arg2[0] = '\0'; |
| 1047 | sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), | 1063 | sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), |
| @@ -1053,10 +1069,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1053 | if (dname_arg) | 1069 | if (dname_arg) |
| 1054 | daemon_name = xstrdup (dname_arg); | 1070 | daemon_name = xstrdup (dname_arg); |
| 1055 | /* Close unused reading end of the pipe. */ | 1071 | /* Close unused reading end of the pipe. */ |
| 1056 | close (daemon_pipe[0]); | 1072 | emacs_close (daemon_pipe[0]); |
| 1057 | /* Make sure that the used end of the pipe is closed on exec, so | ||
| 1058 | that it is not accessible to programs started from .emacs. */ | ||
| 1059 | fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC); | ||
| 1060 | 1073 | ||
| 1061 | setsid (); | 1074 | setsid (); |
| 1062 | #else /* DOS_NT */ | 1075 | #else /* DOS_NT */ |
| @@ -1910,8 +1923,8 @@ shut_down_emacs (int sig, Lisp_Object stuff) | |||
| 1910 | char buf[sizeof format - 2 + INT_STRLEN_BOUND (int)]; | 1923 | char buf[sizeof format - 2 + INT_STRLEN_BOUND (int)]; |
| 1911 | int buflen = sprintf (buf, format, sig); | 1924 | int buflen = sprintf (buf, format, sig); |
| 1912 | char const *sig_desc = safe_strsignal (sig); | 1925 | char const *sig_desc = safe_strsignal (sig); |
| 1913 | ignore_value (write (STDERR_FILENO, buf, buflen)); | 1926 | emacs_write (STDERR_FILENO, buf, buflen); |
| 1914 | ignore_value (write (STDERR_FILENO, sig_desc, strlen (sig_desc))); | 1927 | emacs_write (STDERR_FILENO, sig_desc, strlen (sig_desc)); |
| 1915 | } | 1928 | } |
| 1916 | } | 1929 | } |
| 1917 | } | 1930 | } |
| @@ -2233,7 +2246,7 @@ from the parent process and its tty file descriptors. */) | |||
| 2233 | err |= dup2 (nfd, 0) < 0; | 2246 | err |= dup2 (nfd, 0) < 0; |
| 2234 | err |= dup2 (nfd, 1) < 0; | 2247 | err |= dup2 (nfd, 1) < 0; |
| 2235 | err |= dup2 (nfd, 2) < 0; | 2248 | err |= dup2 (nfd, 2) < 0; |
| 2236 | err |= close (nfd) != 0; | 2249 | err |= emacs_close (nfd) != 0; |
| 2237 | 2250 | ||
| 2238 | /* Closing the pipe will notify the parent that it can exit. | 2251 | /* Closing the pipe will notify the parent that it can exit. |
| 2239 | FIXME: In case some other process inherited the pipe, closing it here | 2252 | FIXME: In case some other process inherited the pipe, closing it here |
| @@ -2243,7 +2256,7 @@ from the parent process and its tty file descriptors. */) | |||
| 2243 | call-process to make sure the pipe is never inherited by | 2256 | call-process to make sure the pipe is never inherited by |
| 2244 | subprocesses. */ | 2257 | subprocesses. */ |
| 2245 | err |= write (daemon_pipe[1], "\n", 1) < 0; | 2258 | err |= write (daemon_pipe[1], "\n", 1) < 0; |
| 2246 | err |= close (daemon_pipe[1]) != 0; | 2259 | err |= emacs_close (daemon_pipe[1]) != 0; |
| 2247 | /* Set it to an invalid value so we know we've already run this function. */ | 2260 | /* Set it to an invalid value so we know we've already run this function. */ |
| 2248 | daemon_pipe[1] = -1; | 2261 | daemon_pipe[1] = -1; |
| 2249 | 2262 | ||