1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32 #endif /* HAVE_PWD_H */
35 #endif /* HAVE_LIMITS_H */
41 #endif /* HAVE_ALLOCA_H */
44 /* Including stdlib.h isn't necessarily enough to get srandom
45 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
47 /* The w32 build defines select stuff in w32.h, which is included by
48 sys/select.h (included below). */
50 #include "sysselect.h"
53 #include "blockinput.h"
57 #define write sys_write
62 #endif /* not WINDOWSNT */
64 /* Does anyone other than VMS need this? */
66 #define sys_fwrite fwrite
71 #include <sys/types.h>
76 #if !defined (USG) || defined (BSD_PGRPS)
78 #define setpgrp setpgid
82 /* Get SI_SRPC_DOMAIN, if it is available. */
83 #ifdef HAVE_SYS_SYSTEMINFO_H
84 #include <sys/systeminfo.h>
87 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
91 #include <sys/param.h>
94 extern unsigned start
__asm__ ("start");
104 #include <sys/ioctl.h>
111 #include <sys/utsname.h>
115 extern int quit_char
;
117 #include "keyboard.h"
120 #include "termhooks.h"
121 #include "termchar.h"
122 #include "termopts.h"
123 #include "dispextern.h"
125 #include "cm.h" /* for reset_sys_modes */
127 /* For serial_configure and serial_open. */
128 extern Lisp_Object QCport
, QCspeed
, QCprocess
;
129 extern Lisp_Object QCbytesize
, QCstopbits
, QCparity
, Qodd
, Qeven
;
130 extern Lisp_Object QCflowcontrol
, Qhw
, Qsw
, QCsummary
;
134 /* In process.h which conflicts with the local copy. */
136 int _cdecl
_spawnlp (int, const char *, const char *, ...);
137 int _cdecl
_getpid (void);
138 extern char *getwd (char *);
141 #include "syssignal.h"
148 #ifndef HAVE_STRUCT_UTIMBUF
149 /* We want to use utime rather than utimes, but we couldn't find the
150 structure declaration. We'll use the traditional one. */
158 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
163 static const int baud_convert
[] =
165 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
166 1800, 2400, 4800, 9600, 19200, 38400
172 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
174 #if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
182 void croak
P_ ((char *)) NO_RETURN
;
184 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
186 SIGMASKTYPE sigprocmask_set
;
189 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
191 /* Return the current working directory. Returns NULL on errors.
192 Any other returned value must be freed with free. This is used
193 only when get_current_dir_name is not defined on the system. */
195 get_current_dir_name ()
199 struct stat dotstat
, pwdstat
;
200 /* If PWD is accurate, use it instead of calling getwd. PWD is
201 sometimes a nicer name, and using it may avoid a fatal error if a
202 parent directory is searchable but not readable. */
203 if ((pwd
= getenv ("PWD")) != 0
204 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
205 && stat (pwd
, &pwdstat
) == 0
206 && stat (".", &dotstat
) == 0
207 && dotstat
.st_ino
== pwdstat
.st_ino
208 && dotstat
.st_dev
== pwdstat
.st_dev
210 && strlen (pwd
) < MAXPATHLEN
214 buf
= (char *) malloc (strlen (pwd
) + 1);
222 size_t buf_size
= 1024;
223 buf
= (char *) malloc (buf_size
);
228 if (getcwd (buf
, buf_size
) == buf
)
232 int tmp_errno
= errno
;
238 buf
= (char *) realloc (buf
, buf_size
);
246 /* We need MAXPATHLEN here. */
247 buf
= (char *) malloc (MAXPATHLEN
+ 1);
250 if (getwd (buf
) == NULL
)
252 int tmp_errno
= errno
;
264 /* Discard pending input on all input descriptors. */
270 struct emacs_tty buf
;
275 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
276 while (dos_keyread () != -1)
278 #else /* not MSDOS */
280 struct tty_display_info
*tty
;
281 for (tty
= tty_list
; tty
; tty
= tty
->next
)
283 if (tty
->input
) /* Is the device suspended? */
285 EMACS_GET_TTY (fileno (tty
->input
), &buf
);
286 EMACS_SET_TTY (fileno (tty
->input
), &buf
, 0);
290 #endif /* not MSDOS */
291 #endif /* not WINDOWSNT */
297 /* Arrange for character C to be read as the next input from
299 XXX What if we have multiple ttys?
305 if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
308 /* Should perhaps error if in batch mode */
310 ioctl (fileno (CURTTY()->input
), TIOCSTI
, &c
);
311 #else /* no TIOCSTI */
312 error ("Cannot stuff terminal input characters in this version of Unix");
313 #endif /* no TIOCSTI */
319 init_baud_rate (int fd
)
327 #else /* not DOS_NT */
333 emacs_ospeed
= cfgetospeed (&sg
);
334 #else /* not TERMIOS */
342 ioctl (fd
, TCGETA
, &sg
);
344 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
345 #else /* neither TERMIOS nor TERMIO */
348 sg
.sg_ospeed
= B9600
;
349 if (ioctl (fd
, TIOCGETP
, &sg
) < 0)
351 emacs_ospeed
= sg
.sg_ospeed
;
352 #endif /* not HAVE_TERMIO */
353 #endif /* not HAVE_TERMIOS */
354 #endif /* not DOS_NT */
357 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
358 ? baud_convert
[emacs_ospeed
] : 9600);
366 set_exclusive_use (fd
)
370 ioctl (fd
, FIOCLEX
, 0);
372 /* Ok to do nothing if this feature does not exist */
377 wait_without_blocking ()
379 croak ("wait_without_blocking");
380 synch_process_alive
= 0;
383 #endif /* not subprocesses */
385 int wait_debugging
; /* Set nonzero to make following function work under dbx
386 (at least for bsd). */
389 wait_for_termination_signal ()
392 /* Wait for subprocess with process id `pid' to terminate and
393 make sure it will get eliminated (not remain forever as a zombie) */
396 wait_for_termination (pid
)
402 #if defined (BSD_SYSTEM) || defined (HPUX)
403 /* Note that kill returns -1 even if the process is just a zombie now.
404 But inevitably a SIGCHLD interrupt should be generated
405 and child_sig will do wait3 and make the process go away. */
406 /* There is some indication that there is a bug involved with
407 termination of subprocesses, perhaps involving a kernel bug too,
408 but no idea what it is. Just as a hunch we signal SIGCHLD to see
409 if that causes the problem to go away or get worse. */
410 sigsetmask (sigmask (SIGCHLD
));
411 if (0 > kill (pid
, 0))
413 sigsetmask (SIGEMPTYMASK
);
414 kill (getpid (), SIGCHLD
);
420 sigpause (SIGEMPTYMASK
);
421 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
422 #ifdef POSIX_SIGNALS /* would this work for GNU/Linux as well? */
423 sigblock (sigmask (SIGCHLD
));
425 if (kill (pid
, 0) == -1 && errno
== ESRCH
)
427 sigunblock (sigmask (SIGCHLD
));
431 sigsuspend (&empty_mask
);
432 #else /* not POSIX_SIGNALS */
433 #ifdef HAVE_SYSV_SIGPAUSE
435 if (0 > kill (pid
, 0))
441 #else /* not HAVE_SYSV_SIGPAUSE */
445 #else /* not WINDOWSNT */
446 if (0 > kill (pid
, 0))
448 /* Using sleep instead of pause avoids timing error.
449 If the inferior dies just before the sleep,
450 we lose just one second. */
452 #endif /* not WINDOWSNT */
453 #endif /* not HAVE_SYSV_SIGPAUSE */
454 #endif /* not POSIX_SIGNALS */
455 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
456 #else /* not subprocesses */
458 #endif /* not subprocesses */
465 * flush any pending output
466 * (may flush input as well; it does not matter the way we use it)
470 flush_pending_output (channel
)
474 /* If we try this, we get hit with SIGTTIN, because
475 the child's tty belongs to the child's pgrp. */
478 ioctl (channel
, TCFLSH
, 1);
482 /* 3rd arg should be ignored
483 but some 4.2 kernels actually want the address of an int
484 and nonzero means something different. */
485 ioctl (channel
, TIOCFLUSH
, &zero
);
491 /* Set up the terminal at the other end of a pseudo-terminal that
492 we will be controlling an inferior through.
493 It should not echo or do line-editing, since that is done
494 in Emacs. No padding needed for insertion into an Emacs buffer. */
497 child_setup_tty (out
)
503 EMACS_GET_TTY (out
, &s
);
505 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
506 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
507 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
509 /* http://lists.gnu.org/archive/html/emacs-devel/2008-05/msg00406.html
510 Some versions of GNU Hurd do not have FFDLY? */
512 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
513 /* No output delays */
515 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
);
516 /* No output delays */
519 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
520 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
522 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
525 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
528 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
530 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
531 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
532 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
533 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
536 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
539 #ifdef SIGNALS_VIA_CHARACTERS
540 /* the QUIT and INTR character are used in process_send_signal
541 so set them here to something useful. */
542 if (s
.main
.c_cc
[VQUIT
] == CDISABLE
)
543 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
544 if (s
.main
.c_cc
[VINTR
] == CDISABLE
)
545 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
546 #endif /* not SIGNALS_VIA_CHARACTERS */
549 /* AIX enhanced edit loses NULs, so disable it */
552 s
.main
.c_iflag
&= ~ASCEDIT
;
554 /* Also, PTY overloads NUL and BREAK.
555 don't ignore break, but don't signal either, so it looks like NUL. */
556 s
.main
.c_iflag
&= ~IGNBRK
;
557 s
.main
.c_iflag
&= ~BRKINT
;
558 /* rms: Formerly it set s.main.c_cc[VINTR] to 0377 here
559 unconditionally. Then a SIGNALS_VIA_CHARACTERS conditional
560 would force it to 0377. That looks like duplicated code. */
561 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
564 #else /* not HAVE_TERMIO */
566 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
568 s
.main
.sg_flags
|= LPASS8
;
569 s
.main
.sg_erase
= 0377;
570 s
.main
.sg_kill
= 0377;
571 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
573 /* We used to enable ICANON (and set VEOF to 04), but this leads to
574 problems where process.c wants to send EOFs every once in a while
575 to force the output, which leads to weird effects when the
576 subprocess has disabled ICANON and ends up seeing those spurious
577 extra EOFs. So we don't send EOFs any more in
578 process.c:send_process, and instead we disable ICANON by default,
579 so if a subsprocess sets up ICANON, it's his problem (or the Elisp
580 package that talks to it) to deal with lines that are too long. */
581 s
.main
.c_lflag
&= ~ICANON
; /* Disable line editing and eof processing */
582 s
.main
.c_cc
[VMIN
] = 1;
583 s
.main
.c_cc
[VTIME
] = 0;
585 #endif /* not HAVE_TERMIO */
587 EMACS_SET_TTY (out
, &s
, 0);
589 #endif /* not DOS_NT */
592 #endif /* subprocesses */
594 /* Record a signal code and the handler for it. */
598 SIGTYPE (*handler
) P_ ((int));
601 static void save_signal_handlers
P_ ((struct save_signal
*));
602 static void restore_signal_handlers
P_ ((struct save_signal
*));
604 /* Suspend the Emacs process; give terminal to its superior. */
609 #if defined (SIGTSTP) && !defined (MSDOS)
612 int pgrp
= EMACS_GETPGRP (0);
613 EMACS_KILLPG (pgrp
, SIGTSTP
);
616 #else /* No SIGTSTP */
617 /* On a system where suspending is not implemented,
618 instead fork a subshell and let it talk directly to the terminal
622 #endif /* no SIGTSTP */
625 /* Fork a subshell. */
630 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
632 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
635 struct save_signal saved_handlers
[5];
637 unsigned char *str
= 0;
640 saved_handlers
[0].code
= SIGINT
;
641 saved_handlers
[1].code
= SIGQUIT
;
642 saved_handlers
[2].code
= SIGTERM
;
644 saved_handlers
[3].code
= SIGIO
;
645 saved_handlers
[4].code
= 0;
647 saved_handlers
[3].code
= 0;
650 /* Mentioning current_buffer->buffer would mean including buffer.h,
651 which somehow wedges the hp compiler. So instead... */
653 dir
= intern ("default-directory");
654 if (NILP (Fboundp (dir
)))
656 dir
= Fsymbol_value (dir
);
660 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
661 str
= (unsigned char *) alloca (SCHARS (dir
) + 2);
663 bcopy (SDATA (dir
), str
, len
);
664 if (str
[len
- 1] != '/') str
[len
++] = '/';
670 save_signal_handlers (saved_handlers
);
671 synch_process_alive
= 1;
675 error ("Can't spawn subshell");
682 #ifdef DOS_NT /* MW, Aug 1993 */
685 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
688 sh
= (char *) egetenv ("SHELL");
692 /* Use our buffer's default directory for the subshell. */
694 chdir ((char *) str
);
697 close_process_descs (); /* Close Emacs's pipes/ptys */
700 #ifdef SET_EMACS_PRIORITY
702 extern EMACS_INT emacs_priority
;
704 if (emacs_priority
< 0)
705 nice (-emacs_priority
);
709 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
711 char *epwd
= getenv ("PWD");
712 char old_pwd
[MAXPATHLEN
+1+4];
714 /* If PWD is set, pass it with corrected value. */
717 strcpy (old_pwd
, epwd
);
718 if (str
[len
- 1] == '/')
720 setenv ("PWD", str
, 1);
725 putenv (old_pwd
); /* restore previous value */
727 #else /* not MSDOS */
729 /* Waits for process completion */
730 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
733 write (1, "Can't execute subshell", 22);
734 #else /* not WINDOWSNT */
735 execlp (sh
, sh
, (char *) 0);
736 write (1, "Can't execute subshell", 22);
738 #endif /* not WINDOWSNT */
739 #endif /* not MSDOS */
742 /* Do this now if we did not do it before. */
744 save_signal_handlers (saved_handlers
);
745 synch_process_alive
= 1;
749 wait_for_termination (pid
);
751 restore_signal_handlers (saved_handlers
);
752 synch_process_alive
= 0;
756 save_signal_handlers (saved_handlers
)
757 struct save_signal
*saved_handlers
;
759 while (saved_handlers
->code
)
761 saved_handlers
->handler
762 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
768 restore_signal_handlers (saved_handlers
)
769 struct save_signal
*saved_handlers
;
771 while (saved_handlers
->code
)
773 signal (saved_handlers
->code
, saved_handlers
->handler
);
779 /* If SIGIO is broken, don't do anything. */
796 unrequest_sigio (void)
803 int old_fcntl_flags
[MAXDESC
];
810 old_fcntl_flags
[fd
] = fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
811 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
] | FASYNC
);
813 interrupts_deferred
= 0;
821 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
]);
825 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
826 /* XXX Uhm, FASYNC is not used anymore here. */
827 /* XXX Yeah, but you need it for SIGIO, don't you? */
836 sigunblock (sigmask (SIGWINCH
));
838 sigunblock (sigmask (SIGIO
));
840 interrupts_deferred
= 0;
844 unrequest_sigio (void)
849 #if 0 /* XXX What's wrong with blocking SIGIO under X? */
855 sigblock (sigmask (SIGWINCH
));
857 sigblock (sigmask (SIGIO
));
858 interrupts_deferred
= 1;
861 #else /* no FASYNC */
867 if (noninteractive
|| read_socket_hook
)
870 croak ("request_sigio");
876 if (noninteractive
|| read_socket_hook
)
879 croak ("unrequest_sigio");
887 /* Saving and restoring the process group of Emacs's terminal. */
891 /* The process group of which Emacs was a member when it initially
894 If Emacs was in its own process group (i.e. inherited_pgroup ==
895 getpid ()), then we know we're running under a shell with job
896 control (Emacs would never be run as part of a pipeline).
899 If Emacs was not in its own process group, then we know we're
900 running under a shell (or a caller) that doesn't know how to
901 separate itself from Emacs (like sh). Emacs must be in its own
902 process group in order to receive SIGIO correctly. In this
903 situation, we put ourselves in our own pgroup, forcibly set the
904 tty's pgroup to our pgroup, and make sure to restore and reinstate
905 the tty's pgroup just like any other terminal setting. If
906 inherited_group was not the tty's pgroup, then we'll get a
907 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
908 it goes foreground in the future, which is what should happen.
910 This variable is initialized in emacs.c. */
911 int inherited_pgroup
;
913 /* Split off the foreground process group to Emacs alone. When we are
914 in the foreground, but not started in our own process group,
915 redirect the tty device handle FD to point to our own process
916 group. We need to be in our own process group to receive SIGIO
919 narrow_foreground_group (int fd
)
923 setpgrp (0, inherited_pgroup
);
925 /* XXX inherited_pgroup should not be zero here, but GTK seems to
927 if (! inherited_pgroup
)
928 abort (); /* Should not happen. */
930 if (inherited_pgroup
!= me
)
931 EMACS_SET_TTY_PGRP (fd
, &me
); /* XXX This only works on the controlling tty. */
935 /* Set the tty to our original foreground group. */
937 widen_foreground_group (int fd
)
939 if (inherited_pgroup
!= getpid ())
940 EMACS_SET_TTY_PGRP (fd
, &inherited_pgroup
);
941 setpgrp (0, inherited_pgroup
);
944 #endif /* BSD_PGRPS */
946 /* Getting and setting emacs_tty structures. */
948 /* Set *TC to the parameters associated with the terminal FD.
949 Return zero if all's well, or -1 if we ran into an error we
950 couldn't deal with. */
952 emacs_get_tty (fd
, settings
)
954 struct emacs_tty
*settings
;
956 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
958 /* We have those nifty POSIX tcmumbleattr functions. */
959 bzero (&settings
->main
, sizeof (settings
->main
));
960 if (tcgetattr (fd
, &settings
->main
) < 0)
965 /* The SYSV-style interface? */
966 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
971 /* I give up - I hope you have the BSD ioctls. */
972 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
974 #endif /* not DOS_NT */
978 /* Suivant - Do we have to get struct ltchars data? */
980 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
984 /* How about a struct tchars and a wordful of lmode bits? */
986 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
987 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
991 /* We have survived the tempest. */
996 /* Set the parameters of the tty on FD according to the contents of
997 *SETTINGS. If FLUSHP is non-zero, we discard input.
998 Return 0 if all went well, and -1 if anything failed. */
1001 emacs_set_tty (fd
, settings
, flushp
)
1003 struct emacs_tty
*settings
;
1006 /* Set the primary parameters - baud rate, character size, etcetera. */
1009 /* We have those nifty POSIX tcmumbleattr functions.
1010 William J. Smith <wjs@wiis.wang.com> writes:
1011 "POSIX 1003.1 defines tcsetattr to return success if it was
1012 able to perform any of the requested actions, even if some
1013 of the requested actions could not be performed.
1014 We must read settings back to ensure tty setup properly.
1015 AIX requires this to keep tty from hanging occasionally." */
1016 /* This make sure that we don't loop indefinitely in here. */
1017 for (i
= 0 ; i
< 10 ; i
++)
1018 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1029 bzero (&new, sizeof (new));
1030 /* Get the current settings, and see if they're what we asked for. */
1031 tcgetattr (fd
, &new);
1032 /* We cannot use memcmp on the whole structure here because under
1033 * aix386 the termios structure has some reserved field that may
1036 if ( new.c_iflag
== settings
->main
.c_iflag
1037 && new.c_oflag
== settings
->main
.c_oflag
1038 && new.c_cflag
== settings
->main
.c_cflag
1039 && new.c_lflag
== settings
->main
.c_lflag
1040 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1048 /* The SYSV-style interface? */
1049 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1054 /* I give up - I hope you have the BSD ioctls. */
1055 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1057 #endif /* not DOS_NT */
1062 /* Suivant - Do we have to get struct ltchars data? */
1064 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1068 /* How about a struct tchars and a wordful of lmode bits? */
1070 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1071 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1075 /* We have survived the tempest. */
1082 int old_fcntl_owner
[MAXDESC
];
1083 #endif /* F_SETOWN */
1085 /* This may also be defined in stdio,
1086 but if so, this does no harm,
1087 and using the same name avoids wasting the other one's space. */
1090 unsigned char _sobuf
[BUFSIZ
+8];
1092 char _sobuf
[BUFSIZ
];
1096 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1099 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1102 /* Initialize the terminal mode on all tty devices that are currently
1106 init_all_sys_modes (void)
1108 struct tty_display_info
*tty
;
1109 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1110 init_sys_modes (tty
);
1113 /* Initialize the terminal mode on the given tty device. */
1116 init_sys_modes (tty_out
)
1117 struct tty_display_info
*tty_out
;
1119 struct emacs_tty tty
;
1121 Vtty_erase_char
= Qnil
;
1126 if (!tty_out
->output
)
1127 return; /* The tty is suspended. */
1131 /* read_socket_hook is not global anymore. I think doing this
1132 unconditionally will not cause any problems. */
1133 if (! read_socket_hook
&& EQ (Vinitial_window_system
, Qnil
))
1135 narrow_foreground_group (fileno (tty_out
->input
));
1138 if (! tty_out
->old_tty
)
1139 tty_out
->old_tty
= (struct emacs_tty
*) xmalloc (sizeof (struct emacs_tty
));
1141 EMACS_GET_TTY (fileno (tty_out
->input
), tty_out
->old_tty
);
1143 tty
= *tty_out
->old_tty
;
1145 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1146 XSETINT (Vtty_erase_char
, tty
.main
.c_cc
[VERASE
]);
1148 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1149 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1150 #ifdef INLCR /* I'm just being cautious,
1151 since I can't check how widespread INLCR is--rms. */
1152 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1155 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1157 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1158 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1160 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1162 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1163 if (tty_out
->flow_control
)
1165 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1167 tty
.main
.c_iflag
&= ~IXANY
;
1171 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1172 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1174 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1176 if (tty_out
->meta_key
)
1178 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1179 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1182 if (tty_out
->input
== stdin
)
1184 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1185 /* Set up C-g for both SIGQUIT and SIGINT.
1186 We don't know which we will get, but we handle both alike
1187 so which one it really gives us does not matter. */
1188 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1192 /* We normally don't get interrupt or quit signals from tty
1193 devices other than our controlling terminal; therefore,
1194 we must handle C-g as normal input. Unfortunately, this
1195 means that the interrupt and quit feature must be
1196 disabled on secondary ttys, or we would not even see the
1199 Note that even though emacsclient could have special code
1200 to pass SIGINT to Emacs, we should _not_ enable
1201 interrupt/quit keys for emacsclient frames. This means
1202 that we can't break out of loops in C code from a
1203 secondary tty frame, but we can always decide what
1204 display the C-g came from, which is more important from a
1205 usability point of view. (Consider the case when two
1206 people work together using the same Emacs instance.) */
1207 tty
.main
.c_cc
[VINTR
] = CDISABLE
;
1208 tty
.main
.c_cc
[VQUIT
] = CDISABLE
;
1210 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1211 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1213 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1217 #if defined (__mips__) || defined (HAVE_TCATTR)
1219 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1222 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1223 #endif /* V_DSUSP */
1224 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1225 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1228 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1231 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1232 #endif /* VREPRINT */
1234 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1235 #endif /* VWERASE */
1237 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1238 #endif /* VDISCARD */
1240 if (tty_out
->flow_control
)
1243 tty
.main
.c_cc
[VSTART
] = '\021';
1246 tty
.main
.c_cc
[VSTOP
] = '\023';
1252 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1255 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1258 #endif /* mips or HAVE_TCATTR */
1262 /* AIX enhanced edit loses NULs, so disable it. */
1263 tty
.main
.c_line
= 0;
1264 tty
.main
.c_iflag
&= ~ASCEDIT
;
1266 tty
.main
.c_cc
[VSTRT
] = CDISABLE
;
1267 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1268 tty
.main
.c_cc
[VSUSP
] = CDISABLE
;
1269 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1270 #endif /* IBMR2AIX */
1271 if (tty_out
->flow_control
)
1274 tty
.main
.c_cc
[VSTART
] = '\021';
1277 tty
.main
.c_cc
[VSTOP
] = '\023';
1280 /* Also, PTY overloads NUL and BREAK.
1281 don't ignore break, but don't signal either, so it looks like NUL.
1282 This really serves a purpose only if running in an XTERM window
1283 or via TELNET or the like, but does no harm elsewhere. */
1284 tty
.main
.c_iflag
&= ~IGNBRK
;
1285 tty
.main
.c_iflag
&= ~BRKINT
;
1287 #else /* if not HAVE_TERMIO */
1289 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1290 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1292 tty
.main
.sg_flags
|= ANYP
;
1293 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1294 #endif /* not DOS_NT */
1295 #endif /* not HAVE_TERMIO */
1297 /* If going to use CBREAK mode, we must request C-g to interrupt
1298 and turn off start and stop chars, etc. If not going to use
1299 CBREAK mode, do this anyway so as to turn off local flow
1300 control for user coming over network on 4.2; in this case,
1301 only t_stopc and t_startc really matter. */
1304 /* Note: if not using CBREAK mode, it makes no difference how we
1306 tty
.tchars
= new_tchars
;
1307 tty
.tchars
.t_intrc
= quit_char
;
1308 if (tty_out
->flow_control
)
1310 tty
.tchars
.t_startc
= '\021';
1311 tty
.tchars
.t_stopc
= '\023';
1314 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| tty_out
->old_tty
.lmode
;
1316 #endif /* HAVE_TCHARS */
1317 #endif /* not HAVE_TERMIO */
1320 tty
.ltchars
= new_ltchars
;
1321 #endif /* HAVE_LTCHARS */
1322 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1323 if (!tty_out
->term_initted
)
1324 internal_terminal_init ();
1325 dos_ttraw (tty_out
);
1328 EMACS_SET_TTY (fileno (tty_out
->input
), &tty
, 0);
1330 /* This code added to insure that, if flow-control is not to be used,
1331 we have an unlocked terminal at the start. */
1334 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TCXONC
, 1);
1337 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TIOCSTART
, 0);
1340 #if defined (HAVE_TERMIOS) || defined (HPUX)
1342 if (!tty_out
->flow_control
) tcflow (fileno (tty_out
->input
), TCOON
);
1347 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1348 if (interrupt_input
)
1350 old_fcntl_owner
[fileno (tty_out
->input
)] =
1351 fcntl (fileno (tty_out
->input
), F_GETOWN
, 0);
1352 fcntl (fileno (tty_out
->input
), F_SETOWN
, getpid ());
1353 init_sigio (fileno (tty_out
->input
));
1355 if (gpm_tty
== tty_out
)
1357 /* Arrange for mouse events to give us SIGIO signals. */
1358 fcntl (gpm_fd
, F_SETOWN
, getpid ());
1359 fcntl (gpm_fd
, F_SETFL
, fcntl (gpm_fd
, F_GETFL
, 0) | O_NONBLOCK
);
1360 init_sigio (gpm_fd
);
1362 #endif /* HAVE_GPM */
1364 #endif /* F_GETOWN */
1365 #endif /* F_SETFL */
1368 /* This symbol is defined on recent USG systems.
1369 Someone says without this call USG won't really buffer the file
1370 even with a call to setbuf. */
1371 setvbuf (tty_out
->output
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1373 setbuf (tty_out
->output
, (char *) _sobuf
);
1376 if (tty_out
->terminal
->set_terminal_modes_hook
)
1377 tty_out
->terminal
->set_terminal_modes_hook (tty_out
->terminal
);
1379 if (!tty_out
->term_initted
)
1381 Lisp_Object tail
, frame
;
1382 FOR_EACH_FRAME (tail
, frame
)
1384 /* XXX This needs to be revised. */
1385 if (FRAME_TERMCAP_P (XFRAME (frame
))
1386 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1387 init_frame_faces (XFRAME (frame
));
1391 if (tty_out
->term_initted
&& no_redraw_on_reenter
)
1393 /* We used to call "direct_output_forward_char(0)" here,
1394 but it's not clear why, since it may not do anything anyway. */
1398 Lisp_Object tail
, frame
;
1400 FOR_EACH_FRAME (tail
, frame
)
1402 if ((FRAME_TERMCAP_P (XFRAME (frame
))
1403 || FRAME_MSDOS_P (XFRAME (frame
)))
1404 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1405 FRAME_GARBAGED_P (XFRAME (frame
)) = 1;
1409 tty_out
->term_initted
= 1;
1412 /* Return nonzero if safe to use tabs in output.
1413 At the time this is called, init_sys_modes has not been done yet. */
1416 tabs_safe_p (int fd
)
1418 struct emacs_tty etty
;
1420 EMACS_GET_TTY (fd
, &etty
);
1421 return EMACS_TTY_TABS_OK (&etty
);
1424 /* Get terminal size from system.
1425 Store number of lines into *HEIGHTP and width into *WIDTHP.
1426 We store 0 if there's no valid information. */
1429 get_tty_size (int fd
, int *widthp
, int *heightp
)
1435 struct winsize size
;
1437 if (ioctl (fd
, TIOCGWINSZ
, &size
) == -1)
1438 *widthp
= *heightp
= 0;
1441 *widthp
= size
.ws_col
;
1442 *heightp
= size
.ws_row
;
1448 /* SunOS - style. */
1449 struct ttysize size
;
1451 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1452 *widthp
= *heightp
= 0;
1455 *widthp
= size
.ts_cols
;
1456 *heightp
= size
.ts_lines
;
1461 *widthp
= ScreenCols ();
1462 *heightp
= ScreenRows ();
1463 #else /* system doesn't know size */
1467 #endif /* not SunOS-style */
1468 #endif /* not BSD-style */
1471 /* Set the logical window size associated with descriptor FD
1472 to HEIGHT and WIDTH. This is used mainly with ptys. */
1475 set_window_size (fd
, height
, width
)
1476 int fd
, height
, width
;
1481 struct winsize size
;
1482 size
.ws_row
= height
;
1483 size
.ws_col
= width
;
1485 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1486 return 0; /* error */
1493 /* SunOS - style. */
1494 struct ttysize size
;
1495 size
.ts_lines
= height
;
1496 size
.ts_cols
= width
;
1498 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1504 #endif /* not SunOS-style */
1505 #endif /* not BSD-style */
1510 /* Prepare all terminal devices for exiting Emacs. */
1513 reset_all_sys_modes (void)
1515 struct tty_display_info
*tty
;
1516 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1517 reset_sys_modes (tty
);
1520 /* Prepare the terminal for closing it; move the cursor to the
1521 bottom of the frame, turn off interrupt-driven I/O, etc. */
1524 reset_sys_modes (tty_out
)
1525 struct tty_display_info
*tty_out
;
1532 if (!tty_out
->term_initted
)
1535 if (!tty_out
->output
)
1536 return; /* The tty is suspended. */
1538 /* Go to and clear the last line of the terminal. */
1540 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1542 /* Code adapted from tty_clear_end_of_line. */
1543 if (tty_out
->TS_clr_line
)
1545 emacs_tputs (tty_out
, tty_out
->TS_clr_line
, 1, cmputc
);
1548 { /* have to do it the hard way */
1550 tty_turn_off_insert (tty_out
);
1552 for (i
= curX (tty_out
); i
< FrameCols (tty_out
) - 1; i
++)
1554 fputc (' ', tty_out
->output
);
1558 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1559 fflush (tty_out
->output
);
1561 if (tty_out
->terminal
->reset_terminal_modes_hook
)
1562 tty_out
->terminal
->reset_terminal_modes_hook (tty_out
->terminal
);
1565 /* Avoid possible loss of output when changing terminal modes. */
1566 fsync (fileno (tty_out
->output
));
1570 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1571 if (interrupt_input
)
1573 reset_sigio (fileno (tty_out
->input
));
1574 fcntl (fileno (tty_out
->input
), F_SETOWN
,
1575 old_fcntl_owner
[fileno (tty_out
->input
)]);
1577 #endif /* F_SETOWN */
1579 fcntl (fileno (tty_out
->input
), F_SETFL
,
1580 fcntl (fileno (tty_out
->input
), F_GETFL
, 0) & ~O_NDELAY
);
1582 #endif /* F_SETFL */
1584 if (tty_out
->old_tty
)
1585 while (EMACS_SET_TTY (fileno (tty_out
->input
),
1586 tty_out
->old_tty
, 0) < 0 && errno
== EINTR
)
1589 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1594 widen_foreground_group (fileno (tty_out
->input
));
1600 /* Set up the proper status flags for use of a pty. */
1606 /* I'm told that TOICREMOTE does not mean control chars
1607 "can't be sent" but rather that they don't have
1608 input-editing or signaling effects.
1609 That should be good, because we have other ways
1610 to do those things in Emacs.
1611 However, telnet mode seems not to work on 4.2.
1612 So TIOCREMOTE is turned off now. */
1614 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1615 will hang. In particular, the "timeout" feature (which
1616 causes a read to return if there is no data available)
1617 does this. Also it is known that telnet mode will hang
1618 in such a way that Emacs must be stopped (perhaps this
1619 is the same problem).
1621 If TIOCREMOTE is turned off, then there is a bug in
1622 hp-ux which sometimes loses data. Apparently the
1623 code which blocks the master process when the internal
1624 buffer fills up does not work. Other than this,
1625 though, everything else seems to work fine.
1627 Since the latter lossage is more benign, we may as well
1628 lose that way. -- cph */
1630 #if defined(UNIX98_PTYS)
1633 ioctl (fd
, FIONBIO
, &on
);
1638 #endif /* HAVE_PTYS */
1640 #if !defined(CANNOT_DUMP) || !defined(SYSTEM_MALLOC)
1641 /* Some systems that cannot dump also cannot implement these. */
1644 * Return the address of the start of the text segment prior to
1645 * doing an unexec. After unexec the return value is undefined.
1646 * See crt0.c for further explanation and _start.
1650 #if !(defined (__NetBSD__) && defined (__ELF__))
1651 #ifndef HAVE_TEXT_START
1656 return ((char *) TEXT_START
);
1658 extern int _start ();
1659 return ((char *) _start
);
1660 #endif /* TEXT_START */
1662 #endif /* not HAVE_TEXT_START */
1666 * Return the address of the start of the data segment prior to
1667 * doing an unexec. After unexec the return value is undefined.
1668 * See crt0.c for further information and definition of data_start.
1670 * Apparently, on BSD systems this is etext at startup. On
1671 * USG systems (swapping) this is highly mmu dependent and
1672 * is also dependent on whether or not the program is running
1673 * with shared text. Generally there is a (possibly large)
1674 * gap between end of text and start of data with shared text.
1676 * On Uniplus+ systems with shared text, data starts at a
1677 * fixed address. Each port (from a given oem) is generally
1678 * different, and the specific value of the start of data can
1679 * be obtained via the UniPlus+ specific "uvar" system call,
1680 * however the method outlined in crt0.c seems to be more portable.
1682 * Probably what will have to happen when a USG unexec is available,
1683 * at least on UniPlus, is temacs will have to be made unshared so
1684 * that text and data are contiguous. Then once loadup is complete,
1685 * unexec will produce a shared executable where the data can be
1686 * at the normal shared text boundary and the startofdata variable
1687 * will be patched by unexec to the correct value.
1691 #ifndef start_of_data
1696 return ((char *) DATA_START
);
1698 #ifdef ORDINARY_LINK
1700 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1701 * data_start isn't defined. We take the address of environ, which
1702 * is known to live at or near the start of the system crt0.c, and
1703 * we don't sweat the handful of bytes that might lose.
1705 extern char **environ
;
1707 return ((char *) &environ
);
1709 extern int data_start
;
1710 return ((char *) &data_start
);
1711 #endif /* ORDINARY_LINK */
1712 #endif /* DATA_START */
1714 #endif /* start_of_data */
1715 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1717 /* init_system_name sets up the string for the Lisp function
1718 system-name to return. */
1720 extern Lisp_Object Vsystem_name
;
1723 #include <sys/socket.h>
1725 #endif /* HAVE_SOCKETS */
1728 #ifndef HAVE_H_ERRNO
1731 #endif /* TRY_AGAIN */
1736 #ifndef HAVE_GETHOSTNAME
1739 Vsystem_name
= build_string (uts
.nodename
);
1740 #else /* HAVE_GETHOSTNAME */
1741 unsigned int hostname_size
= 256;
1742 char *hostname
= (char *) alloca (hostname_size
);
1744 /* Try to get the host name; if the buffer is too short, try
1745 again. Apparently, the only indication gethostname gives of
1746 whether the buffer was large enough is the presence or absence
1747 of a '\0' in the string. Eech. */
1750 gethostname (hostname
, hostname_size
- 1);
1751 hostname
[hostname_size
- 1] = '\0';
1753 /* Was the buffer large enough for the '\0'? */
1754 if (strlen (hostname
) < hostname_size
- 1)
1757 hostname_size
<<= 1;
1758 hostname
= (char *) alloca (hostname_size
);
1761 /* Turn the hostname into the official, fully-qualified hostname.
1762 Don't do this if we're going to dump; this can confuse system
1763 libraries on some machines and make the dumped emacs core dump. */
1766 #endif /* not CANNOT_DUMP */
1767 if (! index (hostname
, '.'))
1770 #ifdef HAVE_GETADDRINFO
1771 struct addrinfo
*res
;
1772 struct addrinfo hints
;
1775 memset (&hints
, 0, sizeof(hints
));
1776 hints
.ai_socktype
= SOCK_STREAM
;
1777 hints
.ai_flags
= AI_CANONNAME
;
1779 for (count
= 0;; count
++)
1781 if ((ret
= getaddrinfo (hostname
, NULL
, &hints
, &res
)) == 0
1782 || ret
!= EAI_AGAIN
)
1787 Fsleep_for (make_number (1), Qnil
);
1792 struct addrinfo
*it
= res
;
1795 char *fqdn
= it
->ai_canonname
;
1796 if (fqdn
&& index (fqdn
, '.')
1797 && strcmp (fqdn
, "localhost.localdomain") != 0)
1803 hostname
= alloca (strlen (it
->ai_canonname
) + 1);
1804 strcpy (hostname
, it
->ai_canonname
);
1808 #else /* !HAVE_GETADDRINFO */
1810 for (count
= 0;; count
++)
1816 hp
= gethostbyname (hostname
);
1818 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
1825 Fsleep_for (make_number (1), Qnil
);
1830 char *fqdn
= (char *) hp
->h_name
;
1832 if (!index (fqdn
, '.'))
1834 /* We still don't have a fully qualified domain name.
1835 Try to find one in the list of alternate names */
1836 char **alias
= hp
->h_aliases
;
1838 && (!index (*alias
, '.')
1839 || !strcmp (*alias
, "localhost.localdomain")))
1846 #endif /* !HAVE_GETADDRINFO */
1848 #endif /* HAVE_SOCKETS */
1849 Vsystem_name
= build_string (hostname
);
1850 #endif /* HAVE_GETHOSTNAME */
1853 for (p
= SDATA (Vsystem_name
); *p
; p
++)
1854 if (*p
== ' ' || *p
== '\t')
1860 #if !defined (HAVE_SELECT)
1862 #include "sysselect.h"
1865 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
1866 /* Cause explanatory error message at compile time,
1867 since the select emulation is not good enough for X. */
1868 int *x
= &x_windows_lose_if_no_select_system_call
;
1871 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1872 * Only checks read descriptors.
1874 /* How long to wait between checking fds in select */
1875 #define SELECT_PAUSE 1
1878 /* For longjmp'ing back to read_input_waiting. */
1880 jmp_buf read_alarm_throw
;
1882 /* Nonzero if the alarm signal should throw back to read_input_waiting.
1883 The read_socket_hook function sets this to 1 while it is waiting. */
1885 int read_alarm_should_throw
;
1891 signal (SIGALRM
, SIG_IGN
);
1892 SIGNAL_THREAD_CHECK (SIGALRM
);
1893 if (read_alarm_should_throw
)
1894 longjmp (read_alarm_throw
, 1);
1898 /* Only rfds are checked. */
1900 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
1902 SELECT_TYPE
*rfds
, *wfds
, *efds
;
1903 EMACS_TIME
*timeout
;
1905 /* XXX This needs to be updated for multi-tty support. Is there
1906 anybody who needs to emulate select these days? */
1911 extern int proc_buffered_char
[];
1912 #ifndef subprocesses
1913 int process_tick
= 0, update_tick
= 0;
1915 extern int process_tick
, update_tick
;
1919 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
1920 /* If we're using X, then the native select will work; we only need the
1921 emulation for non-X usage. */
1922 if (!NILP (Vinitial_window_system
))
1923 return select (nfds
, rfds
, wfds
, efds
, timeout
);
1925 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
1926 local_timeout
= &timeoutval
;
1938 /* If we are looking only for the terminal, with no timeout,
1939 just read it and wait -- that's more efficient. */
1940 if (*local_timeout
== 100000 && process_tick
== update_tick
1941 && FD_ISSET (0, &orfds
))
1944 for (fd
= 1; fd
< nfds
; ++fd
)
1945 if (FD_ISSET (fd
, &orfds
))
1947 if (! detect_input_pending ())
1948 read_input_waiting ();
1954 /* Once a second, till the timer expires, check all the flagged read
1955 * descriptors to see if any input is available. If there is some then
1956 * set the corresponding bit in the return copy of rfds.
1960 register int to_check
, fd
;
1964 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
1966 if (FD_ISSET (fd
, &orfds
))
1968 int avail
= 0, status
= 0;
1971 avail
= detect_input_pending (); /* Special keyboard handler */
1975 status
= ioctl (fd
, FIONREAD
, &avail
);
1976 #else /* no FIONREAD */
1977 /* Hoping it will return -1 if nothing available
1978 or 0 if all 0 chars requested are read. */
1979 if (proc_buffered_char
[fd
] >= 0)
1983 avail
= read (fd
, &buf
, 1);
1985 proc_buffered_char
[fd
] = buf
;
1987 #endif /* no FIONREAD */
1989 if (status
>= 0 && avail
> 0)
1997 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2000 turn_on_atimers (0);
2001 signal (SIGALRM
, select_alarm
);
2003 alarm (SELECT_PAUSE
);
2005 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2006 while (select_alarmed
== 0 && *local_timeout
!= 0
2007 && process_tick
== update_tick
)
2009 /* If we are interested in terminal input,
2010 wait by reading the terminal.
2011 That makes instant wakeup for terminal input at least. */
2012 if (FD_ISSET (0, &orfds
))
2014 read_input_waiting ();
2015 if (detect_input_pending ())
2021 (*local_timeout
) -= SELECT_PAUSE
;
2023 /* Reset the old alarm if there was one. */
2024 turn_on_atimers (1);
2026 if (*local_timeout
== 0) /* Stop on timer being cleared */
2031 #endif /* not WINDOWSNT */
2033 /* Read keyboard input into the standard buffer,
2034 waiting for at least one character. */
2037 read_input_waiting ()
2039 /* XXX This needs to be updated for multi-tty support. Is there
2040 anybody who needs to emulate select these days? */
2042 extern int quit_char
;
2044 if (read_socket_hook
)
2046 struct input_event hold_quit
;
2048 EVENT_INIT (hold_quit
);
2049 hold_quit
.kind
= NO_EVENT
;
2051 read_alarm_should_throw
= 0;
2052 if (! setjmp (read_alarm_throw
))
2053 nread
= (*read_socket_hook
) (0, 1, &hold_quit
);
2057 if (hold_quit
.kind
!= NO_EVENT
)
2058 kbd_buffer_store_event (&hold_quit
);
2062 struct input_event e
;
2064 nread
= read (fileno (stdin
), buf
, 1);
2067 /* Scan the chars for C-g and store them in kbd_buffer. */
2068 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2069 e
.frame_or_window
= selected_frame
;
2071 for (i
= 0; i
< nread
; i
++)
2073 /* Convert chars > 0177 to meta events if desired.
2074 We do this under the same conditions that read_avail_input does. */
2075 if (read_socket_hook
== 0)
2077 /* If the user says she has a meta key, then believe her. */
2078 if (meta_key
== 1 && (buf
[i
] & 0x80))
2079 e
.modifiers
= meta_modifier
;
2084 XSETINT (e
.code
, buf
[i
]);
2085 kbd_buffer_store_event (&e
);
2086 /* Don't look at input that follows a C-g too closely.
2087 This reduces lossage due to autorepeat on C-g. */
2088 if (buf
[i
] == quit_char
)
2094 #if !defined (HAVE_SELECT)
2095 #define select sys_select
2098 #endif /* not HAVE_SELECT */
2099 #endif /* not MSDOS */
2101 /* POSIX signals support - DJB */
2102 /* Anyone with POSIX signals should have ANSI C declarations */
2104 #ifdef POSIX_SIGNALS
2106 sigset_t empty_mask
, full_mask
;
2109 sys_signal (int signal_number
, signal_handler_t action
)
2111 struct sigaction new_action
, old_action
;
2112 sigemptyset (&new_action
.sa_mask
);
2113 new_action
.sa_handler
= action
;
2114 new_action
.sa_flags
= 0;
2115 #if defined (SA_RESTART)
2116 /* Emacs mostly works better with restartable system services. If this
2117 flag exists, we probably want to turn it on here.
2118 However, on some systems this resets the timeout of `select'
2119 which means that `select' never finishes if it keeps getting signals.
2120 BROKEN_SA_RESTART is defined on those systems. */
2121 /* It's not clear why the comment above says "mostly works better". --Stef
2122 When SYNC_INPUT is set, we don't want SA_RESTART because we need to poll
2123 for pending input so we need long-running syscalls to be interrupted
2124 after a signal that sets the interrupt_input_pending flag. */
2125 /* Non-interactive keyboard input goes through stdio, where we always
2126 want restartable system calls. */
2127 # if defined (BROKEN_SA_RESTART) || defined(SYNC_INPUT)
2130 new_action
.sa_flags
= SA_RESTART
;
2132 sigaction (signal_number
, &new_action
, &old_action
);
2133 return (old_action
.sa_handler
);
2137 /* If we're compiling with GCC, we don't need this function, since it
2138 can be written as a macro. */
2140 sys_sigmask (int sig
)
2143 sigemptyset (&mask
);
2144 sigaddset (&mask
, sig
);
2149 /* I'd like to have these guys return pointers to the mask storage in here,
2150 but there'd be trouble if the code was saving multiple masks. I'll be
2151 safe and pass the structure. It normally won't be more than 2 bytes
2155 sys_sigblock (sigset_t new_mask
)
2158 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2163 sys_sigunblock (sigset_t new_mask
)
2166 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2171 sys_sigsetmask (sigset_t new_mask
)
2174 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2178 #endif /* POSIX_SIGNALS */
2180 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2181 static char *my_sys_siglist
[NSIG
];
2185 # define sys_siglist my_sys_siglist
2191 #ifdef POSIX_SIGNALS
2192 sigemptyset (&empty_mask
);
2193 sigfillset (&full_mask
);
2196 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2200 sys_siglist
[SIGABRT
] = "Aborted";
2203 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2206 sys_siglist
[SIGALRM
] = "Alarm clock";
2209 sys_siglist
[SIGBUS
] = "Bus error";
2212 sys_siglist
[SIGCLD
] = "Child status changed";
2215 sys_siglist
[SIGCHLD
] = "Child status changed";
2218 sys_siglist
[SIGCONT
] = "Continued";
2221 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2224 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2227 sys_siglist
[SIGEMT
] = "Emulation trap";
2230 sys_siglist
[SIGFPE
] = "Arithmetic exception";
2233 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
2236 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
2239 sys_siglist
[SIGHUP
] = "Hangup";
2242 sys_siglist
[SIGILL
] = "Illegal instruction";
2245 sys_siglist
[SIGINT
] = "Interrupt";
2248 sys_siglist
[SIGIO
] = "I/O possible";
2251 sys_siglist
[SIGIOINT
] = "I/O intervention required";
2254 sys_siglist
[SIGIOT
] = "IOT trap";
2257 sys_siglist
[SIGKILL
] = "Killed";
2260 sys_siglist
[SIGLOST
] = "Resource lost";
2263 sys_siglist
[SIGLWP
] = "SIGLWP";
2266 sys_siglist
[SIGMSG
] = "Monitor mode data available";
2269 sys_siglist
[SIGWIND
] = "SIGPHONE";
2272 sys_siglist
[SIGPIPE
] = "Broken pipe";
2275 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
2278 sys_siglist
[SIGPROF
] = "Profiling timer expired";
2281 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
2284 sys_siglist
[SIGPWR
] = "Power-fail restart";
2287 sys_siglist
[SIGQUIT
] = "Quit";
2290 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
2293 sys_siglist
[SIGSAK
] = "Secure attention";
2296 sys_siglist
[SIGSEGV
] = "Segmentation violation";
2299 sys_siglist
[SIGSOUND
] = "Sound completed";
2302 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
2305 sys_siglist
[SIGSTP
] = "Stopped (user)";
2308 sys_siglist
[SIGSYS
] = "Bad argument to system call";
2311 sys_siglist
[SIGTERM
] = "Terminated";
2314 sys_siglist
[SIGTHAW
] = "SIGTHAW";
2317 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
2320 sys_siglist
[SIGTSTP
] = "Stopped (user)";
2323 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
2326 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
2329 sys_siglist
[SIGURG
] = "Urgent I/O condition";
2332 sys_siglist
[SIGUSR1
] = "User defined signal 1";
2335 sys_siglist
[SIGUSR2
] = "User defined signal 2";
2338 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
2341 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
2344 sys_siglist
[SIGWINCH
] = "Window size changed";
2347 sys_siglist
[SIGWIND
] = "SIGWIND";
2350 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
2353 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
2356 #endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
2365 /* Figure out how many bits the system's random number generator uses.
2366 `random' and `lrand48' are assumed to return 31 usable bits.
2367 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2368 so we'll shift it and treat it like the 15-bit USG `rand'. */
2372 # define RAND_BITS 31
2373 # else /* !HAVE_RANDOM */
2374 # ifdef HAVE_LRAND48
2375 # define RAND_BITS 31
2376 # define random lrand48
2377 # else /* !HAVE_LRAND48 */
2378 # define RAND_BITS 15
2379 # if RAND_MAX == 32767
2380 # define random rand
2381 # else /* RAND_MAX != 32767 */
2382 # if RAND_MAX == 2147483647
2383 # define random() (rand () >> 16)
2384 # else /* RAND_MAX != 2147483647 */
2386 # define random rand
2388 # define random() (rand () >> 16)
2390 # endif /* RAND_MAX != 2147483647 */
2391 # endif /* RAND_MAX != 32767 */
2392 # endif /* !HAVE_LRAND48 */
2393 # endif /* !HAVE_RANDOM */
2394 #endif /* !RAND_BITS */
2401 srandom ((unsigned int)arg
);
2403 # ifdef HAVE_LRAND48
2406 srand ((unsigned int)arg
);
2412 * Build a full Emacs-sized word out of whatever we've got.
2413 * This suffices even for a 64-bit architecture with a 15-bit rand.
2418 long val
= random ();
2419 #if VALBITS > RAND_BITS
2420 val
= (val
<< RAND_BITS
) ^ random ();
2421 #if VALBITS > 2*RAND_BITS
2422 val
= (val
<< RAND_BITS
) ^ random ();
2423 #if VALBITS > 3*RAND_BITS
2424 val
= (val
<< RAND_BITS
) ^ random ();
2425 #if VALBITS > 4*RAND_BITS
2426 val
= (val
<< RAND_BITS
) ^ random ();
2427 #endif /* need at least 5 */
2428 #endif /* need at least 4 */
2429 #endif /* need at least 3 */
2430 #endif /* need at least 2 */
2431 return val
& ((1L << VALBITS
) - 1);
2434 #ifndef HAVE_STRERROR
2440 extern char *sys_errlist
[];
2441 extern int sys_nerr
;
2443 if (errnum
>= 0 && errnum
< sys_nerr
)
2444 return sys_errlist
[errnum
];
2445 return (char *) "Unknown error";
2447 #endif /* not WINDOWSNT */
2448 #endif /* ! HAVE_STRERROR */
2451 emacs_open (path
, oflag
, mode
)
2455 register int rtnval
;
2457 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2458 && (errno
== EINTR
))
2468 register int rtnval
;
2470 while ((rtnval
= close (fd
)) == -1
2471 && (errno
== EINTR
))
2474 /* If close is interrupted SunOS 4.1 may or may not have closed the
2475 file descriptor. If it did the second close will fail with
2476 errno = EBADF. That means we have succeeded. */
2477 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
2484 emacs_read (fildes
, buf
, nbyte
)
2489 register int rtnval
;
2491 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2492 && (errno
== EINTR
))
2498 emacs_write (fildes
, buf
, nbyte
)
2503 register int rtnval
, bytes_written
;
2509 rtnval
= write (fildes
, buf
, nbyte
);
2516 /* I originally used `QUIT' but that might causes files to
2517 be truncated if you hit C-g in the middle of it. --Stef */
2518 process_pending_signals ();
2523 return (bytes_written
? bytes_written
: -1);
2528 bytes_written
+= rtnval
;
2530 return (bytes_written
);
2535 * All of the following are for USG.
2537 * On USG systems the system calls are INTERRUPTIBLE by signals
2538 * that the user program has elected to catch. Thus the system call
2539 * must be retried in these cases. To handle this without massive
2540 * changes in the source code, we remap the standard system call names
2541 * to names for our own functions in sysdep.c that do the system call
2542 * with retries. Actually, for portability reasons, it is good
2543 * programming practice, as this example shows, to limit all actual
2544 * system calls to a single occurrence in the source. Sure, this
2545 * adds an extra level of function call overhead but it is almost
2546 * always negligible. Fred Fish, Unisoft Systems Inc.
2550 * Warning, this function may not duplicate 4.2 action properly
2551 * under error conditions.
2555 /* In 4.1, param.h fails to define this. */
2556 #define MAXPATHLEN 1024
2565 char *npath
, *spath
;
2566 extern char *getcwd ();
2568 BLOCK_INPUT
; /* getcwd uses malloc */
2569 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2575 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2576 up to first slash. Should be harmless on other systems. */
2577 while (*npath
&& *npath
!= '/')
2579 strcpy (pathname
, npath
);
2580 free (spath
); /* getcwd uses malloc */
2585 #endif /* HAVE_GETWD */
2588 * Emulate rename using unlink/link. Note that this is
2589 * only partially correct. Also, doesn't enforce restriction
2590 * that files be of same type (regular->regular, dir->dir, etc).
2599 if (access (from
, 0) == 0)
2602 if (link (from
, to
) == 0)
2603 if (unlink (from
) == 0)
2612 #if defined(HPUX) && !defined(HAVE_PERROR)
2614 /* HPUX curses library references perror, but as far as we know
2615 it won't be called. Anyway this definition will do for now. */
2620 #endif /* HPUX and not HAVE_PERROR */
2625 * Emulate BSD dup2. First close newd if it already exists.
2626 * Then, attempt to dup oldd. If not successful, call dup2 recursively
2627 * until we are, then close the unsuccessful ones.
2634 register int fd
, ret
;
2639 return fcntl (oldd
, F_DUPFD
, newd
);
2646 ret
= dup2 (old
,new);
2652 #endif /* not HAVE_DUP2 */
2655 * Gettimeofday. Simulate as much as possible. Only accurate
2656 * to nearest second. Emacs doesn't use tzp so ignore it for now.
2657 * Only needed when subprocesses are defined.
2661 #ifndef HAVE_GETTIMEOFDAY
2666 gettimeofday (tp
, tzp
)
2668 struct timezone
*tzp
;
2670 extern long time ();
2672 tp
->tv_sec
= time ((long *)0);
2675 tzp
->tz_minuteswest
= -1;
2681 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL */
2684 * This function will go away as soon as all the stubs fixed. (fnf)
2691 printf ("%s not yet implemented\r\n", badfunc
);
2692 reset_all_sys_modes ();
2698 /* Directory routines for systems that don't have them. */
2700 #ifdef SYSV_SYSTEM_DIR
2704 #if !defined (HAVE_CLOSEDIR)
2707 closedir (DIR *dirp
/* stream from opendir */)
2711 rtnval
= emacs_close (dirp
->dd_fd
);
2713 /* Some systems (like Solaris) allocate the buffer and the DIR all
2714 in one block. Why in the world are we freeing this ourselves
2716 #if ! defined (SOLARIS2)
2717 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
2719 xfree ((char *) dirp
);
2723 #endif /* not HAVE_CLOSEDIR */
2724 #endif /* SYSV_SYSTEM_DIR */
2728 set_file_times (filename
, atime
, mtime
)
2729 const char *filename
;
2730 EMACS_TIME atime
, mtime
;
2733 struct timeval tv
[2];
2736 return utimes (filename
, tv
);
2737 #else /* not HAVE_UTIMES */
2739 utb
.actime
= EMACS_SECS (atime
);
2740 utb
.modtime
= EMACS_SECS (mtime
);
2741 return utime (filename
, &utb
);
2742 #endif /* not HAVE_UTIMES */
2745 /* mkdir and rmdir functions, for systems which don't have them. */
2749 * Written by Robert Rother, Mariah Corporation, August 1985.
2751 * If you want it, it's yours. All I ask in return is that if you
2752 * figure out how to do this in a Bourne Shell script you send me
2754 * sdcsvax!rmr or rmr@uscd
2756 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
2757 * subroutine. 11Mar86; hoptoad!gnu
2759 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
2760 * subroutine didn't return EEXIST. It does now.
2767 mkdir (dpath
, dmode
)
2771 int cpid
, status
, fd
;
2772 struct stat statbuf
;
2774 if (stat (dpath
, &statbuf
) == 0)
2776 errno
= EEXIST
; /* Stat worked, so it already exists */
2780 /* If stat fails for a reason other than non-existence, return error */
2781 if (errno
!= ENOENT
)
2784 synch_process_alive
= 1;
2785 switch (cpid
= fork ())
2788 case -1: /* Error in fork */
2789 return (-1); /* Errno is set already */
2791 case 0: /* Child process */
2793 * Cheap hack to set mode of new directory. Since this
2794 * child process is going away anyway, we zap its umask.
2795 * FIXME, this won't suffice to set SUID, SGID, etc. on this
2796 * directory. Does anybody care?
2798 status
= umask (0); /* Get current umask */
2799 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
2800 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
2807 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
2808 _exit (-1); /* Can't exec /bin/mkdir */
2810 default: /* Parent process */
2811 wait_for_termination (cpid
);
2814 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
2815 || synch_process_termsig
!= 0)
2817 errno
= EIO
; /* We don't know why, but */
2818 return -1; /* /bin/mkdir failed */
2823 #endif /* not HAVE_MKDIR */
2830 int cpid
, status
, fd
;
2831 struct stat statbuf
;
2833 if (stat (dpath
, &statbuf
) != 0)
2835 /* Stat just set errno. We don't have to */
2839 synch_process_alive
= 1;
2840 switch (cpid
= fork ())
2843 case -1: /* Error in fork */
2844 return (-1); /* Errno is set already */
2846 case 0: /* Child process */
2847 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
2854 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
2855 _exit (-1); /* Can't exec /bin/rmdir */
2857 default: /* Parent process */
2858 wait_for_termination (cpid
);
2861 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
2862 || synch_process_termsig
!= 0)
2864 errno
= EIO
; /* We don't know why, but */
2865 return -1; /* /bin/rmdir failed */
2870 #endif /* !HAVE_RMDIR */
2880 register int length
;
2882 while (length
-- > 0)
2886 #endif /* no bzero */
2887 #endif /* BSTRING */
2889 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
2892 /* Saying `void' requires a declaration, above, where bcopy is used
2893 and that declaration causes pain for systems where bcopy is a macro. */
2894 bcopy (b1
, b2
, length
)
2897 register int length
;
2899 while (length
-- > 0)
2902 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
2907 bcmp (b1
, b2
, length
) /* This could be a macro! */
2910 register int length
;
2912 while (length
-- > 0)
2918 #endif /* no bcmp */
2919 #endif /* not BSTRING */
2921 #ifndef HAVE_STRSIGNAL
2928 if (0 <= code
&& code
< NSIG
)
2930 /* Cast to suppress warning if the table has const char *. */
2931 signame
= (char *) sys_siglist
[code
];
2936 #endif /* HAVE_STRSIGNAL */
2939 /* For make-serial-process */
2940 int serial_open (char *port
)
2944 fd
= emacs_open ((char*) port
,
2957 error ("Could not open %s: %s",
2958 port
, emacs_strerror (errno
));
2961 ioctl (fd
, TIOCEXCL
, (char *) 0);
2966 #endif /* TERMIOS */
2970 #if !defined (HAVE_CFMAKERAW)
2971 /* Workaround for targets which are missing cfmakeraw. */
2972 /* Pasted from man page. */
2973 static void cfmakeraw (struct termios
*termios_p
)
2975 termios_p
->c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|ISTRIP
|INLCR
|IGNCR
|ICRNL
|IXON
);
2976 termios_p
->c_oflag
&= ~OPOST
;
2977 termios_p
->c_lflag
&= ~(ECHO
|ECHONL
|ICANON
|ISIG
|IEXTEN
);
2978 termios_p
->c_cflag
&= ~(CSIZE
|PARENB
);
2979 termios_p
->c_cflag
|= CS8
;
2981 #endif /* !defined (HAVE_CFMAKERAW */
2983 #if !defined (HAVE_CFSETSPEED)
2984 /* Workaround for targets which are missing cfsetspeed. */
2985 static int cfsetspeed (struct termios
*termios_p
, speed_t vitesse
)
2987 return (cfsetispeed (termios_p
, vitesse
)
2988 + cfsetospeed (termios_p
, vitesse
));
2992 /* For serial-process-configure */
2994 serial_configure (struct Lisp_Process
*p
,
2995 Lisp_Object contact
)
2997 Lisp_Object childp2
= Qnil
;
2998 Lisp_Object tem
= Qnil
;
2999 struct termios attr
;
3001 char summary
[4] = "???"; /* This usually becomes "8N1". */
3003 childp2
= Fcopy_sequence (p
->childp
);
3005 /* Read port attributes and prepare default configuration. */
3006 err
= tcgetattr (p
->outfd
, &attr
);
3008 error ("tcgetattr() failed: %s", emacs_strerror (errno
));
3010 #if defined (CLOCAL)
3011 attr
.c_cflag
|= CLOCAL
;
3014 attr
.c_cflag
|= CREAD
;
3017 /* Configure speed. */
3018 if (!NILP (Fplist_member (contact
, QCspeed
)))
3019 tem
= Fplist_get (contact
, QCspeed
);
3021 tem
= Fplist_get (p
->childp
, QCspeed
);
3023 err
= cfsetspeed (&attr
, XINT (tem
));
3025 error ("cfsetspeed(%d) failed: %s", XINT (tem
), emacs_strerror (errno
));
3026 childp2
= Fplist_put (childp2
, QCspeed
, tem
);
3028 /* Configure bytesize. */
3029 if (!NILP (Fplist_member (contact
, QCbytesize
)))
3030 tem
= Fplist_get (contact
, QCbytesize
);
3032 tem
= Fplist_get (p
->childp
, QCbytesize
);
3034 tem
= make_number (8);
3036 if (XINT (tem
) != 7 && XINT (tem
) != 8)
3037 error (":bytesize must be nil (8), 7, or 8");
3038 summary
[0] = XINT(tem
) + '0';
3039 #if defined (CSIZE) && defined (CS7) && defined (CS8)
3040 attr
.c_cflag
&= ~CSIZE
;
3041 attr
.c_cflag
|= ((XINT (tem
) == 7) ? CS7
: CS8
);
3043 /* Don't error on bytesize 8, which should be set by cfmakeraw. */
3044 if (XINT (tem
) != 8)
3045 error ("Bytesize cannot be changed");
3047 childp2
= Fplist_put (childp2
, QCbytesize
, tem
);
3049 /* Configure parity. */
3050 if (!NILP (Fplist_member (contact
, QCparity
)))
3051 tem
= Fplist_get (contact
, QCparity
);
3053 tem
= Fplist_get (p
->childp
, QCparity
);
3054 if (!NILP (tem
) && !EQ (tem
, Qeven
) && !EQ (tem
, Qodd
))
3055 error (":parity must be nil (no parity), `even', or `odd'");
3056 #if defined (PARENB) && defined (PARODD) && defined (IGNPAR) && defined (INPCK)
3057 attr
.c_cflag
&= ~(PARENB
| PARODD
);
3058 attr
.c_iflag
&= ~(IGNPAR
| INPCK
);
3063 else if (EQ (tem
, Qeven
))
3066 attr
.c_cflag
|= PARENB
;
3067 attr
.c_iflag
|= (IGNPAR
| INPCK
);
3069 else if (EQ (tem
, Qodd
))
3072 attr
.c_cflag
|= (PARENB
| PARODD
);
3073 attr
.c_iflag
|= (IGNPAR
| INPCK
);
3076 /* Don't error on no parity, which should be set by cfmakeraw. */
3078 error ("Parity cannot be configured");
3080 childp2
= Fplist_put (childp2
, QCparity
, tem
);
3082 /* Configure stopbits. */
3083 if (!NILP (Fplist_member (contact
, QCstopbits
)))
3084 tem
= Fplist_get (contact
, QCstopbits
);
3086 tem
= Fplist_get (p
->childp
, QCstopbits
);
3088 tem
= make_number (1);
3090 if (XINT (tem
) != 1 && XINT (tem
) != 2)
3091 error (":stopbits must be nil (1 stopbit), 1, or 2");
3092 summary
[2] = XINT (tem
) + '0';
3093 #if defined (CSTOPB)
3094 attr
.c_cflag
&= ~CSTOPB
;
3095 if (XINT (tem
) == 2)
3096 attr
.c_cflag
|= CSTOPB
;
3098 /* Don't error on 1 stopbit, which should be set by cfmakeraw. */
3099 if (XINT (tem
) != 1)
3100 error ("Stopbits cannot be configured");
3102 childp2
= Fplist_put (childp2
, QCstopbits
, tem
);
3104 /* Configure flowcontrol. */
3105 if (!NILP (Fplist_member (contact
, QCflowcontrol
)))
3106 tem
= Fplist_get (contact
, QCflowcontrol
);
3108 tem
= Fplist_get (p
->childp
, QCflowcontrol
);
3109 if (!NILP (tem
) && !EQ (tem
, Qhw
) && !EQ (tem
, Qsw
))
3110 error (":flowcontrol must be nil (no flowcontrol), `hw', or `sw'");
3111 #if defined (CRTSCTS)
3112 attr
.c_cflag
&= ~CRTSCTS
;
3114 #if defined (CNEW_RTSCTS)
3115 attr
.c_cflag
&= ~CNEW_RTSCTS
;
3117 #if defined (IXON) && defined (IXOFF)
3118 attr
.c_iflag
&= ~(IXON
| IXOFF
);
3122 /* Already configured. */
3124 else if (EQ (tem
, Qhw
))
3126 #if defined (CRTSCTS)
3127 attr
.c_cflag
|= CRTSCTS
;
3128 #elif defined (CNEW_RTSCTS)
3129 attr
.c_cflag
|= CNEW_RTSCTS
;
3131 error ("Hardware flowcontrol (RTS/CTS) not supported");
3134 else if (EQ (tem
, Qsw
))
3136 #if defined (IXON) && defined (IXOFF)
3137 attr
.c_iflag
|= (IXON
| IXOFF
);
3139 error ("Software flowcontrol (XON/XOFF) not supported");
3142 childp2
= Fplist_put (childp2
, QCflowcontrol
, tem
);
3144 /* Activate configuration. */
3145 err
= tcsetattr (p
->outfd
, TCSANOW
, &attr
);
3147 error ("tcsetattr() failed: %s", emacs_strerror (errno
));
3149 childp2
= Fplist_put (childp2
, QCsummary
, build_string (summary
));
3150 p
->childp
= childp2
;
3153 #endif /* TERMIOS */
3155 /* System depended enumeration of and access to system processes a-la ps(1). */
3159 /* Process enumeration and access via /proc. */
3162 list_system_processes ()
3164 Lisp_Object procdir
, match
, proclist
, next
;
3165 struct gcpro gcpro1
, gcpro2
;
3166 register Lisp_Object tail
;
3168 GCPRO2 (procdir
, match
);
3169 /* For every process on the system, there's a directory in the
3170 "/proc" pseudo-directory whose name is the numeric ID of that
3172 procdir
= build_string ("/proc");
3173 match
= build_string ("[0-9]+");
3174 proclist
= directory_files_internal (procdir
, Qnil
, match
, Qt
, 0, Qnil
);
3176 /* `proclist' gives process IDs as strings. Destructively convert
3177 each string into a number. */
3178 for (tail
= proclist
; CONSP (tail
); tail
= next
)
3181 XSETCAR (tail
, Fstring_to_number (XCAR (tail
), Qnil
));
3185 /* directory_files_internal returns the files in reverse order; undo
3187 proclist
= Fnreverse (proclist
);
3191 /* The WINDOWSNT implementation is in w32.c.
3192 The MSDOS implementation is in dosfns.c. */
3193 #elif !defined (WINDOWSNT) && !defined (MSDOS)
3196 list_system_processes ()
3201 #endif /* !defined (WINDOWSNT) */
3205 time_from_jiffies (unsigned long long tval
, long hz
,
3206 time_t *sec
, unsigned *usec
)
3208 unsigned long long ullsec
;
3212 tval
-= ullsec
* hz
;
3213 /* Careful: if HZ > 1 million, then integer division by it yields zero. */
3215 *usec
= tval
* 1000000 / hz
;
3217 *usec
= tval
/ (hz
/ 1000000);
3221 ltime_from_jiffies (unsigned long long tval
, long hz
)
3226 time_from_jiffies (tval
, hz
, &sec
, &usec
);
3228 return list3 (make_number ((sec
>> 16) & 0xffff),
3229 make_number (sec
& 0xffff),
3230 make_number (usec
));
3234 get_up_time (time_t *sec
, unsigned *usec
)
3241 fup
= fopen ("/proc/uptime", "r");
3245 double uptime
, idletime
;
3247 /* The numbers in /proc/uptime use C-locale decimal point, but
3248 we already set ourselves to the C locale (see `fixup_locale'
3250 if (2 <= fscanf (fup
, "%lf %lf", &uptime
, &idletime
))
3253 *usec
= (uptime
- *sec
) * 1000000;
3260 #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
3261 #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
3264 procfs_ttyname (int rdev
)
3267 char name
[PATH_MAX
];
3270 fdev
= fopen ("/proc/tty/drivers", "r");
3275 unsigned long minor_beg
, minor_end
;
3276 char minor
[25]; /* 2 32-bit numbers + dash */
3279 while (!feof (fdev
) && !ferror (fdev
))
3281 if (3 <= fscanf (fdev
, "%*s %s %u %s %*s\n", name
, &major
, minor
)
3282 && major
== MAJOR (rdev
))
3284 minor_beg
= strtoul (minor
, &endp
, 0);
3286 minor_end
= minor_beg
;
3287 else if (*endp
== '-')
3288 minor_end
= strtoul (endp
+ 1, &endp
, 0);
3292 if (MINOR (rdev
) >= minor_beg
&& MINOR (rdev
) <= minor_end
)
3294 sprintf (name
+ strlen (name
), "%u", MINOR (rdev
));
3302 return build_string (name
);
3305 static unsigned long
3306 procfs_get_total_memory (void)
3309 unsigned long retval
= 2 * 1024 * 1024; /* default: 2GB */
3312 fmem
= fopen ("/proc/meminfo", "r");
3316 unsigned long entry_value
;
3317 char entry_name
[20]; /* the longest I saw is 13+1 */
3319 while (!feof (fmem
) && !ferror (fmem
))
3321 if (2 <= fscanf (fmem
, "%s %lu kB\n", entry_name
, &entry_value
)
3322 && strcmp (entry_name
, "MemTotal:") == 0)
3324 retval
= entry_value
;
3335 system_process_attributes (Lisp_Object pid
)
3337 char procfn
[PATH_MAX
], fn
[PATH_MAX
];
3341 long clocks_per_sec
;
3343 char procbuf
[1025], *p
, *q
;
3346 const char *cmd
= NULL
;
3347 char *cmdline
= NULL
;
3348 size_t cmdsize
= 0, cmdline_size
;
3350 int proc_id
, ppid
, uid
, gid
, pgrp
, sess
, tty
, tpgid
, thcount
;
3351 unsigned long long utime
, stime
, cutime
, cstime
, start
;
3352 long priority
, nice
, rss
;
3353 unsigned long minflt
, majflt
, cminflt
, cmajflt
, vsize
;
3356 EMACS_TIME tnow
, tstart
, tboot
, telapsed
;
3358 Lisp_Object attrs
= Qnil
;
3359 Lisp_Object cmd_str
, decoded_cmd
, tem
;
3360 struct gcpro gcpro1
, gcpro2
;
3361 EMACS_INT uid_eint
, gid_eint
;
3363 CHECK_NUMBER_OR_FLOAT (pid
);
3364 proc_id
= FLOATP (pid
) ? XFLOAT_DATA (pid
) : XINT (pid
);
3365 sprintf (procfn
, "/proc/%u", proc_id
);
3366 if (stat (procfn
, &st
) < 0)
3369 GCPRO2 (attrs
, decoded_cmd
);
3373 /* Use of EMACS_INT stops GCC whining about limited range of data type. */
3375 attrs
= Fcons (Fcons (Qeuid
, make_fixnum_or_float (uid_eint
)), attrs
);
3377 pw
= getpwuid (uid
);
3380 attrs
= Fcons (Fcons (Quser
, build_string (pw
->pw_name
)), attrs
);
3384 attrs
= Fcons (Fcons (Qegid
, make_fixnum_or_float (gid_eint
)), attrs
);
3386 gr
= getgrgid (gid
);
3389 attrs
= Fcons (Fcons (Qgroup
, build_string (gr
->gr_name
)), attrs
);
3391 strcpy (fn
, procfn
);
3392 procfn_end
= fn
+ strlen (fn
);
3393 strcpy (procfn_end
, "/stat");
3394 fd
= emacs_open (fn
, O_RDONLY
, 0);
3395 if (fd
>= 0 && (nread
= emacs_read (fd
, procbuf
, sizeof(procbuf
) - 1)) > 0)
3397 procbuf
[nread
] = '\0';
3400 p
= strchr (p
, '(');
3403 q
= strrchr (p
+ 1, ')');
3418 /* Command name is encoded in locale-coding-system; decode it. */
3419 cmd_str
= make_unibyte_string (cmd
, cmdsize
);
3420 decoded_cmd
= code_convert_string_norecord (cmd_str
,
3421 Vlocale_coding_system
, 0);
3422 attrs
= Fcons (Fcons (Qcomm
, decoded_cmd
), attrs
);
3426 EMACS_INT ppid_eint
, pgrp_eint
, sess_eint
, tpgid_eint
, thcount_eint
;
3428 /* state ppid pgrp sess tty tpgid . minflt cminflt majflt cmajflt utime stime cutime cstime priority nice thcount . start vsize rss */
3429 sscanf (p
, "%c %d %d %d %d %d %*u %lu %lu %lu %lu %Lu %Lu %Lu %Lu %ld %ld %d %*d %Lu %lu %ld",
3430 &c
, &ppid
, &pgrp
, &sess
, &tty
, &tpgid
,
3431 &minflt
, &cminflt
, &majflt
, &cmajflt
,
3432 &utime
, &stime
, &cutime
, &cstime
,
3433 &priority
, &nice
, &thcount
, &start
, &vsize
, &rss
);
3438 state_str
[1] = '\0';
3439 tem
= build_string (state_str
);
3440 attrs
= Fcons (Fcons (Qstate
, tem
), attrs
);
3442 /* Stops GCC whining about limited range of data type. */
3447 thcount_eint
= thcount
;
3448 attrs
= Fcons (Fcons (Qppid
, make_fixnum_or_float (ppid_eint
)), attrs
);
3449 attrs
= Fcons (Fcons (Qpgrp
, make_fixnum_or_float (pgrp_eint
)), attrs
);
3450 attrs
= Fcons (Fcons (Qsess
, make_fixnum_or_float (sess_eint
)), attrs
);
3451 attrs
= Fcons (Fcons (Qttname
, procfs_ttyname (tty
)), attrs
);
3452 attrs
= Fcons (Fcons (Qtpgid
, make_fixnum_or_float (tpgid_eint
)), attrs
);
3453 attrs
= Fcons (Fcons (Qminflt
, make_fixnum_or_float (minflt
)), attrs
);
3454 attrs
= Fcons (Fcons (Qmajflt
, make_fixnum_or_float (majflt
)), attrs
);
3455 attrs
= Fcons (Fcons (Qcminflt
, make_fixnum_or_float (cminflt
)), attrs
);
3456 attrs
= Fcons (Fcons (Qcmajflt
, make_fixnum_or_float (cmajflt
)), attrs
);
3457 clocks_per_sec
= sysconf (_SC_CLK_TCK
);
3458 if (clocks_per_sec
< 0)
3459 clocks_per_sec
= 100;
3460 attrs
= Fcons (Fcons (Qutime
,
3461 ltime_from_jiffies (utime
, clocks_per_sec
)),
3463 attrs
= Fcons (Fcons (Qstime
,
3464 ltime_from_jiffies (stime
, clocks_per_sec
)),
3466 attrs
= Fcons (Fcons (Qtime
,
3467 ltime_from_jiffies (stime
+utime
, clocks_per_sec
)),
3469 attrs
= Fcons (Fcons (Qcutime
,
3470 ltime_from_jiffies (cutime
, clocks_per_sec
)),
3472 attrs
= Fcons (Fcons (Qcstime
,
3473 ltime_from_jiffies (cstime
, clocks_per_sec
)),
3475 attrs
= Fcons (Fcons (Qctime
,
3476 ltime_from_jiffies (cstime
+cutime
, clocks_per_sec
)),
3478 attrs
= Fcons (Fcons (Qpri
, make_number (priority
)), attrs
);
3479 attrs
= Fcons (Fcons (Qnice
, make_number (nice
)), attrs
);
3480 attrs
= Fcons (Fcons (Qthcount
, make_fixnum_or_float (thcount_eint
)), attrs
);
3481 EMACS_GET_TIME (tnow
);
3482 get_up_time (&sec
, &usec
);
3483 EMACS_SET_SECS (telapsed
, sec
);
3484 EMACS_SET_USECS (telapsed
, usec
);
3485 EMACS_SUB_TIME (tboot
, tnow
, telapsed
);
3486 time_from_jiffies (start
, clocks_per_sec
, &sec
, &usec
);
3487 EMACS_SET_SECS (tstart
, sec
);
3488 EMACS_SET_USECS (tstart
, usec
);
3489 EMACS_ADD_TIME (tstart
, tboot
, tstart
);
3490 attrs
= Fcons (Fcons (Qstart
,
3492 ((EMACS_SECS (tstart
) >> 16) & 0xffff),
3494 (EMACS_SECS (tstart
) & 0xffff),
3496 (EMACS_USECS (tstart
)))),
3498 attrs
= Fcons (Fcons (Qvsize
, make_fixnum_or_float (vsize
/1024)), attrs
);
3499 attrs
= Fcons (Fcons (Qrss
, make_fixnum_or_float (4*rss
)), attrs
);
3500 EMACS_SUB_TIME (telapsed
, tnow
, tstart
);
3501 attrs
= Fcons (Fcons (Qetime
,
3503 ((EMACS_SECS (telapsed
) >> 16) & 0xffff),
3505 (EMACS_SECS (telapsed
) & 0xffff),
3507 (EMACS_USECS (telapsed
)))),
3509 time_from_jiffies (utime
+ stime
, clocks_per_sec
, &sec
, &usec
);
3510 pcpu
= (sec
+ usec
/ 1000000.0) / (EMACS_SECS (telapsed
) + EMACS_USECS (telapsed
) / 1000000.0);
3513 attrs
= Fcons (Fcons (Qpcpu
, make_float (100 * pcpu
)), attrs
);
3514 pmem
= 4.0 * 100 * rss
/ procfs_get_total_memory ();
3517 attrs
= Fcons (Fcons (Qpmem
, make_float (pmem
)), attrs
);
3524 strcpy (procfn_end
, "/cmdline");
3525 fd
= emacs_open (fn
, O_RDONLY
, 0);
3528 for (cmdline_size
= 0; emacs_read (fd
, &c
, 1) == 1; cmdline_size
++)
3530 if (isspace (c
) || c
== '\\')
3531 cmdline_size
++; /* for later quoting, see below */
3535 cmdline
= xmalloc (cmdline_size
+ 1);
3536 lseek (fd
, 0L, SEEK_SET
);
3538 if ((nread
= read (fd
, cmdline
, cmdline_size
)) >= 0)
3539 cmdline
[nread
++] = '\0';
3542 /* Assigning zero to `nread' makes us skip the following
3543 two loops, assign zero to cmdline_size, and enter the
3544 following `if' clause that handles unknown command
3548 /* We don't want trailing null characters. */
3549 for (p
= cmdline
+ nread
- 1; p
> cmdline
&& !*p
; p
--)
3551 for (p
= cmdline
; p
< cmdline
+ nread
; p
++)
3553 /* Escape-quote whitespace and backslashes. */
3554 if (isspace (*p
) || *p
== '\\')
3556 memmove (p
+ 1, p
, nread
- (p
- cmdline
));
3560 else if (*p
== '\0')
3563 cmdline_size
= nread
;
3570 cmdsize
= strlen (cmd
);
3571 cmdline_size
= cmdsize
+ 2;
3572 cmdline
= xmalloc (cmdline_size
+ 1);
3573 strcpy (cmdline
, "[");
3574 strcat (strncat (cmdline
, cmd
, cmdsize
), "]");
3577 /* Command line is encoded in locale-coding-system; decode it. */
3578 cmd_str
= make_unibyte_string (cmdline
, cmdline_size
);
3579 decoded_cmd
= code_convert_string_norecord (cmd_str
,
3580 Vlocale_coding_system
, 0);
3582 attrs
= Fcons (Fcons (Qargs
, decoded_cmd
), attrs
);
3589 #elif defined (SOLARIS2) && defined (HAVE_PROCFS)
3591 /* The <procfs.h> header does not like to be included if _LP64 is defined and
3592 __FILE_OFFSET_BITS == 64. This is an ugly workaround that. */
3593 #if !defined (_LP64) && defined (_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
3594 #define PROCFS_FILE_OFFSET_BITS_HACK 1
3595 #undef _FILE_OFFSET_BITS
3597 #define PROCFS_FILE_OFFSET_BITS_HACK 0
3602 #if PROCFS_FILE_OFFSET_BITS_HACK == 1
3603 #define _FILE_OFFSET_BITS 64
3604 #endif /* PROCFS_FILE_OFFSET_BITS_HACK == 1 */
3607 system_process_attributes (Lisp_Object pid
)
3609 char procfn
[PATH_MAX
], fn
[PATH_MAX
];
3614 struct psinfo pinfo
;
3617 int proc_id
, uid
, gid
;
3618 Lisp_Object attrs
= Qnil
;
3619 Lisp_Object decoded_cmd
, tem
;
3620 struct gcpro gcpro1
, gcpro2
;
3621 EMACS_INT uid_eint
, gid_eint
;
3623 CHECK_NUMBER_OR_FLOAT (pid
);
3624 proc_id
= FLOATP (pid
) ? XFLOAT_DATA (pid
) : XINT (pid
);
3625 sprintf (procfn
, "/proc/%u", proc_id
);
3626 if (stat (procfn
, &st
) < 0)
3629 GCPRO2 (attrs
, decoded_cmd
);
3633 /* Use of EMACS_INT stops GCC whining about limited range of data type. */
3635 attrs
= Fcons (Fcons (Qeuid
, make_fixnum_or_float (uid_eint
)), attrs
);
3637 pw
= getpwuid (uid
);
3640 attrs
= Fcons (Fcons (Quser
, build_string (pw
->pw_name
)), attrs
);
3644 attrs
= Fcons (Fcons (Qegid
, make_fixnum_or_float (gid_eint
)), attrs
);
3646 gr
= getgrgid (gid
);
3649 attrs
= Fcons (Fcons (Qgroup
, build_string (gr
->gr_name
)), attrs
);
3651 strcpy (fn
, procfn
);
3652 procfn_end
= fn
+ strlen (fn
);
3653 strcpy (procfn_end
, "/psinfo");
3654 fd
= emacs_open (fn
, O_RDONLY
, 0);
3656 && (nread
= read (fd
, (char*)&pinfo
, sizeof(struct psinfo
)) > 0))
3658 attrs
= Fcons (Fcons (Qppid
, make_fixnum_or_float (pinfo
.pr_ppid
)), attrs
);
3659 attrs
= Fcons (Fcons (Qpgrp
, make_fixnum_or_float (pinfo
.pr_pgid
)), attrs
);
3660 attrs
= Fcons (Fcons (Qsess
, make_fixnum_or_float (pinfo
.pr_sid
)), attrs
);
3664 state_str
[0] = pinfo
.pr_lwp
.pr_sname
;
3665 state_str
[1] = '\0';
3666 tem
= build_string (state_str
);
3667 attrs
= Fcons (Fcons (Qstate
, tem
), attrs
);
3670 /* FIXME: missing Qttyname. psinfo.pr_ttydev is a dev_t,
3671 need to get a string from it. */
3673 /* FIXME: missing: Qtpgid */
3685 Are they available? */
3687 attrs
= Fcons (Fcons (Qtime
,
3688 list3 (make_number (pinfo
.pr_time
.tv_sec
>> 16),
3689 make_number (pinfo
.pr_time
.tv_sec
& 0xffff),
3690 make_number (pinfo
.pr_time
.tv_nsec
))),
3693 attrs
= Fcons (Fcons (Qctime
,
3694 list3 (make_number (pinfo
.pr_ctime
.tv_sec
>> 16),
3695 make_number (pinfo
.pr_ctime
.tv_sec
& 0xffff),
3696 make_number (pinfo
.pr_ctime
.tv_nsec
))),
3699 attrs
= Fcons (Fcons (Qpri
, make_number (pinfo
.pr_lwp
.pr_pri
)), attrs
);
3700 attrs
= Fcons (Fcons (Qnice
, make_number (pinfo
.pr_lwp
.pr_nice
)), attrs
);
3701 attrs
= Fcons (Fcons (Qthcount
, make_fixnum_or_float (pinfo
.pr_nlwp
)), attrs
);
3703 attrs
= Fcons (Fcons (Qstart
,
3704 list3 (make_number (pinfo
.pr_start
.tv_sec
>> 16),
3705 make_number (pinfo
.pr_start
.tv_sec
& 0xffff),
3706 make_number (pinfo
.pr_start
.tv_nsec
))),
3708 attrs
= Fcons (Fcons (Qvsize
, make_fixnum_or_float (pinfo
.pr_size
)), attrs
);
3709 attrs
= Fcons (Fcons (Qrss
, make_fixnum_or_float (pinfo
.pr_rssize
)), attrs
);
3711 /* pr_pctcpu and pr_pctmem are encoded as a fixed point 16 bit number in [0 ... 1]. */
3712 attrs
= Fcons (Fcons (Qpcpu
, (pinfo
.pr_pctcpu
* 100.0) / (double)0x8000), attrs
);
3713 attrs
= Fcons (Fcons (Qpmem
, (pinfo
.pr_pctmem
* 100.0) / (double)0x8000), attrs
);
3716 = code_convert_string_norecord (make_unibyte_string (pinfo
.pr_fname
,
3717 strlen (pinfo
.pr_fname
)),
3718 Vlocale_coding_system
, 0);
3719 attrs
= Fcons (Fcons (Qcomm
, decoded_cmd
), attrs
);
3721 = code_convert_string_norecord (make_unibyte_string (pinfo
.pr_psargs
,
3722 strlen (pinfo
.pr_psargs
)),
3723 Vlocale_coding_system
, 0);
3724 attrs
= Fcons (Fcons (Qargs
, decoded_cmd
), attrs
);
3734 /* The WINDOWSNT implementation is in w32.c.
3735 The MSDOS implementation is in dosfns.c. */
3736 #elif !defined (WINDOWSNT) && !defined (MSDOS)
3739 system_process_attributes (Lisp_Object pid
)
3744 #endif /* !defined (WINDOWSNT) */
3747 /* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
3748 (do not change this comment) */