lkml.org 
[lkml]   [2000]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[SysRq PATCH]: no more reboots because console freeze
From

Hi all

I made a very small patch to the SysRq facility that signals
a program with SIGUSR1, the program is registered via sysctl

The signal is launched with Alt+SysRq+X (X stands for eXecute program)

/proc/sys/kernel/sysrq_progid contains pid and start_time
which totally identifies the program to signal

One of the uses of this is restore the console when a X-server
or a SVGAlib program crashes

How many times did you have got to reboot because of that, while your
system may be doing something important??? this hopefully solves the problem

Patch is included below, sample programs/scripts are available at

http://pusa.uv.es/~ulisses/sysrq_X.tar.gz

Comments/sugestions wanted, please e-mail me directly to uaca@alumni.uv.es
(I'm not subscribed to the linux-kernel mailing list)

Bye!

Ulisses

-----------------------------------------------------------------------------
Debian GNU/Linux: a dream come true
-----------------------------------------------------------------------------

diff -u -r linux-2.4.0-test8/drivers/char/sysrq.c linux-2.4.0-test8-modificat2/drivers/char/sysrq.c
--- linux-2.4.0-test8/drivers/char/sysrq.c Tue Aug 1 04:36:10 2000
+++ linux-2.4.0-test8-modificat2/drivers/char/sysrq.c Mon Sep 25 08:58:23 2000
@@ -6,6 +6,8 @@
*
* (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
* based on ideas by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>
+ *
+ * (c) 2000 Ulisses Alonso Camaró eXecute_program extension
*/

#include <linux/config.h>
@@ -22,6 +24,7 @@
#include <linux/quotaops.h>
#include <linux/smp_lock.h>
#include <linux/module.h>
+#include <linux/kernel.h>

#include <asm/ptrace.h>

@@ -30,9 +33,13 @@
extern int console_loglevel;
extern struct list_head super_blocks;

+void signal_program(void);
+
/* Whether we react on sysrq keys or just ignore them */
int sysrq_enabled = 1;

+unsigned long sysrq_progid[2]= {0, 0}; /* pid and start_time */
+
/* Machine specific power off function */
void (*sysrq_power_off)(void) = NULL;

@@ -53,6 +60,35 @@
}
}

+void signal_program(void)
+{
+ struct task_struct *p;
+ pid_t pid= (pid_t)sysrq_progid[0];
+
+ read_lock(&tasklist_lock);
+
+ if ((p= find_task_by_pid(pid)) == NULL)
+ goto error;
+
+ if (!p->mm || p->pid == 1)
+ goto error;
+
+ if (p->start_time != sysrq_progid[1])
+ goto error;
+
+ send_sig(SIGUSR1, p, 0);
+
+ read_unlock(&tasklist_lock);
+
+ return;
+
+ error:
+ printk(KERN_ERR "SysRq: Could not send signal to pid %d with start_time %lu\n",
+ pid, sysrq_progid[1]);
+
+ return;
+}
+
/*
* This function is called by the keyboard handler when SysRq is pressed
* and any other keycode arrives.
@@ -138,6 +174,10 @@
send_sig_all(SIGKILL, 1);
orig_log_level = 8;
break;
+ case 'x':
+ printk("eXecute program\n");
+ signal_program();
+ break;
default: /* Unknown: help */
if (kbd)
printk("unRaw ");
@@ -148,7 +188,7 @@
printk("Boot ");
if (sysrq_power_off)
printk("Off ");
- printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL\n");
+ printk("Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL eXec_program\n");
/* Don't use 'A' as it's handled specially on the Sparc */
}

diff -u -r linux-2.4.0-test8/include/linux/sysctl.h linux-2.4.0-test8-modificat2/include/linux/sysctl.h
--- linux-2.4.0-test8/include/linux/sysctl.h Thu Aug 10 22:01:26 2000
+++ linux-2.4.0-test8-modificat2/include/linux/sysctl.h Sun Sep 24 12:39:30 2000
@@ -113,6 +113,7 @@
KERN_OVERFLOWGID=47, /* int: overflow GID */
KERN_SHMPATH=48, /* string: path to shm fs */
KERN_HOTPLUG=49, /* string: path to hotplug policy agent */
+ KERN_SYSRQ_PROGID=50 /* string: pid and start_time of the program to signal */
};


diff -u -r linux-2.4.0-test8/kernel/sysctl.c linux-2.4.0-test8-modificat2/kernel/sysctl.c
--- linux-2.4.0-test8/kernel/sysctl.c Tue Aug 1 04:36:11 2000
+++ linux-2.4.0-test8-modificat2/kernel/sysctl.c Mon Sep 25 08:59:24 2000
@@ -83,6 +83,10 @@
extern int acct_parm[];
#endif

+#ifdef CONFIG_MAGIC_SYSRQ
+extern unsigned long sysrq_progid[];
+#endif
+
extern int pgt_cache_water[];

static int parse_table(int *, int, void *, size_t *, void *, size_t,
@@ -220,6 +224,10 @@
#ifdef CONFIG_MAGIC_SYSRQ
{KERN_SYSRQ, "sysrq", &sysrq_enabled, sizeof (int),
0644, NULL, &proc_dointvec},
+ {KERN_SYSRQ_PROGID, "sysrq_progid", &sysrq_progid, 2*sizeof(unsigned long),
+ 0644, NULL, &proc_doulongvec_minmax, NULL,
+ (void *)NULL, (void *)NULL},
+/* (void *)&sysrq_progid_min, (void *)&sysrq_progid_max}, */
#endif
{KERN_MAX_THREADS, "threads-max", &max_threads, sizeof(int),
0644, NULL, &proc_dointvec},
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 12:38    [W:0.030 / U:0.104 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site