aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c6
-rw-r--r--src/keyboard.c46
-rw-r--r--src/lisp.h2
-rw-r--r--src/sysdep.c17
4 files changed, 31 insertions, 40 deletions
diff --git a/src/emacs.c b/src/emacs.c
index 777ade9d825..6929886424f 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2947,9 +2947,9 @@ sort_args (int argc, char **argv)
2947DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 2, "P", 2947DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 2, "P",
2948 doc: /* Exit the Emacs job and kill it. 2948 doc: /* Exit the Emacs job and kill it.
2949If ARG is an integer, return ARG as the exit program code. 2949If ARG is an integer, return ARG as the exit program code.
2950If ARG is a string, stuff it as keyboard input. (This might 2950If ARG is a string, stuff it and then a newline as keyboard input,
2951not work on modern systems due to security considerations, or 2951if Emacs is running interactively on a terminal and the platform
2952not at all.) 2952supports and allows stuffing; this may need special privileges.
2953Any other value of ARG, or ARG omitted, means return an 2953Any other value of ARG, or ARG omitted, means return an
2954exit code that indicates successful program termination. 2954exit code that indicates successful program termination.
2955 2955
diff --git a/src/keyboard.c b/src/keyboard.c
index 648dd81660a..55fb2401f2b 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -12421,19 +12421,15 @@ DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "",
12421If `cannot-suspend' is non-nil, or if the system doesn't support job 12421If `cannot-suspend' is non-nil, or if the system doesn't support job
12422control, run a subshell instead. 12422control, run a subshell instead.
12423 12423
12424If optional arg STUFFSTRING is non-nil, its characters are stuffed 12424If optional arg STUFFSTRING is non-nil, stuff it and then a newline as
12425to be read as terminal input by Emacs's parent, after suspension. 12425keyboard input, if Emacs is running interactively on a terminal and the
12426platform supports and allows stuffing; this may need special privileges.
12426 12427
12427Before suspending, run the normal hook `suspend-hook'. 12428Before suspending, run the normal hook `suspend-hook'.
12428After resumption run the normal hook `suspend-resume-hook'. 12429After resumption run the normal hook `suspend-resume-hook'.
12429 12430
12430Some operating systems cannot stop the Emacs process and resume it later. 12431Some operating systems cannot stop the Emacs process and resume it later.
12431On such systems, Emacs starts a subshell instead of suspending. 12432On such systems, Emacs starts a subshell instead of suspending. */)
12432
12433On some operating systems, stuffing characters into terminal input
12434buffer requires special privileges or is not supported at all.
12435On such systems, calling this function with non-nil STUFFSTRING might
12436either signal an error or silently fail to stuff the characters. */)
12437 (Lisp_Object stuffstring) 12433 (Lisp_Object stuffstring)
12438{ 12434{
12439 specpdl_ref count = SPECPDL_INDEX (); 12435 specpdl_ref count = SPECPDL_INDEX ();
@@ -12472,38 +12468,34 @@ either signal an error or silently fail to stuff the characters. */)
12472 return Qnil; 12468 return Qnil;
12473} 12469}
12474 12470
12475/* If STUFFSTRING is a string, stuff its contents as pending terminal input. 12471/* If STUFFSTRING is a string, stuff its contents and then a newline as
12476 Then in any case stuff anything Emacs has read ahead and not used. */ 12472 pending terminal input. Then stuff anything Emacs has read ahead and
12473 not used. However, do nothing if stuffing does not work. */
12477 12474
12478void 12475void
12479stuff_buffered_input (Lisp_Object stuffstring) 12476stuff_buffered_input (Lisp_Object stuffstring)
12480{ 12477{
12481#ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */ 12478#ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
12482 register unsigned char *p; 12479 int bad_stuff = 0;
12483 12480
12484 if (STRINGP (stuffstring)) 12481 if (STRINGP (stuffstring))
12485 { 12482 {
12486 register ptrdiff_t count; 12483 char *p = SSDATA (stuffstring);
12487 12484 for (ptrdiff_t i = SBYTES (stuffstring); !bad_stuff && 0 < i; i--)
12488 p = SDATA (stuffstring); 12485 bad_stuff = stuff_char (*p++);
12489 count = SBYTES (stuffstring); 12486 if (!bad_stuff)
12490 while (count-- > 0) 12487 bad_stuff = stuff_char ('\n');
12491 stuff_char (*p++);
12492 stuff_char ('\n');
12493 } 12488 }
12494 12489
12495 /* Anything we have read ahead, put back for the shell to read. */ 12490 /* Anything we have read ahead, put back for the shell to read.
12496 /* ?? What should this do when we have multiple keyboards?? 12491 When we have multiple keyboards, we should stuff everything back
12497 Should we ignore anything that was typed in at the "wrong" kboard? 12492 into the keyboard it came from, but fixing this is low priority as
12498 12493 many systems prohibit stuffing for security reasons. */
12499 rms: we should stuff everything back into the kboard
12500 it came from. */
12501 for (; kbd_fetch_ptr != kbd_store_ptr; 12494 for (; kbd_fetch_ptr != kbd_store_ptr;
12502 kbd_fetch_ptr = next_kbd_event (kbd_fetch_ptr)) 12495 kbd_fetch_ptr = next_kbd_event (kbd_fetch_ptr))
12503 { 12496 {
12504 12497 if (kbd_fetch_ptr->kind == ASCII_KEYSTROKE_EVENT && !bad_stuff)
12505 if (kbd_fetch_ptr->kind == ASCII_KEYSTROKE_EVENT) 12498 bad_stuff = stuff_char (kbd_fetch_ptr->ie.code);
12506 stuff_char (kbd_fetch_ptr->ie.code);
12507 12499
12508 clear_event (&kbd_fetch_ptr->ie); 12500 clear_event (&kbd_fetch_ptr->ie);
12509 } 12501 }
diff --git a/src/lisp.h b/src/lisp.h
index cefca3d6fbb..37c34dfbe84 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -5280,7 +5280,7 @@ maybe_disable_address_randomization (int argc, char **argv)
5280extern int emacs_exec_file (char const *, char *const *, char *const *); 5280extern int emacs_exec_file (char const *, char *const *, char *const *);
5281extern void init_standard_fds (void); 5281extern void init_standard_fds (void);
5282extern char *emacs_get_current_dir_name (void); 5282extern char *emacs_get_current_dir_name (void);
5283extern void stuff_char (char c); 5283extern int stuff_char (char c);
5284extern void init_foreground_group (void); 5284extern void init_foreground_group (void);
5285extern void sys_subshell (void); 5285extern void sys_subshell (void);
5286extern void sys_suspend (void); 5286extern void sys_suspend (void);
diff --git a/src/sysdep.c b/src/sysdep.c
index 2f5572009fb..8895655566e 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -390,23 +390,22 @@ discard_tty_input (void)
390 390
391/* Arrange for character C to be read as the next input from 391/* Arrange for character C to be read as the next input from
392 the terminal. 392 the terminal.
393 Return 0 on success, -1 otherwise.
393 XXX What if we have multiple ttys? 394 XXX What if we have multiple ttys?
394*/ 395*/
395 396
396void 397int
397stuff_char (char c) 398stuff_char (char c)
398{ 399{
399 if (! (FRAMEP (selected_frame)
400 && FRAME_LIVE_P (XFRAME (selected_frame))
401 && FRAME_TERMCAP_P (XFRAME (selected_frame))))
402 return;
403
404/* Should perhaps error if in batch mode */ 400/* Should perhaps error if in batch mode */
405#ifdef TIOCSTI 401#ifdef TIOCSTI
406 ioctl (fileno (CURTTY()->input), TIOCSTI, &c); 402 if (FRAMEP (selected_frame)
407#else /* no TIOCSTI */ 403 && FRAME_LIVE_P (XFRAME (selected_frame))
408 error ("Cannot stuff terminal input characters in this version of Unix"); 404 && FRAME_TERMCAP_P (XFRAME (selected_frame)))
405 return ioctl (fileno (CURTTY()->input), TIOCSTI, &c);
409#endif /* no TIOCSTI */ 406#endif /* no TIOCSTI */
407
408 return -1;
410} 409}
411 410
412#endif /* SIGTSTP */ 411#endif /* SIGTSTP */