diff options
| author | Tom Tromey | 2013-08-25 14:25:59 -0600 |
|---|---|---|
| committer | Tom Tromey | 2013-08-25 14:25:59 -0600 |
| commit | 793ea5055aea85ff9227e1bf0c84ab37edba7201 (patch) | |
| tree | c9799eebe2b797a55fcbfcbd3710c9b5aa70051d /src/sysdep.c | |
| parent | 1ce4c6398ea453a66f6943552b0ec866a690e9b1 (diff) | |
| parent | e687aa335a21662f67d2d73063272504a171ffab (diff) | |
| download | emacs-793ea5055aea85ff9227e1bf0c84ab37edba7201.tar.gz emacs-793ea5055aea85ff9227e1bf0c84ab37edba7201.zip | |
merge from trunk
Diffstat (limited to 'src/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 113 |
1 files changed, 47 insertions, 66 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 201ba9d104d..0d732526528 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -337,16 +337,6 @@ child_status_changed (pid_t child, int *status, int options) | |||
| 337 | return get_child_status (child, status, WNOHANG | options, 0); | 337 | return get_child_status (child, status, WNOHANG | options, 0); |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | /* | ||
| 341 | * flush any pending output | ||
| 342 | * (may flush input as well; it does not matter the way we use it) | ||
| 343 | */ | ||
| 344 | |||
| 345 | void | ||
| 346 | flush_pending_output (int channel) | ||
| 347 | { | ||
| 348 | /* FIXME: maybe this function should be removed */ | ||
| 349 | } | ||
| 350 | 340 | ||
| 351 | /* Set up the terminal at the other end of a pseudo-terminal that | 341 | /* Set up the terminal at the other end of a pseudo-terminal that |
| 352 | we will be controlling an inferior through. | 342 | we will be controlling an inferior through. |
| @@ -481,10 +471,20 @@ sys_subshell (void) | |||
| 481 | pid_t pid; | 471 | pid_t pid; |
| 482 | int status; | 472 | int status; |
| 483 | struct save_signal saved_handlers[5]; | 473 | struct save_signal saved_handlers[5]; |
| 484 | Lisp_Object dir; | 474 | char *str = SSDATA (encode_current_directory ()); |
| 485 | unsigned char *volatile str_volatile = 0; | 475 | |
| 486 | unsigned char *str; | 476 | #ifdef DOS_NT |
| 487 | int len; | 477 | pid = 0; |
| 478 | #else | ||
| 479 | { | ||
| 480 | char *volatile str_volatile = str; | ||
| 481 | pid = vfork (); | ||
| 482 | str = str_volatile; | ||
| 483 | } | ||
| 484 | #endif | ||
| 485 | |||
| 486 | if (pid < 0) | ||
| 487 | error ("Can't spawn subshell"); | ||
| 488 | 488 | ||
| 489 | saved_handlers[0].code = SIGINT; | 489 | saved_handlers[0].code = SIGINT; |
| 490 | saved_handlers[1].code = SIGQUIT; | 490 | saved_handlers[1].code = SIGQUIT; |
| @@ -496,31 +496,8 @@ sys_subshell (void) | |||
| 496 | saved_handlers[3].code = 0; | 496 | saved_handlers[3].code = 0; |
| 497 | #endif | 497 | #endif |
| 498 | 498 | ||
| 499 | /* Mentioning current_buffer->buffer would mean including buffer.h, | ||
| 500 | which somehow wedges the hp compiler. So instead... */ | ||
| 501 | |||
| 502 | dir = intern ("default-directory"); | ||
| 503 | if (NILP (Fboundp (dir))) | ||
| 504 | goto xyzzy; | ||
| 505 | dir = Fsymbol_value (dir); | ||
| 506 | if (!STRINGP (dir)) | ||
| 507 | goto xyzzy; | ||
| 508 | |||
| 509 | dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil); | ||
| 510 | str_volatile = str = alloca (SCHARS (dir) + 2); | ||
| 511 | len = SCHARS (dir); | ||
| 512 | memcpy (str, SDATA (dir), len); | ||
| 513 | if (str[len - 1] != '/') str[len++] = '/'; | ||
| 514 | str[len] = 0; | ||
| 515 | xyzzy: | ||
| 516 | |||
| 517 | #ifdef DOS_NT | 499 | #ifdef DOS_NT |
| 518 | pid = 0; | ||
| 519 | save_signal_handlers (saved_handlers); | 500 | save_signal_handlers (saved_handlers); |
| 520 | #else | ||
| 521 | pid = vfork (); | ||
| 522 | if (pid == -1) | ||
| 523 | error ("Can't spawn subshell"); | ||
| 524 | #endif | 501 | #endif |
| 525 | 502 | ||
| 526 | if (pid == 0) | 503 | if (pid == 0) |
| @@ -538,11 +515,10 @@ sys_subshell (void) | |||
| 538 | sh = "sh"; | 515 | sh = "sh"; |
| 539 | 516 | ||
| 540 | /* Use our buffer's default directory for the subshell. */ | 517 | /* Use our buffer's default directory for the subshell. */ |
| 541 | str = str_volatile; | 518 | if (chdir (str) != 0) |
| 542 | if (str && chdir ((char *) str) != 0) | ||
| 543 | { | 519 | { |
| 544 | #ifndef DOS_NT | 520 | #ifndef DOS_NT |
| 545 | emacs_perror ((char *) str); | 521 | emacs_perror (str); |
| 546 | _exit (EXIT_CANCELED); | 522 | _exit (EXIT_CANCELED); |
| 547 | #endif | 523 | #endif |
| 548 | } | 524 | } |
| @@ -556,8 +532,6 @@ sys_subshell (void) | |||
| 556 | if (epwd) | 532 | if (epwd) |
| 557 | { | 533 | { |
| 558 | strcpy (old_pwd, epwd); | 534 | strcpy (old_pwd, epwd); |
| 559 | if (str[len - 1] == '/') | ||
| 560 | str[len - 1] = '\0'; | ||
| 561 | setenv ("PWD", str, 1); | 535 | setenv ("PWD", str, 1); |
| 562 | } | 536 | } |
| 563 | st = system (sh); | 537 | st = system (sh); |
| @@ -1196,7 +1170,8 @@ get_tty_size (int fd, int *widthp, int *heightp) | |||
| 1196 | } | 1170 | } |
| 1197 | 1171 | ||
| 1198 | /* Set the logical window size associated with descriptor FD | 1172 | /* Set the logical window size associated with descriptor FD |
| 1199 | to HEIGHT and WIDTH. This is used mainly with ptys. */ | 1173 | to HEIGHT and WIDTH. This is used mainly with ptys. |
| 1174 | Return a negative value on failure. */ | ||
| 1200 | 1175 | ||
| 1201 | int | 1176 | int |
| 1202 | set_window_size (int fd, int height, int width) | 1177 | set_window_size (int fd, int height, int width) |
| @@ -1208,10 +1183,7 @@ set_window_size (int fd, int height, int width) | |||
| 1208 | size.ws_row = height; | 1183 | size.ws_row = height; |
| 1209 | size.ws_col = width; | 1184 | size.ws_col = width; |
| 1210 | 1185 | ||
| 1211 | if (ioctl (fd, TIOCSWINSZ, &size) == -1) | 1186 | return ioctl (fd, TIOCSWINSZ, &size); |
| 1212 | return 0; /* error */ | ||
| 1213 | else | ||
| 1214 | return 1; | ||
| 1215 | 1187 | ||
| 1216 | #else | 1188 | #else |
| 1217 | #ifdef TIOCSSIZE | 1189 | #ifdef TIOCSSIZE |
| @@ -1221,10 +1193,7 @@ set_window_size (int fd, int height, int width) | |||
| 1221 | size.ts_lines = height; | 1193 | size.ts_lines = height; |
| 1222 | size.ts_cols = width; | 1194 | size.ts_cols = width; |
| 1223 | 1195 | ||
| 1224 | if (ioctl (fd, TIOCGSIZE, &size) == -1) | 1196 | return ioctl (fd, TIOCGSIZE, &size); |
| 1225 | return 0; | ||
| 1226 | else | ||
| 1227 | return 1; | ||
| 1228 | #else | 1197 | #else |
| 1229 | return -1; | 1198 | return -1; |
| 1230 | #endif /* not SunOS-style */ | 1199 | #endif /* not SunOS-style */ |
| @@ -2485,7 +2454,7 @@ serial_configure (struct Lisp_Process *p, | |||
| 2485 | Lisp_Object childp2 = Qnil; | 2454 | Lisp_Object childp2 = Qnil; |
| 2486 | Lisp_Object tem = Qnil; | 2455 | Lisp_Object tem = Qnil; |
| 2487 | struct termios attr; | 2456 | struct termios attr; |
| 2488 | int err = -1; | 2457 | int err; |
| 2489 | char summary[4] = "???"; /* This usually becomes "8N1". */ | 2458 | char summary[4] = "???"; /* This usually becomes "8N1". */ |
| 2490 | 2459 | ||
| 2491 | childp2 = Fcopy_sequence (p->childp); | 2460 | childp2 = Fcopy_sequence (p->childp); |
| @@ -2852,29 +2821,41 @@ procfs_ttyname (int rdev) | |||
| 2852 | return build_string (name); | 2821 | return build_string (name); |
| 2853 | } | 2822 | } |
| 2854 | 2823 | ||
| 2855 | static unsigned long | 2824 | static uintmax_t |
| 2856 | procfs_get_total_memory (void) | 2825 | procfs_get_total_memory (void) |
| 2857 | { | 2826 | { |
| 2858 | FILE *fmem; | 2827 | FILE *fmem; |
| 2859 | unsigned long retval = 2 * 1024 * 1024; /* default: 2GB */ | 2828 | uintmax_t retval = 2 * 1024 * 1024; /* default: 2 GiB */ |
| 2829 | int c; | ||
| 2860 | 2830 | ||
| 2861 | block_input (); | 2831 | block_input (); |
| 2862 | fmem = emacs_fopen ("/proc/meminfo", "r"); | 2832 | fmem = emacs_fopen ("/proc/meminfo", "r"); |
| 2863 | 2833 | ||
| 2864 | if (fmem) | 2834 | if (fmem) |
| 2865 | { | 2835 | { |
| 2866 | unsigned long entry_value; | 2836 | uintmax_t entry_value; |
| 2867 | char entry_name[20]; /* the longest I saw is 13+1 */ | 2837 | bool done; |
| 2838 | |||
| 2839 | do | ||
| 2840 | switch (fscanf (fmem, "MemTotal: %"SCNuMAX, &entry_value)) | ||
| 2841 | { | ||
| 2842 | case 1: | ||
| 2843 | retval = entry_value; | ||
| 2844 | done = 1; | ||
| 2845 | break; | ||
| 2846 | |||
| 2847 | case 0: | ||
| 2848 | while ((c = getc (fmem)) != EOF && c != '\n') | ||
| 2849 | continue; | ||
| 2850 | done = c == EOF; | ||
| 2851 | break; | ||
| 2852 | |||
| 2853 | default: | ||
| 2854 | done = 1; | ||
| 2855 | break; | ||
| 2856 | } | ||
| 2857 | while (!done); | ||
| 2868 | 2858 | ||
| 2869 | while (!feof (fmem) && !ferror (fmem)) | ||
| 2870 | { | ||
| 2871 | if (fscanf (fmem, "%s %lu kB\n", entry_name, &entry_value) >= 2 | ||
| 2872 | && strcmp (entry_name, "MemTotal:") == 0) | ||
| 2873 | { | ||
| 2874 | retval = entry_value; | ||
| 2875 | break; | ||
| 2876 | } | ||
| 2877 | } | ||
| 2878 | fclose (fmem); | 2859 | fclose (fmem); |
| 2879 | } | 2860 | } |
| 2880 | unblock_input (); | 2861 | unblock_input (); |
| @@ -3275,7 +3256,7 @@ system_process_attributes (Lisp_Object pid) | |||
| 3275 | { | 3256 | { |
| 3276 | int proc_id; | 3257 | int proc_id; |
| 3277 | int pagesize = getpagesize (); | 3258 | int pagesize = getpagesize (); |
| 3278 | int npages; | 3259 | unsigned long npages; |
| 3279 | int fscale; | 3260 | int fscale; |
| 3280 | struct passwd *pw; | 3261 | struct passwd *pw; |
| 3281 | struct group *gr; | 3262 | struct group *gr; |