Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

patch for USR1 and USR2 signal handling

0 views
Skip to first unread message

Robert Spier

unread,
Dec 14, 1997, 3:00:00 AM12/14/97
to

Please find included a patch which enables handling of the USR1 and
USR2 signals on those systems which support them.

The patch was done with 19.34b source.

The purpose for this patch is to allow people to define what they want
Emacs to do when it recieves such a signal. Currently, it terminates
kind of uglily. By default, with the patch, it will do nothing unless
a user modifies the hooks. signal-USR1-hook or signal-USR2-hook

for example:
(add-hook 'signal-USR1-hook (function
(lambda ()
(save-buffers-kill-emacs))))

would have emacs cleanly save all open buffers and terminate on
reciept of the signal.

It's important that any functions that will terminate emacs be last in
the hook list.

This was developed to provide a minor amount of remote control,
especially for those moments where you leave something running in
emacs on one terminal, but are working on another and need to access
and modify that file, with the possibly unsaved changes on the other
terminal.

It uses hooks for the added flexibility of letting the user customize.

It's been tested only on Linux 2.0.30, but there are no OS specific
things, assuming the system has SIGUSR1/2 defined, it can handle them.

-Robert

*** /usr/local/src/emacs-19.34/src/emacs.c.orig Sat Dec 13 21:12:10 1997
--- /usr/local/src/emacs-19.34/src/emacs.c Sun Dec 14 14:34:56 1997
***************
*** 71,76 ****
--- 71,84 ----
/* Hook run by `kill-emacs' before it does really anything. */
Lisp_Object Vkill_emacs_hook;

+ #ifdef SIGUSR1
+ /* Hooks for signal USR1 and USR2 handing */
+ Lisp_Object Vsignal_USR1_hook;
+ #ifdef SIGUSR2
+ Lisp_Object Vsignal_USR2_hook;
+ #endif
+ #endif
+
/* Set nonzero after Emacs has started up the first time.
Prevents reinitialization of the Lisp world and keymaps
on subsequent starts. */
***************
*** 148,153 ****
--- 156,196 ----
/* Nonzero if handling a fatal error already */
int fatal_error_in_progress;

+ #ifdef SIGUSR1
+ int SIGUSR1_in_progress=0;
+ SIGTYPE
+ handle_USR1_signal (sig)
+ int sig;
+ {
+ if (! SIGUSR1_in_progress)
+ {
+ SIGUSR1_in_progress = 1;
+
+ if (!NILP (Vrun_hooks) && !noninteractive)
+ call1 (Vrun_hooks, intern ("signal-USR1-hook"));
+
+ SIGUSR1_in_progress = 0;
+ }
+ }
+ #ifdef SIGUSR2
+ int SIGUSR2_in_progress=0;
+ SIGTYPE
+ handle_USR2_signal (sig)
+ int sig;
+ {
+ if (! SIGUSR2_in_progress)
+ {
+ SIGUSR2_in_progress = 1;
+
+ if (!NILP (Vrun_hooks) && !noninteractive)
+ call1 (Vrun_hooks, intern ("signal-USR2-hook"));
+
+ SIGUSR2_in_progress = 0;
+ }
+ }
+ #endif
+ #endif
+
/* Handle bus errors, illegal instruction, etc. */
SIGTYPE
fatal_error_signal (sig)
***************
*** 698,703 ****
--- 741,752 ----
signal (SIGQUIT, fatal_error_signal);
signal (SIGILL, fatal_error_signal);
signal (SIGTRAP, fatal_error_signal);
+ #ifdef SIGUSR1
+ signal(SIGUSR1, handle_USR1_signal);
+ #ifdef SIGUSR2
+ signal(SIGUSR2, handle_USR2_signal);
+ #endif
+ #endif
#ifdef SIGABRT
signal (SIGABRT, fatal_error_signal);
#endif
***************
*** 1495,1500 ****
--- 1544,1561 ----
expect to be able to interact with the user. To ask for confirmation,\n\
see `kill-emacs-query-functions' instead.");
Vkill_emacs_hook = Qnil;
+
+ #ifdef SIGUSR1
+ DEFVAR_LISP ("signal-USR1-hook", &Vsignal_USR1_hook,
+ "Hook to be run whenever emacs recieves a USR1 signal");
+ Vsignal_USR1_hook = Qnil;
+ #ifdef SIGUSR2
+ DEFVAR_LISP ("signal-USR2-hook", &Vsignal_USR2_hook,
+ "Hook to be run whenever emacs recieves a USR2 signal");
+ Vsignal_USR2_hook = Qnil;
+ #endif
+ #endif
+

DEFVAR_INT ("emacs-priority", &emacs_priority,
"Priority for Emacs to run at.\n\

Diff finished at Sun Dec 14 14:43:31


--
Robert Spier <rsp...@seas.upenn.edu>
"Computers are very sophisticated idiots." - The Doctor


0 new messages